fixed dimension rails

This commit is contained in:
Ell 2020-09-22 15:38:58 +02:00
parent e4cb96ddcb
commit 6c8fd1d477
5 changed files with 47 additions and 44 deletions

View file

@ -17,6 +17,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.state.Property; import net.minecraft.state.Property;
@ -66,10 +67,10 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
if (stack.getItem() == ModItems.RANGE_VISUALIZER) { if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
if (!worldIn.isRemote) { if (!worldIn.isRemote) {
BlockPos goalPos = this.getGoalCoords(worldIn, pos); BlockPos goalPos = this.getGoalCoords(worldIn, pos);
// TODO dimension rail visualization CompoundNBT data = new CompoundNBT();
/* data.putString("dim", this.goalDim.func_240901_a_().toString());
PacketHandler.sendTo(player, new PacketClient(0, this.goalDim, goalPos.getX(), goalPos.getY(), goalPos.getZ())); data.putLong("pos", goalPos.toLong());
*/ PacketHandler.sendTo(player, new PacketClient(0, data));
} }
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
@ -93,8 +94,14 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
cart.changeDimension(world.getServer().getWorld(this.goalDim), new ITeleporter() { cart.changeDimension(world.getServer().getWorld(this.goalDim), new ITeleporter() {
@Override @Override
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) { public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
Entity result = repositionEntity.apply(false); // repositionEntity always causes a NPE because why wouldn't it, so this is a fixed copy
entity.world.getProfiler().endStartSection("reloading");
Entity result = entity.getType().create(destWorld);
if (result != null) {
result.copyDataFromOld(entity);
destWorld.addFromAnotherDimension(result);
result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch); result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch);
}
return result; return result;
} }
}); });

View file

@ -150,7 +150,7 @@ public class ClientEvents {
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance(); NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
inst.setParticleSpawnRange(512); inst.setParticleSpawnRange(512);
inst.setParticleDepth(false); inst.setParticleDepth(false);
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_RAILS.get(mc.world.func_234923_W_())) { for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_RAILS.get(mc.world.func_234923_W_().func_240901_a_())) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + mc.world.rand.nextFloat(), pos.getX() + mc.world.rand.nextFloat(),
pos.getY() + mc.world.rand.nextFloat(), pos.getY() + mc.world.rand.nextFloat(),
@ -232,7 +232,7 @@ public class ClientEvents {
GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBegin(GL11.GL_QUADS); GL11.glBegin(GL11.GL_QUADS);
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_BLOCKS.get(dim)) { for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_BLOCKS.get(dim.func_240901_a_())) {
if (!mc.world.isBlockLoaded(pos)) if (!mc.world.isBlockLoaded(pos))
continue; continue;
BlockState state = mc.world.getBlockState(pos); BlockState state = mc.world.getBlockState(pos);
@ -241,7 +241,7 @@ public class ClientEvents {
continue; continue;
this.renderVisualize((IVisualizable) block, mc.world, pos); this.renderVisualize((IVisualizable) block, mc.world, pos);
} }
for (Entity entity : ItemRangeVisualizer.VISUALIZED_ENTITIES.get(dim)) { for (Entity entity : ItemRangeVisualizer.VISUALIZED_ENTITIES.get(dim.func_240901_a_())) {
if (!entity.isAlive() || !(entity instanceof IVisualizable)) if (!entity.isAlive() || !(entity instanceof IVisualizable))
continue; continue;
this.renderVisualize((IVisualizable) entity, mc.world, entity.getPosition()); this.renderVisualize((IVisualizable) entity, mc.world, entity.getPosition());

View file

@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance; import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects; import net.minecraft.potion.Effects;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -30,8 +31,9 @@ public class ItemDeathRing extends ItemImpl {
entity.clearActivePotions(); entity.clearActivePotions();
entity.addPotionEffect(new EffectInstance(Effects.REGENERATION, 500, 1)); entity.addPotionEffect(new EffectInstance(Effects.REGENERATION, 500, 1));
PacketHandler.sendToAllAround(entity.world, entity.getPosition(), 32, CompoundNBT data = new CompoundNBT();
new PacketClient(1, entity.getEntityId())); data.putInt("id", entity.getEntityId());
PacketHandler.sendToAllAround(entity.world, entity.getPosition(), 32, new PacketClient(1, data));
equipped.shrink(1); equipped.shrink(1);
event.setCanceled(true); event.setCanceled(true);

View file

@ -10,10 +10,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResult; import net.minecraft.util.*;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -23,9 +20,9 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ItemRangeVisualizer extends ItemImpl { public class ItemRangeVisualizer extends ItemImpl {
public static final ListMultimap<RegistryKey<World>, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create(); public static final ListMultimap<ResourceLocation, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create();
public static final ListMultimap<RegistryKey<World>, Entity> VISUALIZED_ENTITIES = ArrayListMultimap.create(); public static final ListMultimap<ResourceLocation, Entity> VISUALIZED_ENTITIES = ArrayListMultimap.create();
public static final ListMultimap<RegistryKey<World>, BlockPos> VISUALIZED_RAILS = ArrayListMultimap.create(); public static final ListMultimap<ResourceLocation, BlockPos> VISUALIZED_RAILS = ArrayListMultimap.create();
public ItemRangeVisualizer() { public ItemRangeVisualizer() {
super("range_visualizer", new Properties().maxStackSize(1)); super("range_visualizer", new Properties().maxStackSize(1));
@ -41,7 +38,7 @@ public class ItemRangeVisualizer extends ItemImpl {
VISUALIZED_RAILS.clear(); VISUALIZED_RAILS.clear();
} }
public static <T> void visualize(PlayerEntity player, ListMultimap<RegistryKey<World>, T> map, RegistryKey<World> dim, T value) { public static <T> void visualize(PlayerEntity player, ListMultimap<ResourceLocation, T> map, ResourceLocation dim, T value) {
if (map.containsEntry(dim, value)) { if (map.containsEntry(dim, value)) {
map.remove(dim, value); map.remove(dim, value);
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end"), true); player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end"), true);
@ -70,7 +67,7 @@ public class ItemRangeVisualizer extends ItemImpl {
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof IVisualizable) { if (block instanceof IVisualizable) {
if (world.isRemote) if (world.isRemote)
visualize(context.getPlayer(), VISUALIZED_BLOCKS, world.func_234923_W_(), pos); visualize(context.getPlayer(), VISUALIZED_BLOCKS, world.func_234923_W_().func_240901_a_(), pos);
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
} }
return ActionResultType.PASS; return ActionResultType.PASS;
@ -86,7 +83,7 @@ public class ItemRangeVisualizer extends ItemImpl {
Entity entity = event.getTarget(); Entity entity = event.getTarget();
if (entity instanceof IVisualizable) { if (entity instanceof IVisualizable) {
if (entity.world.isRemote) { if (entity.world.isRemote) {
RegistryKey<World> dim = entity.world.func_234923_W_(); ResourceLocation dim = entity.world.func_234923_W_().func_240901_a_();
visualize(event.getPlayer(), VISUALIZED_ENTITIES, dim, entity); visualize(event.getPlayer(), VISUALIZED_ENTITIES, dim, entity);
} }
event.getPlayer().swingArm(event.getHand()); event.getPlayer().swingArm(event.getHand());

View file

@ -5,8 +5,10 @@ import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.particles.ParticleTypes; import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -15,9 +17,9 @@ import java.util.function.Supplier;
public class PacketClient { public class PacketClient {
private int type; private int type;
private int[] data; private CompoundNBT data;
public PacketClient(int type, int... data) { public PacketClient(int type, CompoundNBT data) {
this.type = type; this.type = type;
this.data = data; this.data = data;
} }
@ -29,18 +31,13 @@ public class PacketClient {
public static PacketClient fromBytes(PacketBuffer buf) { public static PacketClient fromBytes(PacketBuffer buf) {
PacketClient client = new PacketClient(); PacketClient client = new PacketClient();
client.type = buf.readByte(); client.type = buf.readByte();
client.data = new int[buf.readByte()]; client.data = buf.readCompoundTag();
for (int i = 0; i < client.data.length; i++)
client.data[i] = buf.readInt();
return client; return client;
} }
public static void toBytes(PacketClient packet, PacketBuffer buf) { public static void toBytes(PacketClient packet, PacketBuffer buf) {
buf.writeByte(packet.type); buf.writeByte(packet.type);
buf.writeByte(packet.data.length); buf.writeCompoundTag(packet.data);
for (int i : packet.data)
buf.writeInt(i);
} }
// lambda causes classloading issues on a server here // lambda causes classloading issues on a server here
@ -53,11 +50,11 @@ public class PacketClient {
if (mc.world != null) { if (mc.world != null) {
switch (message.type) { switch (message.type) {
case 0: // dimension rail visualization case 0: // dimension rail visualization
/* int goalDim = message.data[0]; ResourceLocation goalDim = new ResourceLocation(message.data.getString("dim"));
BlockPos goalPos = new BlockPos(message.data[1], message.data[2], message.data[3]); BlockPos goalPos = BlockPos.fromLong(message.data.getLong("pos"));
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, DimensionType.getById(goalDim), goalPos);*/ ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
case 1: case 1:
Entity entity = mc.world.getEntityByID(message.data[0]); Entity entity = mc.world.getEntityByID(message.data.getInt("id"));
mc.particles.emitParticleAtEntity(entity, ParticleTypes.TOTEM_OF_UNDYING, 30); mc.particles.emitParticleAtEntity(entity, ParticleTypes.TOTEM_OF_UNDYING, 30);
mc.world.playSound(entity.getPosX(), entity.getPosY(), entity.getPosZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.0F, 1.0F, false); mc.world.playSound(entity.getPosX(), entity.getPosY(), entity.getPosZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.0F, 1.0F, false);
if (entity == mc.player) { if (entity == mc.player) {