diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java index b0e728c5..7b7cd35d 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockContainerImpl.java @@ -26,6 +26,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.registry.GameRegistry; import javax.annotation.Nullable; +import java.util.Random; public class BlockContainerImpl extends BlockContainer implements IModItem, ICreativeItem, IModelProvider { @@ -132,10 +133,22 @@ public class BlockContainerImpl extends BlockContainer implements IModItem, ICre TileEntityImpl impl = (TileEntityImpl) tile; int newPower = world.getRedstonePowerFromNeighbors(pos); if (impl.redstonePower != newPower) { + boolean pulse = impl.redstonePower <= 0 && newPower > 0; impl.redstonePower = newPower; impl.onRedstonePowerChange(); + if (pulse) + world.scheduleUpdate(pos, this, this.tickRate(world)); } } } } + + @Override + public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { + if (!worldIn.isRemote) { + TileEntity tile = worldIn.getTileEntity(pos); + if (tile instanceof TileEntityImpl) + ((TileEntityImpl) tile).onRedstonePulse(); + } + } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java new file mode 100644 index 00000000..a7986712 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockPowderPlacer.java @@ -0,0 +1,51 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.blocks.tiles.TileEntityPowderPlacer; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.BlockFaceShape; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; + +public class BlockPowderPlacer extends BlockContainerImpl { + private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(0F, 0F, 0F, 1F, 4 / 16F, 1F); + + public BlockPowderPlacer() { + super(Material.ROCK, "powder_placer", TileEntityPowderPlacer.class, "powder_placer"); + this.setSoundType(SoundType.STONE); + this.setHardness(2.5F); + } + + @Override + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { + return BOUND_BOX; + } + + @Override + public boolean isFullCube(IBlockState state) { + return false; + } + + @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @Override + public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { + return false; + } + + @Override + public boolean isSideSolid(IBlockState baseState, IBlockAccess world, BlockPos pos, EnumFacing side) { + return side == EnumFacing.DOWN; + } + + @Override + public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) { + return BlockFaceShape.UNDEFINED; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java index 2218744e..63f90aaf 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSpawnLamp.java @@ -114,7 +114,6 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable int radius = ((TileEntitySpawnLamp) tile).getRadius(); if (radius > 0) return new AxisAlignedBB(pos).grow(radius); - System.out.println(radius); } return null; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index e31dc15b..5bfcedc7 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -50,4 +50,5 @@ public final class ModBlocks { public static final Block TIME_CHANGER = new BlockTimeChanger(); public static final Block GENERATOR_LIMIT_REMOVER = new BlockImpl("generator_limit_remover", Material.ROCK).setSoundType(SoundType.STONE).setHardness(2F); public static final Block ENDER_CRATE = new BlockEnderCrate(); + public static final Block POWDER_PLACER = new BlockPowderPlacer(); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java index 9accd999..db437171 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java @@ -62,6 +62,10 @@ public class TileEntityImpl extends TileEntity { } + public void onRedstonePulse(){ + + } + @Override public final SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound compound = new NBTTagCompound(); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPowderPlacer.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPowderPlacer.java new file mode 100644 index 00000000..53ea8503 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPowderPlacer.java @@ -0,0 +1,54 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import de.ellpeck.naturesaura.entities.EntityEffectInhibitor; +import de.ellpeck.naturesaura.items.ModItems; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EntitySelectors; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; + +import java.util.List; + +public class TileEntityPowderPlacer extends TileEntityImpl { + + @Override + public void onRedstonePulse() { + List powders = this.world.getEntitiesWithinAABB(EntityEffectInhibitor.class, + new AxisAlignedBB(this.pos, this.pos.add(1, 2, 1)), EntitySelectors.IS_ALIVE); + for (EnumFacing facing : EnumFacing.HORIZONTALS) { + TileEntity tile = this.world.getTileEntity(this.pos.offset(facing)); + if (tile == null || !tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())) + continue; + IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()); + if (handler == null) + continue; + + if (!powders.isEmpty()) { + for (EntityEffectInhibitor powder : powders) { + ItemStack drop = powder.getDrop(); + for (int i = 0; i < handler.getSlots(); i++) { + ItemStack remain = handler.insertItem(i, drop, false); + if (remain.isEmpty()) { + powder.setDead(); + break; + } else if (remain.getCount() != drop.getCount()) { + powder.setAmount(remain.getCount()); + } + } + } + } else { + for (int i = 0; i < handler.getSlots(); i++) { + ItemStack stack = handler.extractItem(i, Integer.MAX_VALUE, true); + if (stack.isEmpty() || stack.getItem() != ModItems.EFFECT_POWDER) + continue; + EntityEffectInhibitor.place(this.world, stack, this.pos.getX() + 0.5, this.pos.getY() + 1, this.pos.getZ() + 0.5); + handler.extractItem(i, Integer.MAX_VALUE, false); + break; + } + } + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java b/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java index 5f7e1b25..d3641926 100644 --- a/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java +++ b/src/main/java/de/ellpeck/naturesaura/entities/EntityEffectInhibitor.java @@ -3,6 +3,7 @@ package de.ellpeck.naturesaura.entities; import com.google.common.collect.ListMultimap; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.misc.IWorldData; import de.ellpeck.naturesaura.api.render.IVisualizable; import de.ellpeck.naturesaura.items.ItemEffectPowder; @@ -40,6 +41,16 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable { super(worldIn); } + public static void place(World world, ItemStack stack, double posX, double posY, double posZ) { + ResourceLocation effect = ItemEffectPowder.getEffect(stack); + EntityEffectInhibitor entity = new EntityEffectInhibitor(world); + entity.setInhibitedEffect(effect); + entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect)); + entity.setAmount(stack.getCount()); + entity.setPosition(posX, posY, posZ); + world.spawnEntity(entity); + } + @Override public void onAddedToWorld() { super.onAddedToWorld(); @@ -134,12 +145,16 @@ public class EntityEffectInhibitor extends Entity implements IVisualizable { public boolean attackEntityFrom(DamageSource source, float amount) { if (source instanceof EntityDamageSource && !this.world.isRemote) { this.setDead(); - this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.getAmount()), this.getInhibitedEffect()), 0F); + this.entityDropItem(this.getDrop(), 0F); return true; } else return super.attackEntityFrom(source, amount); } + public ItemStack getDrop() { + return ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.getAmount()), this.getInhibitedEffect()); + } + public void setInhibitedEffect(ResourceLocation effect) { this.removeFromPowderList(); this.dataManager.set(INHIBITED_EFFECT, effect.toString()); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java index cfaffbdf..071526f8 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemEffectPowder.java @@ -25,13 +25,7 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem { public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { ItemStack stack = player.getHeldItem(hand); - ResourceLocation effect = getEffect(stack); - EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn); - entity.setInhibitedEffect(effect); - entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect)); - entity.setAmount(stack.getCount()); - entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ); - worldIn.spawnEntity(entity); + EntityEffectInhibitor.place(worldIn, stack, pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ); stack.setCount(0); } return EnumActionResult.SUCCESS; diff --git a/src/main/resources/assets/naturesaura/blockstates/powder_placer.json b/src/main/resources/assets/naturesaura/blockstates/powder_placer.json new file mode 100644 index 00000000..cc618bdf --- /dev/null +++ b/src/main/resources/assets/naturesaura/blockstates/powder_placer.json @@ -0,0 +1,16 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "naturesaura:powder_placer", + "textures": { + "texture": "naturesaura:blocks/powder_placer", + "top": "naturesaura:blocks/powder_placer_top", + "particle": "#top" + }, + "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 835e1222..5a0ce068 100644 --- a/src/main/resources/assets/naturesaura/lang/en_US.lang +++ b/src/main/resources/assets/naturesaura/lang/en_US.lang @@ -46,6 +46,7 @@ tile.naturesaura.moss_generator.name=Swamp Homi tile.naturesaura.time_changer.name=Shifting Sundial tile.naturesaura.generator_limit_remover.name=Creational Catalyst tile.naturesaura.ender_crate.name=Ender Crate +tile.naturesaura.powder_placer.name=Powder Manipulator item.naturesaura.eye.name=Environmental Eye item.naturesaura.eye_improved.name=Environmental Ocular diff --git a/src/main/resources/assets/naturesaura/models/block/powder_placer.json b/src/main/resources/assets/naturesaura/models/block/powder_placer.json new file mode 100644 index 00000000..6e750fa6 --- /dev/null +++ b/src/main/resources/assets/naturesaura/models/block/powder_placer.json @@ -0,0 +1,39 @@ +{ + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 4, 16], + "faces": { + "down": { + "uv": [0, 0, 16, 16], + "texture": "#top", + "cullface": "down" + }, + "up": { + "uv": [0, 0, 16, 16], + "texture": "#top" + }, + "north": { + "uv": [0, 12, 16, 16], + "texture": "#texture", + "cullface": "north" + }, + "south": { + "uv": [0, 12, 16, 16], + "texture": "#texture", + "cullface": "south" + }, + "west": { + "uv": [0, 12, 16, 16], + "texture": "#texture", + "cullface": "west" + }, + "east": { + "uv": [0, 12, 16, 16], + "texture": "#texture", + "cullface": "east" + } + } + } + ] +} diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/devices/powder_placer.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/devices/powder_placer.json new file mode 100644 index 00000000..bce0745d --- /dev/null +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/devices/powder_placer.json @@ -0,0 +1,17 @@ +{ + "name": "Powder Manipulator", + "icon": "naturesaura:powder_placer", + "category": "devices", + "advancement": "naturesaura:positive_imbalance", + "pages": [ + { + "type": "text", + "text": "Using $(l:effects/effect_powder)Effect Powder$() can prove to be quite useful when trying to inhibit or start certain $(thing)Aura Imbalance$() effects. The $(item)Powder Manipulator$() helps with this greatly: Placing a chest on any side of it and placing any kind of $(item)Effect Powder$() into it will cause it to, upon receiving a $(thing)redstone pulse$(), place that powder down in the world." + }, + { + "type": "crafting", + "text": "Similarly, upon giving it another pulse, it will collect the powder that it has placed on top of it once again and deposit it in a nearby chest.", + "recipe": "naturesaura:powder_placer" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/recipes/powder_placer.json b/src/main/resources/assets/naturesaura/recipes/powder_placer.json new file mode 100644 index 00000000..f070d49f --- /dev/null +++ b/src/main/resources/assets/naturesaura/recipes/powder_placer.json @@ -0,0 +1,25 @@ +{ + "type": "forge:ore_shaped", + "pattern": [ + " A ", + "PSP", + " T " + ], + "key": { + "P": { + "item": "naturesaura:gold_powder" + }, + "S": { + "item": "naturesaura:infused_stone" + }, + "T": { + "item": "naturesaura:token_joy" + }, + "A": { + "item": "naturesaura:token_anger" + } + }, + "result": { + "item": "naturesaura:powder_placer" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/naturesaura/textures/blocks/powder_placer.png b/src/main/resources/assets/naturesaura/textures/blocks/powder_placer.png new file mode 100644 index 00000000..e1d5dcca Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/blocks/powder_placer.png differ diff --git a/src/main/resources/assets/naturesaura/textures/blocks/powder_placer_top.png b/src/main/resources/assets/naturesaura/textures/blocks/powder_placer_top.png new file mode 100644 index 00000000..40ed31fc Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/blocks/powder_placer_top.png differ