mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
visual overhaul of the mystical magnifier
This commit is contained in:
parent
4bcd7f9c80
commit
1c3c8221bd
3 changed files with 36 additions and 23 deletions
|
@ -2,25 +2,24 @@ package de.ellpeck.naturesaura.items;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
||||||
import de.ellpeck.naturesaura.blocks.BlockDimensionRail;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ItemRangeVisualizer extends ItemImpl {
|
public class ItemRangeVisualizer extends ItemImpl {
|
||||||
|
|
||||||
public static final ListMultimap<Integer, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create();
|
public static final ListMultimap<Integer, BlockPos> VISUALIZED_BLOCKS = ArrayListMultimap.create();
|
||||||
|
@ -29,20 +28,29 @@ public class ItemRangeVisualizer extends ItemImpl {
|
||||||
|
|
||||||
public ItemRangeVisualizer() {
|
public ItemRangeVisualizer() {
|
||||||
super("range_visualizer");
|
super("range_visualizer");
|
||||||
|
this.setMaxStackSize(1);
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
|
||||||
|
ItemStack stack = playerIn.getHeldItem(handIn);
|
||||||
|
if (playerIn.isSneaking()) {
|
||||||
|
clear();
|
||||||
|
playerIn.sendStatusMessage(new TextComponentTranslation("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true);
|
||||||
|
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
|
||||||
|
}
|
||||||
|
return new ActionResult<>(EnumActionResult.PASS, stack);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||||
IBlockState state = worldIn.getBlockState(pos);
|
IBlockState state = worldIn.getBlockState(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if (block instanceof IVisualizable) {
|
if (block instanceof IVisualizable) {
|
||||||
int dim = worldIn.provider.getDimension();
|
|
||||||
if (worldIn.isRemote)
|
if (worldIn.isRemote)
|
||||||
if (VISUALIZED_BLOCKS.containsEntry(dim, pos))
|
visualize(player, VISUALIZED_BLOCKS, worldIn.provider.getDimension(), pos);
|
||||||
VISUALIZED_BLOCKS.remove(dim, pos);
|
|
||||||
else
|
|
||||||
VISUALIZED_BLOCKS.put(dim, pos);
|
|
||||||
return EnumActionResult.SUCCESS;
|
return EnumActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return EnumActionResult.PASS;
|
return EnumActionResult.PASS;
|
||||||
|
@ -57,6 +65,16 @@ public class ItemRangeVisualizer extends ItemImpl {
|
||||||
VISUALIZED_RAILS.clear();
|
VISUALIZED_RAILS.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> void visualize(EntityPlayer player, ListMultimap<Integer, T> map, int dim, T value) {
|
||||||
|
if (map.containsEntry(dim, value)) {
|
||||||
|
map.remove(dim, value);
|
||||||
|
player.sendStatusMessage(new TextComponentTranslation("info." + NaturesAura.MOD_ID + ".range_visualizer.end"), true);
|
||||||
|
} else {
|
||||||
|
map.put(dim, value);
|
||||||
|
player.sendStatusMessage(new TextComponentTranslation("info." + NaturesAura.MOD_ID + ".range_visualizer.start"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onInteract(PlayerInteractEvent.EntityInteractSpecific event) {
|
public void onInteract(PlayerInteractEvent.EntityInteractSpecific event) {
|
||||||
ItemStack stack = event.getItemStack();
|
ItemStack stack = event.getItemStack();
|
||||||
|
@ -66,10 +84,7 @@ public class ItemRangeVisualizer extends ItemImpl {
|
||||||
if (entity instanceof IVisualizable) {
|
if (entity instanceof IVisualizable) {
|
||||||
if (entity.world.isRemote) {
|
if (entity.world.isRemote) {
|
||||||
int dim = entity.world.provider.getDimension();
|
int dim = entity.world.provider.getDimension();
|
||||||
if (VISUALIZED_ENTITIES.containsEntry(dim, entity))
|
visualize(event.getEntityPlayer(), VISUALIZED_ENTITIES, dim, entity);
|
||||||
VISUALIZED_ENTITIES.remove(dim, entity);
|
|
||||||
else
|
|
||||||
VISUALIZED_ENTITIES.put(dim, entity);
|
|
||||||
}
|
}
|
||||||
event.getEntityPlayer().swingArm(event.getHand());
|
event.getEntityPlayer().swingArm(event.getHand());
|
||||||
event.setCancellationResult(EnumActionResult.SUCCESS);
|
event.setCancellationResult(EnumActionResult.SUCCESS);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
@ -48,17 +47,13 @@ public class PacketClient implements IMessage {
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public IMessage onMessage(PacketClient message, MessageContext ctx) {
|
public IMessage onMessage(PacketClient message, MessageContext ctx) {
|
||||||
NaturesAura.proxy.scheduleTask(() -> {
|
NaturesAura.proxy.scheduleTask(() -> {
|
||||||
World world = Minecraft.getMinecraft().world;
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
if (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];
|
int goalDim = message.data[0];
|
||||||
BlockPos goalPos = new BlockPos(message.data[1], message.data[2], message.data[3]);
|
BlockPos goalPos = new BlockPos(message.data[1], message.data[2], message.data[3]);
|
||||||
if (ItemRangeVisualizer.VISUALIZED_RAILS.containsEntry(goalDim, goalPos))
|
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
|
||||||
ItemRangeVisualizer.VISUALIZED_RAILS.remove(goalDim, goalPos);
|
|
||||||
else
|
|
||||||
ItemRangeVisualizer.VISUALIZED_RAILS.put(goalDim, goalPos);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,8 +105,8 @@ container.naturesaura.animal_spawner.name=Altar of Birthing
|
||||||
info.naturesaura.aura_in_area=Aura Around
|
info.naturesaura.aura_in_area=Aura Around
|
||||||
info.naturesaura.book.landing=$(aura) is a complicated matter, and creating, collecting and making use of it can be difficult.$(br)The $(item)Book of Natural Aura$() contains all the information one requires to do so.
|
info.naturesaura.book.landing=$(aura) is a complicated matter, and creating, collecting and making use of it can be difficult.$(br)The $(item)Book of Natural Aura$() contains all the information one requires to do so.
|
||||||
info.naturesaura.book.subtitle=The guide to Nature's Aura
|
info.naturesaura.book.subtitle=The guide to Nature's Aura
|
||||||
info.naturesaura.stored_pos=You jotted down the position
|
info.naturesaura.stored_pos=You jot down the position
|
||||||
info.naturesaura.connected=You made a connection
|
info.naturesaura.connected=You make a connection
|
||||||
info.naturesaura.same_position=This seems to be the position from your notes...
|
info.naturesaura.same_position=This seems to be the position from your notes...
|
||||||
info.naturesaura.too_far=The distance seems too great...
|
info.naturesaura.too_far=The distance seems too great...
|
||||||
info.naturesaura.stored_pos_gone=Your notes seem out of date...
|
info.naturesaura.stored_pos_gone=Your notes seem out of date...
|
||||||
|
@ -115,6 +115,9 @@ info.naturesaura.ender_crate=Ender Crate: %s
|
||||||
info.naturesaura.ender_access=Ender Ocular: %s
|
info.naturesaura.ender_access=Ender Ocular: %s
|
||||||
info.naturesaura.ender_name.missing=No Ender Name
|
info.naturesaura.ender_name.missing=No Ender Name
|
||||||
info.naturesaura.ender_name=Ender Name: %s
|
info.naturesaura.ender_name=Ender Name: %s
|
||||||
|
info.naturesaura.range_visualizer.start=You take note of the magnification...
|
||||||
|
info.naturesaura.range_visualizer.end=You lose focus of the magnification...
|
||||||
|
info.naturesaura.range_visualizer.end_all=You lose focus of all magnifications...
|
||||||
|
|
||||||
advancement.naturesaura.root=Nature's Aura
|
advancement.naturesaura.root=Nature's Aura
|
||||||
advancement.naturesaura.root.desc=Becoming a magical botanist
|
advancement.naturesaura.root.desc=Becoming a magical botanist
|
||||||
|
|
Loading…
Reference in a new issue