Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
- Thank you, pau101
  • Loading branch information
InsomniaKitten committed Jul 27, 2017
1 parent 6b9f4f7 commit 8b4a8ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,4 +1,4 @@
mod_version=1.1.0
mod_version=1.2.0
mod_build=

mc_version=1.12
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/net/insomniakitten/cake/PersistentCake.java
@@ -1,12 +1,14 @@
package net.insomniakitten.cake;

import net.minecraft.block.Block;
import net.minecraft.block.BlockCake;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
Expand All @@ -27,26 +29,36 @@ public class PersistentCake {

@SuppressWarnings("ConstantConditions")
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onCakeUpdate(BlockEvent.BreakEvent event) {
public static void onBlockBreak(BlockEvent.BreakEvent event) {
if (event.getWorld().isRemote) return;
BlockPos pos = event.getPos().up();
IBlockState state = event.getWorld().getBlockState(pos);
if (state == null) return;
if (state.getBlock().equals(Blocks.CAKE)
&& state.getValue(BlockCake.BITES).equals(0)) {
InventoryHelper.spawnItemStack(event.getWorld(),
pos.getX(), pos.getY(), pos.getZ(),
new ItemStack(Items.CAKE));
if (state.getBlock().equals(Blocks.CAKE) && state.getValue(BlockCake.BITES).equals(0)) {
Block.spawnAsEntity(event.getWorld(), event.getPos(), new ItemStack(Items.CAKE));
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onCakeBroken(BlockEvent.HarvestDropsEvent event) {
public static void onHarvestDrops(BlockEvent.HarvestDropsEvent event) {
if (event.getWorld().isRemote || event.getState() == null) return;
if (event.getState().getBlock().equals(Blocks.CAKE)
&& event.getState().getValue(BlockCake.BITES).equals(0)) {
event.getDrops().add(new ItemStack(Items.CAKE));
}
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onNeighborNotify(BlockEvent.NeighborNotifyEvent event) {
if (!event.getNotifiedSides().contains(EnumFacing.UP)) return;
World world = event.getWorld();
BlockPos pos = event.getPos().up();
IBlockState state = world.getBlockState(pos);
boolean solidBelow = world.getBlockState(pos.down()).getMaterial().isSolid();
if (!solidBelow && state.getBlock() == Blocks.CAKE && state.getValue(BlockCake.BITES).equals(0)) {
Block.spawnAsEntity(world, pos, new ItemStack(Items.CAKE));
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
}

}

0 comments on commit 8b4a8ea

Please sign in to comment.