Skip to content

Commit

Permalink
made is possible to drop meat items into an empty cauldron
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Jun 27, 2021
1 parent 50863d9 commit ed41a4e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ else if (!Flags.isFlagSet(flagValue, Flags.BONE_MEAL) && item instanceof BoneMea
worldIn.getPendingBlockTicks().scheduleTick(pos, state.getBlock(), 55 + 1 + worldIn.rand.nextInt(20));
}
}
else if (level >= MAX_LEVEL - 3 && level < MAX_LEVEL - 1) {
if (item instanceof PotionItem) {
Potion potion = PotionUtils.getPotionFromItem(stack);
if (potion == Potions.HEALING || potion == Potions.REGENERATION) {
stack.grow(-1);
entityIn.entityDropItem(stack.hasContainerItem() ? stack.getContainerItem() : new ItemStack(Items.GLASS_BOTTLE));
setSoupLevel(worldIn, pos, state, flagValue, level, 1);
worldIn.playSound(null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1f, 1f);
}
else if (potion == Potions.STRONG_HEALING || potion == Potions.STRONG_REGENERATION || potion == Potions.LONG_REGENERATION) {
stack.grow(-1);
entityIn.entityDropItem(stack.hasContainerItem() ? stack.getContainerItem() : new ItemStack(Items.GLASS_BOTTLE));
setSoupLevel(worldIn, pos, state, flagValue, level, 2);
worldIn.playSound(null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1f, 1f);
}
}
}
}
}
}
Expand Down
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();
}
}
}
}

}
1 change: 1 addition & 0 deletions src/main/resources/biomancy.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
"ArmorStandEntityAccessor",
"CapabilityProviderMixin",
"CauldronBlockMixin",
"DamageSourceMixin",
"GrindstoneContainerMixin",
"LivingEntityMixin",
Expand Down

0 comments on commit ed41a4e

Please sign in to comment.