mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Handy Tweaks
- Deployers now place block drops into their internal inventory - Deployers can now harvest honey or honeycombs from beehives - Pipes can now connect to and drain liquid honey from beehives
This commit is contained in:
parent
389b2e0e90
commit
3a6714fb08
4 changed files with 109 additions and 61 deletions
|
@ -13,19 +13,17 @@ import com.simibubi.create.content.contraptions.components.deployer.DeployerTile
|
||||||
import com.simibubi.create.content.curiosities.tools.SandPaperItem;
|
import com.simibubi.create.content.curiosities.tools.SandPaperItem;
|
||||||
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
|
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
|
||||||
|
|
||||||
import net.minecraft.advancements.CriteriaTriggers;
|
|
||||||
import net.minecraft.block.BeehiveBlock;
|
import net.minecraft.block.BeehiveBlock;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.enchantment.Enchantments;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
import net.minecraft.entity.item.ItemEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
import net.minecraft.fluid.Fluids;
|
import net.minecraft.fluid.Fluids;
|
||||||
import net.minecraft.inventory.EquipmentSlotType;
|
import net.minecraft.inventory.EquipmentSlotType;
|
||||||
|
@ -39,13 +37,13 @@ import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.server.management.PlayerInteractionManager;
|
import net.minecraft.server.management.PlayerInteractionManager;
|
||||||
import net.minecraft.stats.Stats;
|
|
||||||
import net.minecraft.tileentity.BeehiveTileEntity;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.SoundCategory;
|
||||||
|
import net.minecraft.util.SoundEvents;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
import net.minecraft.util.math.BlockRayTraceResult;
|
||||||
|
@ -53,6 +51,7 @@ import net.minecraft.util.math.RayTraceContext;
|
||||||
import net.minecraft.util.math.RayTraceContext.BlockMode;
|
import net.minecraft.util.math.RayTraceContext.BlockMode;
|
||||||
import net.minecraft.util.math.RayTraceContext.FluidMode;
|
import net.minecraft.util.math.RayTraceContext.FluidMode;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import net.minecraft.world.GameType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraftforge.common.ForgeHooks;
|
import net.minecraftforge.common.ForgeHooks;
|
||||||
|
@ -216,7 +215,7 @@ public class DeployerHandler {
|
||||||
progress += before;
|
progress += before;
|
||||||
|
|
||||||
if (progress >= 1) {
|
if (progress >= 1) {
|
||||||
safeTryHarvestBlock(player.interactionManager, clickedPos);
|
tryHarvestBlock(player.interactionManager, clickedPos);
|
||||||
world.sendBlockBreakProgress(player.getEntityId(), clickedPos, -1);
|
world.sendBlockBreakProgress(player.getEntityId(), clickedPos, -1);
|
||||||
player.blockBreakingProgress = null;
|
player.blockBreakingProgress = null;
|
||||||
return;
|
return;
|
||||||
|
@ -255,11 +254,9 @@ public class DeployerHandler {
|
||||||
boolean flag1 =
|
boolean flag1 =
|
||||||
!(player.isSneaking() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player));
|
!(player.isSneaking() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player));
|
||||||
|
|
||||||
if (clickedState.getBlock() instanceof BeehiveBlock)
|
|
||||||
return; // Beehives assume a lot about the usage context. Crashes to side-effects
|
|
||||||
|
|
||||||
// Use on block
|
// Use on block
|
||||||
if (useBlock != DENY && flag1 && clickedState.onUse(world, player, hand, result) == ActionResultType.SUCCESS)
|
if (useBlock != DENY && flag1
|
||||||
|
&& safeOnUse(clickedState, world, clickedPos, player, hand, result) == ActionResultType.SUCCESS)
|
||||||
return;
|
return;
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -294,7 +291,8 @@ public class DeployerHandler {
|
||||||
|
|
||||||
ActionResult<ItemStack> onItemRightClick = item.onItemRightClick(itemUseWorld, player, hand);
|
ActionResult<ItemStack> onItemRightClick = item.onItemRightClick(itemUseWorld, player, hand);
|
||||||
ItemStack resultStack = onItemRightClick.getResult();
|
ItemStack resultStack = onItemRightClick.getResult();
|
||||||
if (resultStack != stack || resultStack.getCount() != stack.getCount() || resultStack.getUseDuration() > 0 || resultStack.getDamage() != stack.getDamage()) {
|
if (resultStack != stack || resultStack.getCount() != stack.getCount() || resultStack.getUseDuration() > 0
|
||||||
|
|| resultStack.getDamage() != stack.getDamage()) {
|
||||||
player.setHeldItem(hand, onItemRightClick.getResult());
|
player.setHeldItem(hand, onItemRightClick.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,51 +307,89 @@ public class DeployerHandler {
|
||||||
player.resetActiveHand();
|
player.resetActiveHand();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean safeTryHarvestBlock(PlayerInteractionManager interactionManager, BlockPos clickedPos) {
|
public static boolean tryHarvestBlock(PlayerInteractionManager interactionManager, BlockPos pos) {
|
||||||
BlockState state = interactionManager.world.getBlockState(clickedPos);
|
// <> PlayerInteractionManager#tryHarvestBlock
|
||||||
if (!(state.getBlock() instanceof BeehiveBlock))
|
|
||||||
return interactionManager.tryHarvestBlock(clickedPos);
|
ServerWorld world = interactionManager.world;
|
||||||
else {
|
ServerPlayerEntity player = interactionManager.player;
|
||||||
harvestBeehive(interactionManager, state, clickedPos);
|
BlockState blockstate = world.getBlockState(pos);
|
||||||
}
|
GameType gameType = interactionManager.getGameType();
|
||||||
|
|
||||||
|
if (net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos) == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
TileEntity tileentity = world.getTileEntity(pos);
|
||||||
|
if (player.getHeldItemMainhand()
|
||||||
|
.onBlockStartBreak(pos, player))
|
||||||
|
return false;
|
||||||
|
if (player.canMine(world, pos, gameType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ItemStack prevHeldItem = player.getHeldItemMainhand();
|
||||||
|
ItemStack heldItem = prevHeldItem.copy();
|
||||||
|
|
||||||
|
boolean canHarvest = blockstate.canHarvestBlock(world, pos, player);
|
||||||
|
prevHeldItem.onBlockDestroyed(world, blockstate, pos, player);
|
||||||
|
if (prevHeldItem.isEmpty() && !heldItem.isEmpty())
|
||||||
|
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, heldItem, Hand.MAIN_HAND);
|
||||||
|
if (!blockstate.removedByPlayer(world, pos, player, canHarvest, world.getFluidState(pos)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
blockstate.getBlock()
|
||||||
|
.onPlayerDestroy(world, pos, blockstate);
|
||||||
|
if (!canHarvest)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Block.getDrops(blockstate, world, pos, tileentity, player, prevHeldItem)
|
||||||
|
.forEach(item -> player.inventory.placeItemBackInInventory(world, item));
|
||||||
|
blockstate.spawnAdditionalDrops(world, pos, prevHeldItem);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void harvestBeehive(PlayerInteractionManager interactionManager, BlockState state,
|
public static ActionResultType safeOnUse(BlockState state, World world, BlockPos pos, PlayerEntity player,
|
||||||
BlockPos clickedPos) {
|
Hand hand, BlockRayTraceResult ray) {
|
||||||
// Modified code from PlayerInteractionManager, Block and BeehiveBlock to handle
|
if (state.getBlock() instanceof BeehiveBlock)
|
||||||
// deployers breaking beehives without crash.
|
return safeOnBeehiveUse(state, world, pos, player, hand);
|
||||||
ItemStack itemstack = interactionManager.player.getHeldItemMainhand();
|
return state.onUse(world, player, hand, ray);
|
||||||
ItemStack itemstack1 = itemstack.copy();
|
|
||||||
|
|
||||||
boolean flag1 = state.canHarvestBlock(interactionManager.world, clickedPos, interactionManager.player);
|
|
||||||
itemstack.onBlockDestroyed(interactionManager.world, state, clickedPos, interactionManager.player);
|
|
||||||
if (itemstack.isEmpty() && !itemstack1.isEmpty())
|
|
||||||
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(interactionManager.player, itemstack1,
|
|
||||||
Hand.MAIN_HAND);
|
|
||||||
|
|
||||||
boolean flag = state.removedByPlayer(interactionManager.world, clickedPos, interactionManager.player, flag1,
|
|
||||||
interactionManager.world.getFluidState(clickedPos));
|
|
||||||
if (flag)
|
|
||||||
state.getBlock()
|
|
||||||
.onPlayerDestroy(interactionManager.world, clickedPos, state);
|
|
||||||
|
|
||||||
if (flag && flag1) {
|
|
||||||
interactionManager.player.addStat(Stats.BLOCK_MINED.get(state.getBlock()));
|
|
||||||
interactionManager.player.addExhaustion(0.005F);
|
|
||||||
TileEntity te = interactionManager.world.getTileEntity(clickedPos);
|
|
||||||
ItemStack heldItem = interactionManager.player.getHeldItemMainhand();
|
|
||||||
Block.spawnDrops(state, interactionManager.world, clickedPos, te, interactionManager.player, heldItem);
|
|
||||||
|
|
||||||
if (!interactionManager.world.isRemote && te instanceof BeehiveTileEntity) {
|
|
||||||
BeehiveTileEntity beehivetileentity = (BeehiveTileEntity) te;
|
|
||||||
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, heldItem) == 0) {
|
|
||||||
interactionManager.world.updateComparatorOutputLevel(clickedPos, state.getBlock());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CriteriaTriggers.BEE_NEST_DESTROYED.test(interactionManager.player,
|
protected static ActionResultType safeOnBeehiveUse(BlockState state, World world, BlockPos pos, PlayerEntity player,
|
||||||
state.getBlock(), heldItem, beehivetileentity.getBeeCount());
|
Hand hand) {
|
||||||
|
// <> BeehiveBlock#onUse
|
||||||
|
|
||||||
|
BeehiveBlock block = (BeehiveBlock) state.getBlock();
|
||||||
|
ItemStack prevHeldItem = player.getHeldItem(hand);
|
||||||
|
int honeyLevel = state.get(BeehiveBlock.HONEY_LEVEL);
|
||||||
|
boolean success = false;
|
||||||
|
if (honeyLevel < 5)
|
||||||
|
return ActionResultType.PASS;
|
||||||
|
|
||||||
|
if (prevHeldItem.getItem() == Items.SHEARS) {
|
||||||
|
world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.field_226133_ah_,
|
||||||
|
SoundCategory.NEUTRAL, 1.0F, 1.0F);
|
||||||
|
// <> BeehiveBlock#dropHoneycomb
|
||||||
|
player.inventory.placeItemBackInInventory(world, new ItemStack(Items.field_226635_pU_, 3));
|
||||||
|
prevHeldItem.damageItem(1, player, s -> s.sendBreakAnimation(hand));
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prevHeldItem.getItem() == Items.GLASS_BOTTLE) {
|
||||||
|
prevHeldItem.shrink(1);
|
||||||
|
world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.ITEM_BOTTLE_FILL,
|
||||||
|
SoundCategory.NEUTRAL, 1.0F, 1.0F);
|
||||||
|
ItemStack honeyBottle = new ItemStack(Items.field_226638_pX_);
|
||||||
|
if (prevHeldItem.isEmpty())
|
||||||
|
player.setHeldItem(hand, honeyBottle);
|
||||||
|
else
|
||||||
|
player.inventory.placeItemBackInInventory(world, honeyBottle);
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
return ActionResultType.PASS;
|
||||||
|
|
||||||
|
block.takeHoney(world, state, pos);
|
||||||
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,8 @@ public class FluidPropagator {
|
||||||
if (PumpBlock.isPump(connectedState) && connectedState.get(PumpBlock.FACING)
|
if (PumpBlock.isPump(connectedState) && connectedState.get(PumpBlock.FACING)
|
||||||
.getAxis() == side.getAxis())
|
.getAxis() == side.getAxis())
|
||||||
return false;
|
return false;
|
||||||
|
if (connectedState.has(BlockStateProperties.HONEY_LEVEL))
|
||||||
|
return true;
|
||||||
if (Block.hasSolidSide(connectedState, reader, connectedPos, side.getOpposite()))
|
if (Block.hasSolidSide(connectedState, reader, connectedPos, side.getOpposite()))
|
||||||
return false;
|
return false;
|
||||||
if (!(connectedState.getMaterial()
|
if (!(connectedState.getMaterial()
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.simibubi.create.content.contraptions.fluids;
|
package com.simibubi.create.content.contraptions.fluids;
|
||||||
|
|
||||||
|
import static net.minecraft.state.properties.BlockStateProperties.HONEY_LEVEL;
|
||||||
|
import static net.minecraft.state.properties.BlockStateProperties.WATERLOGGED;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
@ -21,7 +24,6 @@ import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.potion.Effect;
|
import net.minecraft.potion.Effect;
|
||||||
import net.minecraft.potion.EffectInstance;
|
import net.minecraft.potion.EffectInstance;
|
||||||
import net.minecraft.potion.PotionUtils;
|
import net.minecraft.potion.PotionUtils;
|
||||||
import net.minecraft.state.properties.BlockStateProperties;
|
|
||||||
import net.minecraft.tags.FluidTags;
|
import net.minecraft.tags.FluidTags;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
|
@ -71,7 +73,13 @@ public class OpenEndedPipe extends FlowSource {
|
||||||
|
|
||||||
BlockState state = world.getBlockState(outputPos);
|
BlockState state = world.getBlockState(outputPos);
|
||||||
IFluidState fluidState = state.getFluidState();
|
IFluidState fluidState = state.getFluidState();
|
||||||
boolean waterlog = state.has(BlockStateProperties.WATERLOGGED);
|
boolean waterlog = state.has(WATERLOGGED);
|
||||||
|
|
||||||
|
if (state.has(HONEY_LEVEL) && state.get(HONEY_LEVEL) >= 5) {
|
||||||
|
if (!simulate)
|
||||||
|
world.setBlockState(outputPos, state.with(HONEY_LEVEL, 0), 3);
|
||||||
|
return new FluidStack(AllFluids.HONEY.get(), 250);
|
||||||
|
}
|
||||||
|
|
||||||
if (!waterlog && !state.getMaterial()
|
if (!waterlog && !state.getMaterial()
|
||||||
.isReplaceable())
|
.isReplaceable())
|
||||||
|
@ -87,7 +95,7 @@ public class OpenEndedPipe extends FlowSource {
|
||||||
AllTriggers.triggerForNearbyPlayers(AllTriggers.PIPE_SPILL, world, pos, 5);
|
AllTriggers.triggerForNearbyPlayers(AllTriggers.PIPE_SPILL, world, pos, 5);
|
||||||
|
|
||||||
if (waterlog) {
|
if (waterlog) {
|
||||||
world.setBlockState(outputPos, state.with(BlockStateProperties.WATERLOGGED, false), 3);
|
world.setBlockState(outputPos, state.with(WATERLOGGED, false), 3);
|
||||||
world.getPendingFluidTicks()
|
world.getPendingFluidTicks()
|
||||||
.scheduleTick(outputPos, Fluids.WATER, 1);
|
.scheduleTick(outputPos, Fluids.WATER, 1);
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -105,7 +113,7 @@ public class OpenEndedPipe extends FlowSource {
|
||||||
|
|
||||||
BlockState state = world.getBlockState(outputPos);
|
BlockState state = world.getBlockState(outputPos);
|
||||||
IFluidState fluidState = state.getFluidState();
|
IFluidState fluidState = state.getFluidState();
|
||||||
boolean waterlog = state.has(BlockStateProperties.WATERLOGGED);
|
boolean waterlog = state.has(WATERLOGGED);
|
||||||
|
|
||||||
if (!waterlog && !state.getMaterial()
|
if (!waterlog && !state.getMaterial()
|
||||||
.isReplaceable())
|
.isReplaceable())
|
||||||
|
@ -143,7 +151,7 @@ public class OpenEndedPipe extends FlowSource {
|
||||||
AllTriggers.triggerForNearbyPlayers(AllTriggers.PIPE_SPILL, world, pos, 5);
|
AllTriggers.triggerForNearbyPlayers(AllTriggers.PIPE_SPILL, world, pos, 5);
|
||||||
|
|
||||||
if (waterlog) {
|
if (waterlog) {
|
||||||
world.setBlockState(outputPos, state.with(BlockStateProperties.WATERLOGGED, true), 3);
|
world.setBlockState(outputPos, state.with(WATERLOGGED, true), 3);
|
||||||
world.getPendingFluidTicks()
|
world.getPendingFluidTicks()
|
||||||
.scheduleTick(outputPos, Fluids.WATER, 1);
|
.scheduleTick(outputPos, Fluids.WATER, 1);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -142,6 +142,8 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren
|
||||||
public static boolean canConnectTo(ILightReader world, BlockPos neighbourPos, BlockState neighbour, Direction direction) {
|
public static boolean canConnectTo(ILightReader world, BlockPos neighbourPos, BlockState neighbour, Direction direction) {
|
||||||
if (FluidPropagator.hasFluidCapability(world, neighbourPos, direction.getOpposite()))
|
if (FluidPropagator.hasFluidCapability(world, neighbourPos, direction.getOpposite()))
|
||||||
return true;
|
return true;
|
||||||
|
if (neighbour.has(BlockStateProperties.HONEY_LEVEL))
|
||||||
|
return true;
|
||||||
FluidTransportBehaviour transport = TileEntityBehaviour.get(world, neighbourPos, FluidTransportBehaviour.TYPE);
|
FluidTransportBehaviour transport = TileEntityBehaviour.get(world, neighbourPos, FluidTransportBehaviour.TYPE);
|
||||||
BracketedTileEntityBehaviour bracket = TileEntityBehaviour.get(world, neighbourPos, BracketedTileEntityBehaviour.TYPE);
|
BracketedTileEntityBehaviour bracket = TileEntityBehaviour.get(world, neighbourPos, BracketedTileEntityBehaviour.TYPE);
|
||||||
if (isPipe(neighbour))
|
if (isPipe(neighbour))
|
||||||
|
|
Loading…
Reference in a new issue