Skip to content

Commit

Permalink
Fixed TackleBox not dropping content, when broken
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Dec 17, 2021
1 parent c80be20 commit a3c006b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
minecraft_version=1.18
forge_version=38.0.15
mod_version=2.3.0
jei_version=9.0.0.40
minecraft_version=1.18.1
forge_version=39.0.5
mod_version=2.3.1
jei_version=9.1.0.46
ct_version=7.7.1.126

org.gradle.jvmargs=-Xmx4G
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
Expand All @@ -36,6 +37,7 @@
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.items.CapabilityItemHandler;
Expand Down Expand Up @@ -126,14 +128,6 @@ public void setPlacedBy(@Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Bl
}
}

@Override
public void onRemove(BlockState state, @Nonnull Level world, @Nonnull BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
world.updateNeighbourForOutputSignal(pos, this);
super.onRemove(state, world, pos, newState, isMoving);
}
}

@Override
@Nonnull
public BlockState updateShape(BlockState state, @Nonnull Direction facing, @Nonnull BlockState facingState, @Nonnull LevelAccessor world, @Nonnull BlockPos currentPos, @Nonnull BlockPos facingPos) {
Expand Down Expand Up @@ -187,28 +181,47 @@ public boolean isPathfindable(@Nonnull BlockState state, @Nonnull BlockGetter bl
}

@Override
public void playerDestroy(@Nonnull Level world, Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity tileEntity, @Nonnull ItemStack stack) {
public void onRemove(BlockState state, @Nonnull Level level, @Nonnull BlockPos pos, @Nonnull BlockState newState, boolean isMoving) {
if (!state.is(newState.getBlock())) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof TackleBoxTileEntity) {
level.updateNeighbourForOutputSignal(pos, this);

ItemStack tackleBox = new ItemStack(this);
blockEntity.saveToItem(tackleBox);
Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), tackleBox);
super.onRemove(state, level, pos, newState, isMoving);
}
}
}

@Override
public void playerDestroy(@Nonnull Level level, Player player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity tileEntity, @Nonnull ItemStack stack) {
player.awardStat(Stats.BLOCK_MINED.get(this));
player.causeFoodExhaustion(0.005F);
if (tileEntity != null) {
ItemStack tackleBox = new ItemStack(this);
tileEntity.saveToItem(tackleBox);
popResource(world, pos, tackleBox);
}
}

@Override
public void onBlockExploded(BlockState state, Level world, BlockPos pos, Explosion explosion) {
if (!world.isClientSide) {
this.dropInventory(world, pos);
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos, Player player) {
ItemStack cloneItemStack = super.getCloneItemStack(state, target, level, pos, player);
level.getBlockEntity(pos, AquaBlockEntities.TACKLE_BOX.get()).ifPresent((blockEntity) -> {
blockEntity.saveToItem(cloneItemStack);
});
return cloneItemStack;
}

@Override
public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) {
if (!level.isClientSide) {
this.dropInventory(level, pos);
}
super.onBlockExploded(state, world, pos, explosion);
super.onBlockExploded(state, level, pos, explosion);
}

private void dropInventory(Level world, BlockPos pos) {
BlockEntity tileEntity = world.getBlockEntity(pos);
private void dropInventory(Level level, BlockPos pos) {
BlockEntity tileEntity = level.getBlockEntity(pos);
if (tileEntity != null) {
tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(handler -> StackHelper.dropInventory(world, pos, handler));
tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).ifPresent(handler -> StackHelper.dropInventory(level, pos, handler));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void render(@Nonnull T tackleBox, float partialTicks, @Nonnull PoseStack

DoubleBlockCombiner.NeighborCombineResult<?> callbackWrapper = DoubleBlockCombiner.Combiner::acceptNone;
float angle = tackleBox.getOpenNess(partialTicks);
//System.out.println("angle: " + angle);
angle = 1.0F - angle;
angle = 1.0F - angle * angle * angle;
int brightness = ((Int2IntFunction) callbackWrapper.apply(new BrightnessCombiner())).applyAsInt(combinedLight);
Expand Down

0 comments on commit a3c006b

Please sign in to comment.