diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java index f246cfcd..176a8c77 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java @@ -1,11 +1,13 @@ package com.minelittlepony.unicopia.block; import java.util.List; +import java.util.Random; import javax.annotation.Nullable; import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.init.UBlocks; +import com.minelittlepony.unicopia.item.ItemMoss; import com.minelittlepony.unicopia.player.PlayerSpeciesList; import net.minecraft.block.Block; @@ -39,6 +41,8 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { setResistance(1.0F); setSoundType(SoundType.CLOTH); setLightOpacity(20); + setTickRandomly(true); + useNeighborBrightness = true; this.variant = variant; @@ -54,6 +58,20 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { return variant != CloudType.NORMAL; } + @Override + public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { + if (rand.nextInt(10) == 0) { + pos = pos.offset(EnumFacing.random(rand), 1 + rand.nextInt(2)); + state = world.getBlockState(pos); + + IBlockState converted = ItemMoss.affected.getInverse().getConverted(state); + + if (!state.equals(converted)) { + world.setBlockState(pos, converted); + } + } + } + @Override //Push player out of block public boolean isFullCube(IBlockState state) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java index 6eb59397..f28b6d41 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudSlab.java @@ -46,6 +46,7 @@ public abstract class BlockCloudSlab extends Bloc setSoundType(SoundType.CLOTH); setLightOpacity(20); setTranslationKey(name); + setTickRandomly(modelBlock.getTickRandomly()); setRegistryName(domain, name); useNeighborBrightness = true; @@ -83,6 +84,11 @@ public abstract class BlockCloudSlab extends Bloc return isDouble() && modelBlock.isNormalCube(state); } + @Override + public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { + modelBlock.updateTick(world, pos, state, rand); + } + @Override public BlockRenderLayer getRenderLayer() { return modelBlock.getRenderLayer(); diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java index fc63ffc4..6152b83a 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloudStairs.java @@ -33,6 +33,9 @@ public class BlockCloudStairs extends BlockStairs implements ICloudBlock { setRegistryName(domain, name); theBlock = inherited.getBlock(); theState = inherited; + + setTickRandomly(theBlock.getTickRandomly()); + useNeighborBrightness = true; fullBlock = isOpaqueCube(inherited); diff --git a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java index cd569272..b8ab2e60 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java @@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.forgebullshit.FUF; - import net.minecraft.block.Block; import net.minecraft.block.BlockBed; import net.minecraft.block.BlockChest; diff --git a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java index d2ca8f4b..3c7a37cd 100644 --- a/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java +++ b/src/main/java/com/minelittlepony/unicopia/edibles/ItemEdible.java @@ -2,11 +2,9 @@ package com.minelittlepony.unicopia.edibles; import java.util.List; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.minelittlepony.unicopia.Race; -import com.minelittlepony.unicopia.forgebullshit.IMultiItem; import com.minelittlepony.unicopia.init.UEffects; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -29,33 +27,19 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; -public class ItemEdible extends ItemFood implements IEdible, IMultiItem { - - private String translationKey; - - private final IEdible toxicityDeterminant; +public abstract class ItemEdible extends ItemFood implements IEdible { private EnumAction useAction = EnumAction.EAT; - public ItemEdible(@Nonnull IEdible mapper) { - super(1, 0, false); - - toxicityDeterminant = mapper; + public ItemEdible(int amount, int saturation, boolean isMeat) { + super(amount, saturation, isMeat); } - public ItemEdible(String domain, String name, int amount, int saturation, @Nonnull IEdible mapper) { - super(amount, saturation, false); + public ItemEdible(String domain, String name, int amount, int saturation, boolean isMeat) { + super(amount, saturation, isMeat); setTranslationKey(name); setRegistryName(domain, name); - - toxicityDeterminant = mapper; - } - - public Item setTranslationKey(String key) { - translationKey = key; - - return super.setTranslationKey(key); } public Item setUseAction(EnumAction action) { @@ -140,22 +124,5 @@ public class ItemEdible extends ItemFood implements IEdible, IMultiItem { } else if (toxicity.toxicWhenCooked()) { player.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 3, 1, false, false)); } - - toxicityDeterminant.addSecondaryEffects(player, toxicity, stack); - } - - @Override - public Toxicity getToxicityLevel(ItemStack stack) { - return toxicityDeterminant.getToxicityLevel(stack); - } - - @Override - public String[] getVariants() { - return Toxicity.getVariants(translationKey); - } - - @Override - public boolean variantsAreHidden() { - return true; } } diff --git a/src/main/java/com/minelittlepony/unicopia/edibles/MultiItemEdible.java b/src/main/java/com/minelittlepony/unicopia/edibles/MultiItemEdible.java new file mode 100644 index 00000000..82c124cd --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/edibles/MultiItemEdible.java @@ -0,0 +1,54 @@ +package com.minelittlepony.unicopia.edibles; + +import javax.annotation.Nonnull; +import com.minelittlepony.unicopia.forgebullshit.IMultiItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class MultiItemEdible extends ItemEdible implements IMultiItem { + + private String translationKey; + + private final IEdible toxicityDeterminant; + + public MultiItemEdible(@Nonnull IEdible mapper) { + super(1, 0, false); + + toxicityDeterminant = mapper; + } + + public MultiItemEdible(String domain, String name, int amount, int saturation, @Nonnull IEdible mapper) { + super(domain, name, amount, saturation, false); + + toxicityDeterminant = mapper; + } + + public Item setTranslationKey(String key) { + translationKey = key; + + return super.setTranslationKey(key); + } + + @Override + public void addSecondaryEffects(EntityPlayer player, Toxicity toxicity, ItemStack stack) { + super.addSecondaryEffects(player, toxicity, stack); + + toxicityDeterminant.addSecondaryEffects(player, toxicity, stack); + } + + @Override + public Toxicity getToxicityLevel(ItemStack stack) { + return toxicityDeterminant.getToxicityLevel(stack); + } + + @Override + public String[] getVariants() { + return Toxicity.getVariants(translationKey); + } + + @Override + public boolean variantsAreHidden() { + return true; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/init/UItems.java b/src/main/java/com/minelittlepony/unicopia/init/UItems.java index cd64de7a..809cd38a 100644 --- a/src/main/java/com/minelittlepony/unicopia/init/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/init/UItems.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.item.ItemCereal; import com.minelittlepony.unicopia.item.ItemCloud; import com.minelittlepony.unicopia.item.ItemCurse; import com.minelittlepony.unicopia.item.ItemFruitLeaves; +import com.minelittlepony.unicopia.item.ItemMoss; import com.minelittlepony.unicopia.item.ItemOfHolding; import com.minelittlepony.unicopia.item.ItemRottenApple; import com.minelittlepony.unicopia.item.ItemSpell; @@ -48,7 +49,7 @@ import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.edibles.BushToxicityDeterminent; import com.minelittlepony.unicopia.edibles.CookedToxicityDeterminent; import com.minelittlepony.unicopia.edibles.FlowerToxicityDeterminent; -import com.minelittlepony.unicopia.edibles.ItemEdible; +import com.minelittlepony.unicopia.edibles.MultiItemEdible; import com.minelittlepony.unicopia.edibles.Toxicity; import com.minelittlepony.unicopia.edibles.UItemFoodDelegate; import com.minelittlepony.unicopia.extern.Baubles; @@ -113,6 +114,7 @@ public class UItems { public static final ItemSpellbook spellbook = new ItemSpellbook(Unicopia.MODID, "spellbook"); public static final Item staff_meadow_brook = new ItemStaff(Unicopia.MODID, "staff_meadow_brook").setMaxDamage(2); + public static final ItemMoss moss = new ItemMoss(Unicopia.MODID, "moss"); public static final Item alfalfa_seeds = new ItemSeedFood(1, 4, UBlocks.alfalfa, Blocks.FARMLAND) .setTranslationKey("alfalfa_seeds") @@ -140,7 +142,7 @@ public class UItems { public static final Item double_plant = new UItemFoodDelegate(Blocks.DOUBLE_PLANT, stack -> BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new ItemEdible(new BushToxicityDeterminent())) + ).setFoodDelegate(new MultiItemEdible(new BushToxicityDeterminent())) .setTranslationKey("doublePlant"); public static final Item tall_grass = new UItemFoodDelegate(Blocks.TALLGRASS, stack -> { @@ -150,7 +152,7 @@ public class UItems { case 2: return "fern"; default: return ""; } - }).setFoodDelegate(new ItemEdible(stack -> { + }).setFoodDelegate(new MultiItemEdible(stack -> { switch (stack.getMetadata()) { default: case 0: return Toxicity.SAFE; @@ -161,38 +163,38 @@ public class UItems { public static final Item yellow_flower = new UItemFoodDelegate(Blocks.YELLOW_FLOWER, stack -> BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.YELLOW, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new ItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) + ).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.YELLOW))) .setTranslationKey("flower"); public static final Item red_flower = new UItemFoodDelegate(Blocks.RED_FLOWER, stack -> BlockFlower.EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, stack.getMetadata()).getTranslationKey() - ).setFoodDelegate(new ItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) + ).setFoodDelegate(new MultiItemEdible(new FlowerToxicityDeterminent(BlockFlower.EnumFlowerColor.RED))) .setTranslationKey("rose"); - public static final Item daffodil_daisy_sandwich = new ItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) + public static final Item daffodil_daisy_sandwich = new MultiItemEdible(Unicopia.MODID, "daffodil_daisy_sandwich", 3, 2, CookedToxicityDeterminent.instance) .setHasSubtypes(true); - public static final Item hay_burger = new ItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) + public static final Item hay_burger = new MultiItemEdible(Unicopia.MODID, "hay_burger", 3, 4, CookedToxicityDeterminent.instance) .setHasSubtypes(true); - public static final Item hay_fries = new ItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); - public static final Item salad = new ItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) + public static final Item hay_fries = new MultiItemEdible(Unicopia.MODID, "hay_fries", 1, 5, stack -> Toxicity.SAFE); + public static final Item salad = new MultiItemEdible(Unicopia.MODID, "salad", 4, 2, CookedToxicityDeterminent.instance) .setHasSubtypes(true) .setContainerItem(Items.BOWL); - public static final Item wheat_worms = new ItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); + public static final Item wheat_worms = new MultiItemEdible(Unicopia.MODID, "wheat_worms", 1, 0, stack -> Toxicity.SEVERE); public static final Item mug = new Item() .setTranslationKey("mug") .setRegistryName(Unicopia.MODID, "mug") .setCreativeTab(CreativeTabs.MATERIALS) .setFull3D(); - public static final Item apple_cider = new ItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) + public static final Item apple_cider = new MultiItemEdible(Unicopia.MODID, "apple_cider", 4, 2, stack -> Toxicity.MILD) .setUseAction(EnumAction.DRINK) .setContainerItem(mug) .setFull3D(); - public static final Item juice = new ItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) + public static final Item juice = new MultiItemEdible(Unicopia.MODID, "juice", 2, 2, stack -> Toxicity.SAFE) .setUseAction(EnumAction.DRINK) .setContainerItem(Items.GLASS_BOTTLE); - public static final Item burned_juice = new ItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) + public static final Item burned_juice = new MultiItemEdible(Unicopia.MODID, "burned_juice", 3, 1, stack -> Toxicity.FAIR) .setUseAction(EnumAction.DRINK) .setContainerItem(Items.GLASS_BOTTLE); @@ -220,7 +222,7 @@ public class UItems { cereal, sugar_cereal, sugar_block, rotten_apple, zap_apple, cooked_zap_apple, - cloudsdale_tomato, tomato_seeds, tomato, + cloudsdale_tomato, tomato_seeds, tomato, moss, apple_seeds, apple_leaves, @@ -236,7 +238,7 @@ public class UItems { zap_apple, rotten_apple, cooked_zap_apple, dew_drop, - tomato, cloudsdale_tomato, + tomato, cloudsdale_tomato, moss, cloud_spawner, cloud_matter, cloud_block, enchanted_cloud, packed_cloud, cloud_stairs, diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemMoss.java b/src/main/java/com/minelittlepony/unicopia/item/ItemMoss.java new file mode 100644 index 00000000..341f2d38 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemMoss.java @@ -0,0 +1,121 @@ +package com.minelittlepony.unicopia.item; + +import javax.annotation.Nullable; + +import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.edibles.ItemEdible; +import com.minelittlepony.unicopia.edibles.Toxicity; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; +import com.minelittlepony.util.collection.ReversableStateMapList; +import com.mojang.authlib.GameProfile; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockDispenser; +import net.minecraft.block.BlockSilverfish; +import net.minecraft.block.BlockStoneBrick; +import net.minecraft.block.BlockWall; +import net.minecraft.block.state.IBlockState; +import net.minecraft.dispenser.BehaviorDefaultDispenseItem; +import net.minecraft.dispenser.IBehaviorDispenseItem; +import net.minecraft.dispenser.IBlockSource; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.IShearable; + +public class ItemMoss extends ItemEdible { + + public static final ReversableStateMapList affected = new ReversableStateMapList(); + + static { + affected.replaceBlock(Blocks.MOSSY_COBBLESTONE, Blocks.COBBLESTONE); + affected.replaceProperty(Blocks.COBBLESTONE_WALL, BlockWall.VARIANT, BlockWall.EnumType.MOSSY, BlockWall.EnumType.NORMAL); + affected.replaceProperty(Blocks.STONEBRICK, BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY, BlockStoneBrick.EnumType.DEFAULT); + affected.replaceProperty(Blocks.MONSTER_EGG, BlockSilverfish.VARIANT, BlockSilverfish.EnumType.MOSSY_STONEBRICK, BlockSilverfish.EnumType.STONEBRICK); + } + + @Nullable + protected IBehaviorDispenseItem vanillaDispenserBehaviour; + private final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem() { + @Override + protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) { + + EnumFacing facing = source.getBlockState().getValue(BlockDispenser.FACING); + BlockPos pos = source.getBlockPos().offset(facing); + World w = source.getWorld(); + + if (tryConvert(w, w.getBlockState(pos), pos, null)) { + stack.attemptDamageItem(1, w.rand, null); + + return stack; + } + + EntityPlayer player = null; + + for (EntityLivingBase e : w.getEntitiesWithinAABB(EntityLivingBase.class, Block.FULL_BLOCK_AABB.offset(pos), e -> + e instanceof IShearable && ((IShearable)e).isShearable(stack, w, pos) + )) { + if (player == null) { + player = UClient.instance().createPlayer(e, new GameProfile(null, "Notch")); + } + + if (stack.interactWithEntity(player, e, EnumHand.MAIN_HAND)) { + return stack; + } + } + + if (vanillaDispenserBehaviour != null) { + return vanillaDispenserBehaviour.dispense(source, stack); + } + + return stack; + } + }; + + public ItemMoss(String domain, String name) { + super(domain, name, 3, 0, false); + + IBehaviorDispenseItem previous = BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.containsKey(Items.SHEARS) ? BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.getObject(Items.SHEARS) : null; + + if (previous != null && previous != dispenserBehavior) { + vanillaDispenserBehaviour = previous; + } + + BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(Items.SHEARS, dispenserBehavior); + } + + public boolean tryConvert(World world, IBlockState state, BlockPos pos, @Nullable EntityPlayer player) { + IBlockState converted = affected.getConverted(state); + + if (!state.equals(converted)) { + world.setBlockState(pos, converted, 3); + + world.playSound(null, pos, SoundEvents.ENTITY_SHEEP_SHEAR, SoundCategory.PLAYERS, 1, 1); + + int amount = 1; + + if (player != null && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canUseEarth()) { + amount = world.rand.nextInt(4); + } + + Block.spawnAsEntity(world, pos, new ItemStack(this, amount)); + + return true; + } + + return false; + } + + @Override + public Toxicity getToxicityLevel(ItemStack stack) { + return Toxicity.MILD; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/spell/SpellFire.java b/src/main/java/com/minelittlepony/unicopia/spell/SpellFire.java index 7f289a8e..946946d1 100644 --- a/src/main/java/com/minelittlepony/unicopia/spell/SpellFire.java +++ b/src/main/java/com/minelittlepony/unicopia/spell/SpellFire.java @@ -63,9 +63,7 @@ public class SpellFire extends AbstractSpell.RangedAreaSpell implements IUseActi affected.add(IStateMapping.build( s -> s.getBlock() == Blocks.DIRT && s.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT, - s -> Math.random() <= 0.15 ? - s.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT) - : s)); + s -> (Math.random() <= 0.15 ? s.withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT) : s))); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java b/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java index 5634e0ea..3fbc421f 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java +++ b/src/main/java/com/minelittlepony/unicopia/world/BlockInteractions.java @@ -11,7 +11,10 @@ import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -34,6 +37,22 @@ public class BlockInteractions { return true; } + public EnumActionResult onBlockInteract(World world, IBlockState state, BlockPos pos, EntityPlayer player, ItemStack stack, EnumHand hand) { + + if (stack.getItem() == Items.SHEARS) { + if (UItems.moss.tryConvert(world, state, pos, player)) { + + if (!player.isCreative()) { + stack.damageItem(1, player); + } + + return EnumActionResult.SUCCESS; + } + } + + return EnumActionResult.PASS; + } + public void addAuxiliaryDrops(World world, IBlockState state, BlockPos pos, List drops, int fortune) { Block block = state.getBlock(); diff --git a/src/main/java/com/minelittlepony/unicopia/world/Hooks.java b/src/main/java/com/minelittlepony/unicopia/world/Hooks.java index 8eaa1a75..51cb0951 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/Hooks.java +++ b/src/main/java/com/minelittlepony/unicopia/world/Hooks.java @@ -1,5 +1,7 @@ package com.minelittlepony.unicopia.world; +import net.minecraft.util.EnumActionResult; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.UseHoeEvent; import net.minecraftforge.event.terraingen.PopulateChunkEvent; import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType; @@ -13,6 +15,22 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; @EventBusSubscriber public class Hooks { + @SubscribeEvent + public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) { + + if (event.isCanceled()) { + return; + } + + EnumActionResult result = UWorld.instance().getBlocks().onBlockInteract( + event.getWorld(), event.getWorld().getBlockState(event.getPos()), event.getPos(), event.getEntityPlayer(), event.getItemStack(), event.getHand()); + + if (result != EnumActionResult.PASS) { + event.setCanceled(true); + event.setCancellationResult(result); + } + } + @SubscribeEvent public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) { UWorld.instance().getBlocks().addAuxiliaryDrops(event.getWorld(), event.getState(), event.getPos(), event.getDrops(), event.getFortuneLevel()); diff --git a/src/main/java/com/minelittlepony/util/collection/IStateMapping.java b/src/main/java/com/minelittlepony/util/collection/IStateMapping.java index 7046e5ff..865c9178 100644 --- a/src/main/java/com/minelittlepony/util/collection/IStateMapping.java +++ b/src/main/java/com/minelittlepony/util/collection/IStateMapping.java @@ -21,13 +21,15 @@ public interface IStateMapping extends Predicate, Function s.getBlock() == from, - s -> to.getDefaultState()); + s -> to.getDefaultState(), + s -> replaceBlock(to, from)); } static > IStateMapping replaceProperty(Block block, IProperty property, T from, T to) { return build( s -> s.getBlock() == block && s.getValue(property) == from, - s -> s.withProperty(property, to)); + s -> s.withProperty(property, to), + s -> replaceProperty(block, property, to, from)); } static > IStateMapping setProperty(Block block, IProperty property, T to) { @@ -37,7 +39,13 @@ public interface IStateMapping extends Predicate, Function predicate, Function converter) { + return build(predicate, converter, s -> s); + } + + static IStateMapping build(Predicate predicate, Function converter, Function inverter) { return new IStateMapping() { + private IStateMapping inverse; + @Override public boolean test(IBlockState state) { return predicate.test(state); @@ -47,6 +55,14 @@ public interface IStateMapping extends Predicate, Function, Function