From c4ef6cd863fb036dbda3e5347c6245b4bb9be2ed Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 13 Feb 2017 17:36:55 +0100 Subject: [PATCH] Add Laser Relay invisbility modfier --- .../mod/blocks/BlockLaserRelay.java | 53 ++++++++++++++---- .../mod/blocks/render/RenderLaserRelay.java | 40 ++++++++++++- .../mod/creative/CreativeTab.java | 1 + .../mod/items/InitItems.java | 2 + .../mod/items/ItemLaserRelayUpgrade.java | 27 +++++++++ .../mod/tile/TileEntityLaserRelay.java | 17 +++++- .../assets/actuallyadditions/lang/en_US.lang | 1 + .../item/item_laser_upgrade_invisibility.json | 6 ++ .../items/item_laser_upgrade_invisibility.png | Bin 0 -> 286 bytes 9 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserRelayUpgrade.java create mode 100644 src/main/resources/assets/actuallyadditions/models/item/item_laser_upgrade_invisibility.json create mode 100644 src/main/resources/assets/actuallyadditions/textures/items/item_laser_upgrade_invisibility.png diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 090708326..df364304d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; +import de.ellpeck.actuallyadditions.mod.items.ItemLaserRelayUpgrade; import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench; import de.ellpeck.actuallyadditions.mod.tile.*; import de.ellpeck.actuallyadditions.mod.util.StackUtil; @@ -85,7 +86,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ if(player != null && world != null && StackUtil.isValid(stack) && pos != null){ IBlockState state = event.getWorld().getBlockState(pos); if(state != null && state.getBlock() instanceof BlockLaserRelay){ - if(stack.getItem() instanceof ItemCompass && player.isSneaking()){ + if(player.isSneaking()){ event.setUseBlock(Event.Result.ALLOW); } } @@ -162,22 +163,52 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ if(tile instanceof TileEntityLaserRelay){ TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; - if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){ - if(!world.isRemote){ - relay.onCompassAction(player); + if(StackUtil.isValid(stack)){ + if(stack.getItem() instanceof ItemCompass){ + if(!world.isRemote){ + relay.onCompassAction(player); - Network network = relay.getNetwork(); - if(network != null){ - network.changeAmount++; + Network network = relay.getNetwork(); + if(network != null){ + network.changeAmount++; + } + + relay.markDirty(); + relay.sendUpdate(); } - relay.markDirty(); - relay.sendUpdate(); + return true; } + else if(stack.getItem() instanceof ItemLaserRelayUpgrade){ + ItemStack inRelay = relay.slots.getStackInSlot(0); + if(!StackUtil.isValid(inRelay)){ + if(!world.isRemote){ + player.setHeldItem(hand, StackUtil.addStackSize(stack, -1)); - return true; + ItemStack set = StackUtil.validateCopy(stack); + relay.slots.setStackInSlot(0, StackUtil.setStackSize(set, 1)); + } + return true; + } + + } } - else if(relay instanceof TileEntityLaserRelayItemWhitelist){ + + if(player.isSneaking()){ + ItemStack inRelay = StackUtil.validateCopy(relay.slots.getStackInSlot(0)); + if(StackUtil.isValid(inRelay)){ + if(!world.isRemote){ + relay.slots.setStackInSlot(0, StackUtil.getNull()); + + if(!player.inventory.addItemStackToInventory(inRelay)){ + player.entityDropItem(inRelay, 0); + } + } + return true; + } + } + + if(relay instanceof TileEntityLaserRelayItemWhitelist){ if(!world.isRemote){ player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.LASER_RELAY_ITEM_WHITELIST.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java index 5671f49eb..8278a8db3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java @@ -14,10 +14,15 @@ package de.ellpeck.actuallyadditions.mod.blocks.render; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.LaserType; +import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import de.ellpeck.actuallyadditions.mod.util.StackUtil; import io.netty.util.internal.ConcurrentSet; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.relauncher.Side; @@ -34,15 +39,46 @@ public class RenderLaserRelay extends TileEntitySpecialRenderer{ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float par5, int par6){ if(tile instanceof TileEntityLaserRelay){ TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; + boolean hasInvis = false; + + ItemStack upgrade = relay.slots.getStackInSlot(0); + if(StackUtil.isValid(upgrade)){ + if(upgrade.getItem() == InitItems.itemLaserUpgradeInvisibility){ + hasInvis = true; + } + + GlStateManager.pushMatrix(); + + float yTrans = tile.getBlockMetadata() == 0 ? 0.2F : 0.8F; + GlStateManager.translate((float)x+0.5F, (float)y+yTrans, (float)z+0.5F); + GlStateManager.scale(0.2F, 0.2F, 0.2F); + + double boop = Minecraft.getSystemTime()/800D; + GlStateManager.rotate((float)(((boop*40D)%360)), 0, 1, 0); + + AssetUtil.renderItemInWorld(upgrade); + + GlStateManager.popMatrix(); + } + ConcurrentSet connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(tile.getPos(), tile.getWorld()); if(connections != null && !connections.isEmpty()){ for(IConnectionPair pair : connections){ if(!pair.doesSuppressRender() && tile.getPos().equals(pair.getPositions()[0])){ BlockPos first = tile.getPos(); BlockPos second = pair.getPositions()[1]; - float[] color = relay.type == LaserType.ITEM ? COLOR_ITEM : (relay.type == LaserType.FLUID ? COLOR_FLUIDS : COLOR); - AssetUtil.renderLaser(first.getX()+0.5, first.getY()+0.5, first.getZ()+0.5, second.getX()+0.5, second.getY()+0.5, second.getZ()+0.5, 120, 0.35F, 0.05, color); + TileEntity secondTile = tile.getWorld().getTileEntity(second); + if(secondTile instanceof TileEntityLaserRelay){ + ItemStack secondUpgrade = ((TileEntityLaserRelay)secondTile).slots.getStackInSlot(0); + boolean otherInvis = StackUtil.isValid(secondUpgrade) && secondUpgrade.getItem() == InitItems.itemLaserUpgradeInvisibility; + + if(!hasInvis || !otherInvis){ + float[] color = relay.type == LaserType.ITEM ? COLOR_ITEM : (relay.type == LaserType.FLUID ? COLOR_FLUIDS : COLOR); + + AssetUtil.renderLaser(first.getX()+0.5, first.getY()+0.5, first.getZ()+0.5, second.getX()+0.5, second.getY()+0.5, second.getZ()+0.5, 120, 0.35F, 0.05, color); + } + } } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java index d9c2030d2..65cd618a0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java @@ -160,6 +160,7 @@ public class CreativeTab extends CreativeTabs{ this.add(InitItems.itemDisenchantingLens); this.add(InitItems.itemMiningLens); this.add(InitItems.itemLaserWrench); + this.add(InitItems.itemLaserUpgradeInvisibility); this.add(InitItems.itemCrateKeeper); this.add(InitItems.itemChestToCrateUpgrade); this.add(InitItems.itemSmallToMediumCrateUpgrade); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java index 32b0085e3..2332c6d50 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java @@ -193,10 +193,12 @@ public final class InitItems{ public static Item itemBag; public static Item itemVoidBag; public static Item itemFillingWand; + public static Item itemLaserUpgradeInvisibility; public static void init(){ ModUtil.LOGGER.info("Initializing Items..."); + itemLaserUpgradeInvisibility = new ItemLaserRelayUpgrade("item_laser_upgrade_invisibility"); itemFillingWand = new ItemFillingWand("item_filling_wand"); itemBag = new ItemBag("item_bag", false); itemVoidBag = new ItemBag("item_void_bag", true); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserRelayUpgrade.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserRelayUpgrade.java new file mode 100644 index 000000000..17818375f --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserRelayUpgrade.java @@ -0,0 +1,27 @@ +/* + * This file ("ItemLaserRelayUpgrade.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2017 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.items; + +import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; + +public class ItemLaserRelayUpgrade extends ItemBase{ + + public ItemLaserRelayUpgrade(String name){ + super(name); + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.UNCOMMON; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java index c07dd51b2..4c4529f68 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelay.java @@ -19,13 +19,15 @@ import io.netty.util.internal.ConcurrentSet; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import java.util.Set; -public abstract class TileEntityLaserRelay extends TileEntityBase{ +public abstract class TileEntityLaserRelay extends TileEntityInventoryBase{ public static final int MAX_DISTANCE = 15; @@ -37,7 +39,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ private Set tempConnectionStorage; public TileEntityLaserRelay(String name, LaserType type){ - super(name); + super(1, name); this.type = type; } @@ -149,10 +151,21 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{ } @Override + @SideOnly(Side.CLIENT) public AxisAlignedBB getRenderBoundingBox(){ return INFINITE_EXTENT_AABB; } + @Override + public boolean shouldSyncSlots(){ + return true; + } + + @Override + public IItemHandler getItemHandler(EnumFacing facing){ + return null; + } + @SideOnly(Side.CLIENT) public abstract String getExtraDisplayString(); diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index ab4974714..056992696 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -520,6 +520,7 @@ item.actuallyadditions.item_misc_empowered_canola_seed.name=Empowered Canola See item.actuallyadditions.item_mining_lens.name=Lens of the Miner item.actuallyadditions.item_more_damage_lens.name=Lens of the Killer item.actuallyadditions.item_filling_wand.name=Handheld Filler +item.actuallyadditions.item_laser_upgrade_invisibility.name=Laser Relay Modifier: Invisibility #Tooltips tooltip.actuallyadditions.onSuffix.desc=On diff --git a/src/main/resources/assets/actuallyadditions/models/item/item_laser_upgrade_invisibility.json b/src/main/resources/assets/actuallyadditions/models/item/item_laser_upgrade_invisibility.json new file mode 100644 index 000000000..bece64fa1 --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/models/item/item_laser_upgrade_invisibility.json @@ -0,0 +1,6 @@ +{ + "parent": "actuallyadditions:item/standard_item", + "textures": { + "layer0": "actuallyadditions:items/item_laser_upgrade_invisibility" + } +} diff --git a/src/main/resources/assets/actuallyadditions/textures/items/item_laser_upgrade_invisibility.png b/src/main/resources/assets/actuallyadditions/textures/items/item_laser_upgrade_invisibility.png new file mode 100644 index 0000000000000000000000000000000000000000..f9867b85b7501d00a9db462b1cf317977cfaaed5 GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;>1s;*b z3=G_YAk0{w5<>&kwgO-MvW^6>o$_klu^C9V-A!TD(=<%vb93~dIoxiM$RnRZ-9zAJY5_^Ec~bTcMBd+;Bbz;6u7%7`{uHSc8!jmr++HyuXSA+ zUlF)p@KejgA6DzH-3mE$U4=*4K7QY|U(#