From 1b0df8272f4bdb6ebcbe1082f0d4931bf2ac2a97 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 5 Nov 2018 22:37:40 +0100 Subject: [PATCH] added the hopper enhancement --- .../blocks/BlockHopperUpgrade.java | 10 +++ .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../blocks/tiles/TileEntityHopperUpgrade.java | 70 ++++++++++++++++++ .../naturesaura/packet/PacketParticles.java | 8 ++ .../naturesaura/particles/ParticleMagic.java | 6 +- .../blockstates/hopper_upgrade.json | 14 ++++ .../assets/naturesaura/lang/en_US.lang | 1 + .../en_us/entries/using/hopper_upgrade.json | 17 +++++ .../naturesaura/recipes/hopper_upgrade.json | 26 +++++++ .../textures/blocks/hopper_upgrade.png | Bin 0 -> 739 bytes 10 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockHopperUpgrade.java create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityHopperUpgrade.java create mode 100644 src/main/resources/assets/naturesaura/blockstates/hopper_upgrade.json create mode 100644 src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/using/hopper_upgrade.json create mode 100644 src/main/resources/assets/naturesaura/recipes/hopper_upgrade.json create mode 100644 src/main/resources/assets/naturesaura/textures/blocks/hopper_upgrade.png diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockHopperUpgrade.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockHopperUpgrade.java new file mode 100644 index 00000000..2ada4b66 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockHopperUpgrade.java @@ -0,0 +1,10 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.blocks.tiles.TileEntityHopperUpgrade; +import net.minecraft.block.material.Material; + +public class BlockHopperUpgrade extends BlockContainerImpl { + public BlockHopperUpgrade() { + super(Material.IRON, "hopper_upgrade", TileEntityHopperUpgrade.class, "hopper_upgrade"); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index 427e74c5..579a5cf7 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -30,4 +30,5 @@ public final class ModBlocks { public static final Block CONVERSION_CATALYST = new BlockImpl("conversion_catalyst", Material.ROCK).setSoundType(SoundType.STONE).setHardness(2.5F); public static final Block FLOWER_GENERATOR = new BlockFlowerGenerator(); public static final Block PLACER = new BlockPlacer(); + public static final Block HOPPER_UPGRADE = new BlockHopperUpgrade(); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityHopperUpgrade.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityHopperUpgrade.java new file mode 100644 index 00000000..7acd0d3a --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityHopperUpgrade.java @@ -0,0 +1,70 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import de.ellpeck.naturesaura.aura.chunk.AuraChunk; +import de.ellpeck.naturesaura.packet.PacketHandler; +import de.ellpeck.naturesaura.packet.PacketParticles; +import net.minecraft.block.BlockHopper; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityHopper; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; + +import java.util.List; + +public class TileEntityHopperUpgrade extends TileEntityImpl implements ITickable { + @Override + public void update() { + if (!this.world.isRemote && this.world.getTotalWorldTime() % 10 == 0) { + if (AuraChunk.getAuraInArea(this.world, this.pos, 25) < 1000) + return; + TileEntity tile = this.world.getTileEntity(this.pos.down()); + if (!(tile instanceof TileEntityHopper) || !BlockHopper.isEnabled(tile.getBlockMetadata())) + return; + TileEntityHopper hopper = (TileEntityHopper) tile; + if (!hopper.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP)) + return; + IItemHandler handler = hopper.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); + if (handler == null) + return; + + List items = this.world.getEntitiesWithinAABB(EntityItem.class, + new AxisAlignedBB(this.pos).grow(7)); + if (items.isEmpty()) + return; + + for (EntityItem item : items) { + if (item.isDead || item.cannotPickup()) + continue; + ItemStack stack = item.getItem(); + if (stack.isEmpty()) + continue; + ItemStack copy = stack.copy(); + + for (int i = 0; i < handler.getSlots(); i++) { + copy = handler.insertItem(i, copy, false); + if (copy.isEmpty()) { + break; + } + } + + if (!ItemStack.areItemStacksEqual(stack, copy)) { + item.setItem(copy); + if (copy.isEmpty()) + item.setDead(); + + BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 25, this.pos); + AuraChunk.getAuraChunk(this.world, spot).drainAura(spot, 10); + + PacketHandler.sendToAllAround(this.world, this.pos, 32, + new PacketParticles((float) item.posX, (float) item.posY, (float) item.posZ, 10)); + } + } + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java index 4ba141a2..2913f40f 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java @@ -188,6 +188,14 @@ public class PacketParticles implements IMessage { 0xad7a37, world.rand.nextFloat() + 1F, 50, 0F, true, true); } break; + case 10: // Hopper upgrade picking up + for (int i = world.rand.nextInt(20) + 10; i >= 0; i--) + NaturesAura.proxy.spawnMagicParticle(world, + message.posX, message.posY + 0.45F, message.posZ, + world.rand.nextGaussian() * 0.015F, + world.rand.nextGaussian() * 0.015F, + world.rand.nextGaussian() * 0.015F, + 0xdde7ff, world.rand.nextFloat() + 1F, 30, -0.06F, true, true); } } }); diff --git a/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java b/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java index 111cf543..0fa7f3f5 100644 --- a/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java +++ b/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java @@ -29,9 +29,9 @@ public class ParticleMagic extends Particle { this.motionY = motionY; this.motionZ = motionZ; - float r = (((color >> 16) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.35F); - float g = (((color >> 8) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.35F); - float b = ((color & 255) / 255F) * (1F - this.rand.nextFloat() * 0.35F); + float r = (((color >> 16) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F); + float g = (((color >> 8) & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F); + float b = ((color & 255) / 255F) * (1F - this.rand.nextFloat() * 0.25F); this.setRBGColorF(r, g, b); TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks(); diff --git a/src/main/resources/assets/naturesaura/blockstates/hopper_upgrade.json b/src/main/resources/assets/naturesaura/blockstates/hopper_upgrade.json new file mode 100644 index 00000000..20128987 --- /dev/null +++ b/src/main/resources/assets/naturesaura/blockstates/hopper_upgrade.json @@ -0,0 +1,14 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "minecraft:cube_all", + "textures": { + "all": "naturesaura:blocks/hopper_upgrade" + }, + "transform": "forge:default-block" + }, + "variants": { + "normal": [{}], + "inventory": [{}] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/lang/en_US.lang b/src/main/resources/assets/naturesaura/lang/en_US.lang index 6c4116f7..517cdd94 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -27,6 +27,7 @@ tile.naturesaura.infused_brick_slab.name=Infused Brick Slab tile.naturesaura.infused_brick_slab_double.name=Infused Brick Double Slab tile.naturesaura.flower_generator.name=Herbivorous Absorber tile.naturesaura.placer.name=Imperceptible Builder +tile.naturesaura.hopper_upgrade.name=Hopper Enhancement item.naturesaura.eye.name=Environmental Eye item.naturesaura.gold_fiber.name=Brilliant Fiber diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/using/hopper_upgrade.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/using/hopper_upgrade.json new file mode 100644 index 00000000..9ff81ec3 --- /dev/null +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/using/hopper_upgrade.json @@ -0,0 +1,17 @@ +{ + "name": "Hopper Enhancement", + "icon": "naturesaura:hopper_upgrade", + "category": "using", + "advancement": "naturesaura:infused_materials", + "pages": [ + { + "type": "text", + "text": "Collecting items using $(item)Hoppers$() is useful, but sometimes, it can be inconvenient, especially if given a big area that one has to collect items in. For that, the $(item)Hopper Enhancement$() will be a help: By simply placing it on top of any $(item)Hopper$(), it will increase its range of picking up items drastically by about $(thing)seven$() blocks.$(br)When collecting an item, it then uses a small amount of $(aura)." + }, + { + "type": "crafting", + "text": "Creating the $(item)Hopper Enhancement$()", + "recipe": "naturesaura:hopper_upgrade" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/hopper_upgrade.json b/src/main/resources/assets/naturesaura/recipes/hopper_upgrade.json new file mode 100644 index 00000000..b338c3af --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/hopper_upgrade.json @@ -0,0 +1,26 @@ +{ + "type": "forge:ore_shaped", + "pattern": [ + "RIR", + "IEI", + "RHR" + ], + "key": { + "H": { + "item": "minecraft:hopper" + }, + "I": { + "item": "naturesaura:infused_iron" + }, + "R": { + "type": "forge:ore_dict", + "ore": "ingotIron" + }, + "E": { + "item": "minecraft:ender_pearl" + } + }, + "result": { + "item": "naturesaura:hopper_upgrade" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/blocks/hopper_upgrade.png b/src/main/resources/assets/naturesaura/textures/blocks/hopper_upgrade.png new file mode 100644 index 0000000000000000000000000000000000000000..f6f2f16685c94b3c66caa2c27ca43ff6777875d7 GIT binary patch literal 739 zcmV<90v!E`P)N2bZe?^J zG%hhNF=Hy6O8@`@VM#UWKn(RTW5;pqzzc=6!xL>ovtBz{-+GCY-llER z+?wQj3d1WypCQ8s@X!?a!oy0i&_2l4?n+0}kz`$6UE${D29wDI!{HETXJ=R}7MRcH z7>~!ezP{$a(aB~yow80o3~+RGgyZ95bh};jdOg<5vP8e%$NBj=zmrby=HA>{qtOT_ zCnrw;RGJ`7JIM1CN-1P2L8q;r0Fd2mHiJc}(Sd|eRXag-+eNKegST6SyX(Pw7r8xJiRGNIHV z1~@#_sirC1ZI5d%);$zI`-oSCj+~?Qxr4orF??M{rBPu3a;EaFi;D{`K_!YACj#Ry zDcY-jB;WQS?>cC{53zGA5Xb;_!$zwmI4HM~J~Vww_d3w+s#6D|0DGT05IXYC2Z`ow zq)7~z;ELwJlt9^AW_(GcCdboRR6{)je}TA_TK8oQ&tBS)p~UIwDGLKo9mFU}p63wS zz}~Q7Z#rvu>8k=#K#?D6N4-X%GkSYzX2ro Vs