Safety platform spawns in overworld instead of dimension.

Started by Unknown634 on

Topic category: Help with modding (Java Edition)

Last seen on 22:05, 23. Jun 2023
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Safety platform spawns in overworld instead of dimension.

This is supposed to spawn a platform in the nether under the player, but it spawns it in the overworld where the player was.

public class NetherTeletotemPlayerFinishesUsingItemProcedure {

public static void execute(LevelAccessor world, double x, double y, double z, Entity entity, ItemStack itemstack) {
if (entity == null)
return;
if (entity instanceof Player _player)
_player.getCooldowns().addCooldown(itemstack.getItem(), 100);
if (!(entity instanceof Player _plr ? _plr.getAbilities().instabuild : false) && !((entity instanceof LivingEntity _livEnt ? _livEnt.getOffhandItem() : ItemStack.EMPTY).getItem() == WackyWeaponryModItems.NETHER_TELETOTEM.get())) {
if (entity instanceof Player _player) {
ItemStack _stktoremove = new ItemStack(WackyWeaponryModItems.NETHER_TELETOTEM.get());
_player.getInventory().clearOrCountMatchingItems(p -> _stktoremove.getItem() == p.getItem(), 1, _player.inventoryMenu.getCraftSlots());
}
} else if (!(entity instanceof Player _plr ? _plr.getAbilities().instabuild : false) && (entity instanceof LivingEntity _livEnt ? _livEnt.getOffhandItem() : ItemStack.EMPTY).getItem() == WackyWeaponryModItems.NETHER_TELETOTEM.get()) {
if (entity instanceof LivingEntity _entity) {
ItemStack _setstack = new ItemStack(Blocks.AIR);
_setstack.setCount(1);
_entity.setItemInHand(InteractionHand.OFF_HAND, _setstack);
if (_entity instanceof Player _player)
_player.getInventory().setChanged();
}
}
if (world instanceof Level _level) {
if (!_level.isClientSide()) {
_level.playSound(null, BlockPos.containing(x, y, z), ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.portal.trigger")), SoundSource.PLAYERS, (float) 0.3, 1);
} else {
_level.playLocalSound(x, y, z, ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.portal.trigger")), SoundSource.PLAYERS, (float) 0.3, 1, false);
}
}
if (world instanceof ServerLevel _level)
_level.sendParticles(ParticleTypes.PORTAL, x, y, z, 500, 2, 2, 2, 1);
WackyWeaponryMod.queueServerWork(80, () -> {
if (entity instanceof ServerPlayer _player && !_player.level.isClientSide()) {
ResourceKey<Level> destinationType = Level.NETHER;
if (_player.level.dimension() == destinationType)
return;
ServerLevel nextLevel = _player.server.getLevel(destinationType);
if (nextLevel != null) {
_player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.WIN_GAME, 0));
_player.teleportTo(nextLevel, _player.getX(), _player.getY(), _player.getZ(), _player.getYRot(), _player.getXRot());
_player.connection.send(new ClientboundPlayerAbilitiesPacket(_player.getAbilities()));
for (MobEffectInstance _effectinstance : _player.getActiveEffects())
_player.connection.send(new ClientboundUpdateMobEffectPacket(_player.getId(), _effectinstance));
_player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
}
}
if (world instanceof ServerLevel _serverworld) {
StructureTemplate template = _serverworld.getStructureManager().getOrCreate(new ResourceLocation("wacky_weaponry", "hellplatform"));
if (template != null) {
template.placeInWorld(_serverworld, BlockPos.containing(entity.getX() + -2, entity.getY() + -1, entity.getZ() + -2), BlockPos.containing(entity.getX() + -2, entity.getY() + -1, entity.getZ() + -2),
new StructurePlaceSettings().setRotation(Rotation.NONE).setMirror(Mirror.NONE).setIgnoreEntities(false), _serverworld.random, 3);
}
}
});
}
}

 

 

 

Last seen on 20:18, 12. Mar 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Right before the template…
Sun, 07/16/2023 - 17:41

Right before the template.placeInWorld line, add:

ResourceKey<Level> destinationType = Level.NETHER;
ServerLevel nextLevel = world.getServer().getLevel(destinationType);

Then replace _serverworld in the template.placeInWorld line with nextLevel.