-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made is possible to drop meat items into an empty cauldron
- Loading branch information
1 parent
50863d9
commit ed41a4e
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/github/elenterius/biomancy/mixin/CauldronBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.github.elenterius.biomancy.mixin; | ||
|
||
import com.github.elenterius.biomancy.block.MeatsoupCauldronBlock; | ||
import com.github.elenterius.biomancy.init.ModBlocks; | ||
import com.github.elenterius.biomancy.init.ModTags; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.CauldronBlock; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.item.ItemEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.state.IntegerProperty; | ||
import net.minecraft.util.SoundCategory; | ||
import net.minecraft.util.SoundEvents; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.util.Constants; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(CauldronBlock.class) | ||
public abstract class CauldronBlockMixin { | ||
|
||
@Shadow | ||
@Final | ||
public static IntegerProperty LEVEL; | ||
|
||
@Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) | ||
protected void biomancy_onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { | ||
if (!worldIn.isRemote && entityIn instanceof ItemEntity) { | ||
int waterLevel = state.get(LEVEL); | ||
if (waterLevel == 0) { | ||
ItemStack stack = ((ItemEntity) entityIn).getItem(); | ||
Item item = stack.getItem(); | ||
if (item.isIn(ModTags.Items.RAW_MEATS)) { | ||
int amount = Math.min(stack.getCount(), 5); | ||
((ItemEntity) entityIn).getItem().grow(-amount); | ||
|
||
BlockState meatState = ModBlocks.MEATSOUP_CAULDRON.get().getDefaultState().with(MeatsoupCauldronBlock.LEVEL, amount); | ||
worldIn.setBlockState(pos, meatState, Constants.BlockFlags.BLOCK_UPDATE); | ||
worldIn.playSound(null, pos, SoundEvents.ENTITY_SLIME_SQUISH_SMALL, SoundCategory.BLOCKS, 1f, 0.5f); | ||
|
||
ci.cancel(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters