mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 14:59:22 +01:00
fixed dimension rails
This commit is contained in:
parent
e4cb96ddcb
commit
6c8fd1d477
5 changed files with 47 additions and 44 deletions
|
@ -17,6 +17,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.state.EnumProperty;
|
||||
import net.minecraft.state.Property;
|
||||
|
@ -66,10 +67,10 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
|
|||
if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
|
||||
if (!worldIn.isRemote) {
|
||||
BlockPos goalPos = this.getGoalCoords(worldIn, pos);
|
||||
// TODO dimension rail visualization
|
||||
/*
|
||||
PacketHandler.sendTo(player, new PacketClient(0, this.goalDim, goalPos.getX(), goalPos.getY(), goalPos.getZ()));
|
||||
*/
|
||||
CompoundNBT data = new CompoundNBT();
|
||||
data.putString("dim", this.goalDim.func_240901_a_().toString());
|
||||
data.putLong("pos", goalPos.toLong());
|
||||
PacketHandler.sendTo(player, new PacketClient(0, data));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
@ -93,8 +94,14 @@ public class BlockDimensionRail extends AbstractRailBlock implements IModItem, I
|
|||
cart.changeDimension(world.getServer().getWorld(this.goalDim), new ITeleporter() {
|
||||
@Override
|
||||
public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
|
||||
Entity result = repositionEntity.apply(false);
|
||||
result.moveToBlockPosAndAngles(goalCoords, yaw, result.rotationPitch);
|
||||
// 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);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -150,7 +150,7 @@ public class ClientEvents {
|
|||
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
|
||||
inst.setParticleSpawnRange(512);
|
||||
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(
|
||||
pos.getX() + mc.world.rand.nextFloat(),
|
||||
pos.getY() + mc.world.rand.nextFloat(),
|
||||
|
@ -216,7 +216,7 @@ public class ClientEvents {
|
|||
RenderSystem.translated((pos.getX() + 0.1) / scale, (pos.getY() + 1.001) / scale, (pos.getZ() + 0.1) / scale);
|
||||
RenderSystem.rotatef(90F, 1F, 0F, 0F);
|
||||
RenderSystem.scalef(0.65F, 0.65F, 0.65F);
|
||||
mc.fontRenderer.drawString(stack,format.format(spot.getValue()), 0, 0, 0);
|
||||
mc.fontRenderer.drawString(stack, format.format(spot.getValue()), 0, 0, 0);
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class ClientEvents {
|
|||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
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))
|
||||
continue;
|
||||
BlockState state = mc.world.getBlockState(pos);
|
||||
|
@ -241,7 +241,7 @@ public class ClientEvents {
|
|||
continue;
|
||||
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))
|
||||
continue;
|
||||
this.renderVisualize((IVisualizable) entity, mc.world, entity.getPosition());
|
||||
|
@ -385,7 +385,7 @@ public class ClientEvents {
|
|||
if (tile != null && (container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null)) != null) {
|
||||
BlockState state = mc.world.getBlockState(pos);
|
||||
ItemStack blockStack = state.getBlock().getPickBlock(state, mc.objectMouseOver, mc.world, pos, mc.player);
|
||||
this.drawContainerInfo(stack,container.getStoredAura(), container.getMaxAura(), container.getAuraColor(),
|
||||
this.drawContainerInfo(stack, container.getStoredAura(), container.getMaxAura(), container.getAuraColor(),
|
||||
mc, res, 35, blockStack.getDisplayName().getString(), null);
|
||||
|
||||
if (tile instanceof TileEntityNatureAltar) {
|
||||
|
@ -393,14 +393,14 @@ public class ClientEvents {
|
|||
if (!tileStack.isEmpty()) {
|
||||
IAuraContainer stackCont = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
|
||||
if (stackCont != null) {
|
||||
this.drawContainerInfo(stack,stackCont.getStoredAura(), stackCont.getMaxAura(), stackCont.getAuraColor(),
|
||||
this.drawContainerInfo(stack, stackCont.getStoredAura(), stackCont.getMaxAura(), stackCont.getAuraColor(),
|
||||
mc, res, 55, tileStack.getDisplayName().getString(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (tile instanceof TileEntityRFConverter) {
|
||||
EnergyStorage storage = ((TileEntityRFConverter) tile).storage;
|
||||
this.drawContainerInfo(stack,storage.getEnergyStored(), storage.getMaxEnergyStored(), 0xcc4916,
|
||||
this.drawContainerInfo(stack, storage.getEnergyStored(), storage.getMaxEnergyStored(), 0xcc4916,
|
||||
mc, res, 35, I18n.format("tile.naturesaura.rf_converter.name"),
|
||||
storage.getEnergyStored() + " / " + storage.getMaxEnergyStored() + " RF");
|
||||
} else if (tile instanceof TileEntityGratedChute) {
|
||||
|
@ -433,8 +433,8 @@ public class ClientEvents {
|
|||
ItemStack itemStack = timer.getItemHandler(null).getStackInSlot(0);
|
||||
if (!itemStack.isEmpty()) {
|
||||
Helper.renderItemInGui(itemStack, x - 20, y - 20, 1);
|
||||
mc.fontRenderer.drawStringWithShadow(stack,TextFormatting.GRAY + this.createTimeString(timer.getTotalTime()), x + 5, y - 11, 0xFFFFFF);
|
||||
mc.fontRenderer.drawStringWithShadow(stack,TextFormatting.GRAY + I18n.format("info.naturesaura.remaining", this.createTimeString(timer.getTimeLeft())), x + 5, y + 3, 0xFFFFFF);
|
||||
mc.fontRenderer.drawStringWithShadow(stack, TextFormatting.GRAY + this.createTimeString(timer.getTotalTime()), x + 5, y - 11, 0xFFFFFF);
|
||||
mc.fontRenderer.drawStringWithShadow(stack, TextFormatting.GRAY + I18n.format("info.naturesaura.remaining", this.createTimeString(timer.getTimeLeft())), x + 5, y + 3, 0xFFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -464,13 +464,13 @@ public class ClientEvents {
|
|||
|
||||
mc.getTextureManager().bindTexture(OVERLAYS);
|
||||
if (width < 80)
|
||||
AbstractGui.blit(stack,x + width, y, width, 0, 80 - width, 6, 256, 256);
|
||||
AbstractGui.blit(stack, x + width, y, width, 0, 80 - width, 6, 256, 256);
|
||||
if (width > 0)
|
||||
AbstractGui.blit(stack,x, y, 0, 6, width, 6, 256, 256);
|
||||
AbstractGui.blit(stack, x, y, 0, 6, width, 6, 256, 256);
|
||||
|
||||
mc.fontRenderer.drawStringWithShadow(stack,name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color);
|
||||
mc.fontRenderer.drawStringWithShadow(stack, name, x + 40 - mc.fontRenderer.getStringWidth(name) / 2F, y - 9, color);
|
||||
|
||||
if (textBelow != null)
|
||||
mc.fontRenderer.drawStringWithShadow(stack,textBelow, x + 40 - mc.fontRenderer.getStringWidth(textBelow) / 2F, y + 7, color);
|
||||
mc.fontRenderer.drawStringWithShadow(stack, textBelow, x + 40 - mc.fontRenderer.getStringWidth(textBelow) / 2F, y + 7, color);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -30,8 +31,9 @@ public class ItemDeathRing extends ItemImpl {
|
|||
entity.clearActivePotions();
|
||||
entity.addPotionEffect(new EffectInstance(Effects.REGENERATION, 500, 1));
|
||||
|
||||
PacketHandler.sendToAllAround(entity.world, entity.getPosition(), 32,
|
||||
new PacketClient(1, entity.getEntityId()));
|
||||
CompoundNBT data = new CompoundNBT();
|
||||
data.putInt("id", entity.getEntityId());
|
||||
PacketHandler.sendToAllAround(entity.world, entity.getPosition(), 32, new PacketClient(1, data));
|
||||
|
||||
equipped.shrink(1);
|
||||
event.setCanceled(true);
|
||||
|
|
|
@ -10,10 +10,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -23,9 +20,9 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||
|
||||
public class ItemRangeVisualizer extends ItemImpl {
|
||||
|
||||
public static final ListMultimap<RegistryKey<World>, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create();
|
||||
public static final ListMultimap<RegistryKey<World>, Entity> VISUALIZED_ENTITIES = ArrayListMultimap.create();
|
||||
public static final ListMultimap<RegistryKey<World>, BlockPos> VISUALIZED_RAILS = ArrayListMultimap.create();
|
||||
public static final ListMultimap<ResourceLocation, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create();
|
||||
public static final ListMultimap<ResourceLocation, Entity> VISUALIZED_ENTITIES = ArrayListMultimap.create();
|
||||
public static final ListMultimap<ResourceLocation, BlockPos> VISUALIZED_RAILS = ArrayListMultimap.create();
|
||||
|
||||
public ItemRangeVisualizer() {
|
||||
super("range_visualizer", new Properties().maxStackSize(1));
|
||||
|
@ -41,7 +38,7 @@ public class ItemRangeVisualizer extends ItemImpl {
|
|||
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)) {
|
||||
map.remove(dim, value);
|
||||
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();
|
||||
if (block instanceof IVisualizable) {
|
||||
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.PASS;
|
||||
|
@ -86,7 +83,7 @@ public class ItemRangeVisualizer extends ItemImpl {
|
|||
Entity entity = event.getTarget();
|
||||
if (entity instanceof IVisualizable) {
|
||||
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);
|
||||
}
|
||||
event.getPlayer().swingArm(event.getHand());
|
||||
|
|
|
@ -5,8 +5,10 @@ import de.ellpeck.naturesaura.items.ModItems;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
@ -15,9 +17,9 @@ import java.util.function.Supplier;
|
|||
|
||||
public class PacketClient {
|
||||
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.data = data;
|
||||
}
|
||||
|
@ -29,18 +31,13 @@ public class PacketClient {
|
|||
public static PacketClient fromBytes(PacketBuffer buf) {
|
||||
PacketClient client = new PacketClient();
|
||||
client.type = buf.readByte();
|
||||
client.data = new int[buf.readByte()];
|
||||
for (int i = 0; i < client.data.length; i++)
|
||||
client.data[i] = buf.readInt();
|
||||
|
||||
client.data = buf.readCompoundTag();
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void toBytes(PacketClient packet, PacketBuffer buf) {
|
||||
buf.writeByte(packet.type);
|
||||
buf.writeByte(packet.data.length);
|
||||
for (int i : packet.data)
|
||||
buf.writeInt(i);
|
||||
buf.writeCompoundTag(packet.data);
|
||||
}
|
||||
|
||||
// lambda causes classloading issues on a server here
|
||||
|
@ -53,11 +50,11 @@ public class PacketClient {
|
|||
if (mc.world != null) {
|
||||
switch (message.type) {
|
||||
case 0: // dimension rail visualization
|
||||
/* int goalDim = message.data[0];
|
||||
BlockPos goalPos = new BlockPos(message.data[1], message.data[2], message.data[3]);
|
||||
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, DimensionType.getById(goalDim), goalPos);*/
|
||||
ResourceLocation goalDim = new ResourceLocation(message.data.getString("dim"));
|
||||
BlockPos goalPos = BlockPos.fromLong(message.data.getLong("pos"));
|
||||
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
|
||||
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.world.playSound(entity.getPosX(), entity.getPosY(), entity.getPosZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.0F, 1.0F, false);
|
||||
if (entity == mc.player) {
|
||||
|
|
Loading…
Reference in a new issue