Skip to content

Commit

Permalink
fix shulker box mattok bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Oct 2, 2024
1 parent 07bfa29 commit 224dac2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
55 changes: 24 additions & 31 deletions src/main/java/com/lothrazar/cyclic/item/equipment/MattockItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
Expand Down Expand Up @@ -44,23 +43,7 @@ public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
BlockHitResult brt = (BlockHitResult) ray;
Direction sideHit = brt.getDirection();
List<BlockPos> shape;
if (sideHit == Direction.UP || sideHit == Direction.DOWN) {
shape = ShapeUtil.squareHorizontalHollow(pos, radius);
if (radius == 2) {
shape.addAll(ShapeUtil.squareHorizontalHollow(pos, radius - 1));
}
}
else if (sideHit == Direction.EAST || sideHit == Direction.WEST) {
int y = 1 + radius - yoff;
int z = radius;
shape = ShapeUtil.squareVerticalZ(pos, y, z);
}
else { //has to be NORTHSOUTH
int x = radius;
int y = 1 + radius - yoff;
shape = ShapeUtil.squareVerticalX(pos, x, y);
}
List<BlockPos> shape = getShape(pos, yoff, sideHit);
for (BlockPos posCurrent : shape) {
BlockState bsCurrent = level.getBlockState(posCurrent);
if (bsCurrent.isAir()) {
Expand All @@ -71,30 +54,19 @@ else if (sideHit == Direction.EAST || sideHit == Direction.WEST) {
&& ForgeEventFactory.doPlayerHarvestCheck(player, bsCurrent, true)
&& this.getDestroySpeed(stack, bsCurrent) > 1
&& (bsCurrent.canHarvestBlock(level, pos, player)
|| bsCurrent.is(this.getTier().getTag())
//this.getTier().getTag().contains(bsCurrent.getBlock())
)
//end of OR
) {
|| bsCurrent.is(this.getTier().getTag()))) {
stack.mineBlock(level, bsCurrent, posCurrent, player);
Block blockCurrent = bsCurrent.getBlock();
if (level.isClientSide) {
level.levelEvent(2001, posCurrent, Block.getId(bsCurrent));
//removedByPlayer
if (blockCurrent.onDestroyedByPlayer(bsCurrent, level, posCurrent, player, true, bsCurrent.getFluidState())) {
blockCurrent.destroy(level, posCurrent, bsCurrent);
}
// stack.onBlockDestroyed(world, bsCurrent, posCurrent, player);//update tool damage
}
else if (player instanceof ServerPlayer) { //Server side, so this works
ServerPlayer mp = (ServerPlayer) player;
int xpGivenOnDrop = ForgeHooks.onBlockBreakEvent(level, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, posCurrent);
if (xpGivenOnDrop >= 0) {
blockCurrent.playerDestroy(level, player, posCurrent, bsCurrent, level.getBlockEntity(posCurrent), stack);
if (blockCurrent.onDestroyedByPlayer(bsCurrent, level, posCurrent, player, true, bsCurrent.getFluidState())
&& level instanceof ServerLevel) {
BlockEntity tile = level.getBlockEntity(posCurrent);
blockCurrent.destroy(level, posCurrent, bsCurrent);
blockCurrent.playerDestroy(level, player, posCurrent, bsCurrent, tile, stack);
blockCurrent.popExperience((ServerLevel) level, posCurrent, xpGivenOnDrop);
}
mp.connection.send(new ClientboundBlockUpdatePacket(level, posCurrent));
Expand All @@ -111,6 +83,27 @@ else if (player instanceof ServerPlayer) { //Server side, so this works
// Items.DIAMOND_SHOVEL.getHarvestLevel(stack, tool, player, blockState));
// }

private List<BlockPos> getShape(BlockPos pos, int yoff, Direction sideHit) {
List<BlockPos> shape;
if (sideHit == Direction.UP || sideHit == Direction.DOWN) {
shape = ShapeUtil.squareHorizontalHollow(pos, radius);
if (radius == 2) {
shape.addAll(ShapeUtil.squareHorizontalHollow(pos, radius - 1));
}
}
else if (sideHit == Direction.EAST || sideHit == Direction.WEST) {
int y = 1 + radius - yoff;
int z = radius;
shape = ShapeUtil.squareVerticalZ(pos, y, z);
}
else { //has to be NORTHSOUTH
int x = radius;
int y = 1 + radius - yoff;
shape = ShapeUtil.squareVerticalX(pos, x, y);
}
return shape;
}

@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (this.getTier() == Tiers.STONE) {
Expand Down
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@
"1.20.10": "fix #2407 item cable guidebook page. Lunchbox when inserting items into it in the inventory with right click; you can also open the lunchbox from your open inventory by right clicking with an empty mouse cursor. Copper, Gold and Netherite chains block model now extends the vanilla reference, meaning they are compatible with any 3D chain model resource pack (such as vanillatweaks). Merge pull request #2402 from Apollounknowndev Fix lime flower generation. Merge pull request #2404 from PocketSizedWeeb: JEI Changes: Fixes issue Solidifier doesn't show liquid requirements #2369; Made the JEI category for the Melter more closely match the Melter's GUI; Moved the JEI 'Show Recipe' area for the machines line up with the progress bar; Moved the JEI \"Show Recipe\" area for the generators line up with the generator name; Every applicable JEI Category got an energy bar added to show max consumed/produced RF; Every applicable JEI Category got a progress bar to show how long the machine will run for; Edited the Melter category texture to add space for energy bar; HashMap memory leak #2383 by caching an instance of Minecraft instead of grabbing it when needed in the Packager's JEI Category; Fix Peat bog cannot be saturated with water-logged leaves #2399 by allowing water-logged blocks to hydrate peat; Solidifier/Melter: fixes desync issue by making all of the processing server sided; Crushing Macerator continues to operate and void items if full #2343; Crushing Macerator allows items to be shift-clicked into output slots #2341; Evaporation Generator:; Removed tank tooltip from before it was rotated; Fixes ; Evaporation Generator 1.19.2 #2322 by implementing a workaround since the fluid portion of FluidTagIngredient was defaulting to empty which was not allowing tagged fluids in the generator; auto crafting machine duplicate glitch #2358 by checking input before processing; Fixed an issue where the preview slot wasn't updating until the machine was processing a craft; Wireless Transmitter:; Fixed gps card inside wireless transmitter disappearing #2403 by adding an onRemove method to the transmitter that drops the gps card"
,"1.20.11":"Fix create new world crash from previous version 'Feature order cycle found minecraft:frozen_peaks': Merge pull request #2426 from Apollounknowndev/trunk/1.20.1 "
,"1.12.12":"Added config controls to the settings in the item.laser_cannon laser beam; along with a new option to render the laser even when you miss. Battery and Claystone Battery now have their storage capacity defined in the config file. Some default config values have been changed, and upper limits have been raised. Increase capacity of the (creative) Infinite Battery. Rebalanced recipes for Breaker and Placer. Fix a bug where if the Item User is configured to consume energy, it still had the capability (connected to cables and showed RF in Jade); fixed to match behavior of other configured blocks "
,"1.12.13":"Block Reach enchantment now has max level 5 to give players more control of how far the reach boost is increased; so levels I through V are now available. Since players normally have 5 blocks of reach distance: level I reaches 8, II reaches 10, III reaches 12, IV reaches 14, and V reaches 16 blocks (+4 for anything beyond with something like apotheosis)"
,"1.12.13":"Fix Mattock not saving contents of Shulker Boxes when mined #2411. Block Reach enchantment now has max level 5 to give players more control of how far the reach boost is increased; so levels I through V are now available. Since players normally have 5 blocks of reach distance: level I reaches 8, II reaches 10, III reaches 12, IV reaches 14, and V reaches 16 blocks (+4 for anything beyond with something like apotheosis)"
}
}

0 comments on commit 224dac2

Please sign in to comment.