Cells should work on caludron. Closes #2490

This commit is contained in:
drcrazy 2021-09-20 05:38:43 +03:00
parent 6b89b08ff0
commit 4c4881e7e5
3 changed files with 77 additions and 0 deletions

View file

@ -93,6 +93,7 @@ public class TechReborn implements ModInitializer {
//noinspection ResultOfMethodCallIgnored
GuiType.AESU.getIdentifier();
TRDispenserBehavior.init();
TRCauldronBehavior.init();
PoweredCraftingHandler.setup();
UseBlockHandler.init();
ApplyArmorToDamageHandler.init();

View file

@ -0,0 +1,75 @@
package techreborn.init;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeveledCauldronBlock;
import net.minecraft.block.cauldron.CauldronBehavior;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsage;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import techreborn.items.DynamicCellItem;
import techreborn.utils.FluidUtils;
public class TRCauldronBehavior {
public static void init() {
CauldronBehavior FILL_CELL_WITH_LAVA = (state, world, pos, player, hand, stack) -> {
if (!FluidUtils.isContainerEmpty(stack)) {
return ActionResult.PASS;
}
return CauldronBehavior.emptyCauldron(state, world, pos, player, hand, stack,
DynamicCellItem.getCellWithFluid(Fluids.LAVA), (statex) -> true, SoundEvents.ITEM_BUCKET_FILL);
};
CauldronBehavior FILL_CELL_WITH_WATER = (state, world, pos, player, hand, stack) -> {
if (!FluidUtils.isContainerEmpty(stack)) {
return ActionResult.PASS;
}
return CauldronBehavior.emptyCauldron(state, world, pos, player, hand, stack,
DynamicCellItem.getCellWithFluid(Fluids.WATER), (statex) -> true, SoundEvents.ITEM_BUCKET_FILL_LAVA);
};
CauldronBehavior FILL_FROM_CELL = (state, world, pos, player, hand, stack) -> {
Fluid cellFluid = ((DynamicCellItem) stack.getItem()).getFluid(stack);
if (cellFluid == Fluids.WATER) {
return fillCauldronFromCell(world, pos, player, hand, stack,
Blocks.WATER_CAULDRON.getDefaultState().with(LeveledCauldronBlock.LEVEL, 3),
SoundEvents.ITEM_BUCKET_EMPTY);
} else if (cellFluid == Fluids.LAVA) {
return fillCauldronFromCell(world, pos, player, hand, stack,
Blocks.LAVA_CAULDRON.getDefaultState(),
SoundEvents.ITEM_BUCKET_EMPTY_LAVA);
}
return ActionResult.PASS;
};
CauldronBehavior.LAVA_CAULDRON_BEHAVIOR.put(TRContent.CELL, FILL_CELL_WITH_LAVA);
CauldronBehavior.WATER_CAULDRON_BEHAVIOR.put(TRContent.CELL, FILL_CELL_WITH_WATER);
CauldronBehavior.EMPTY_CAULDRON_BEHAVIOR.put(TRContent.CELL, FILL_FROM_CELL);
}
static ActionResult fillCauldronFromCell(World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack, BlockState state, SoundEvent soundEvent) {
if (!world.isClient) {
player.setStackInHand(hand, ItemUsage.exchangeStack(stack, player, new ItemStack(TRContent.CELL)));
player.incrementStat(Stats.FILL_CAULDRON);
world.setBlockState(pos, state);
world.playSound(null, pos, soundEvent, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.emitGameEvent(null, GameEvent.FLUID_PLACE, pos);
}
return ActionResult.success(world.isClient);
}
}

View file

@ -186,6 +186,7 @@ public class DynamicCellItem extends Item implements ItemFluidInfo {
ItemStack itemStack = ((FluidDrainable) hitState.getBlock()).tryDrainFluid(world, hitPos, hitState);
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemFluidInfo) {
Fluid drainFluid = ((ItemFluidInfo) itemStack.getItem()).getFluid(itemStack);
// TODO: Change to ItemUsage.exchangeStack
if (stack.getCount() == 1) {
stack = getCellWithFluid(drainFluid, 1);
} else {