Skip to content

Commit

Permalink
fix: fix Fleshkin Chests being breakable by block breaker machines (e…
Browse files Browse the repository at this point in the history
….g. Create Drill)

Closes: #109
  • Loading branch information
Elenterius committed Mar 15, 2024
1 parent 0167e51 commit cc70b33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.network.NetworkHooks;

import javax.annotation.Nullable;
Expand All @@ -67,9 +68,11 @@ public class FleshkinChestBlock extends BaseEntityBlock implements SimpleWaterlo

public static final VoxelShape SHAPE_NORTH_OR_SOUTH = Block.box(0, 0, 1, 16, 13, 15);
public static final VoxelShape SHAPE_WEST_OR_EAST = Block.box(1, 0, 0, 15, 13, 16);
private final float destroySpeed;

public FleshkinChestBlock(Properties builder) {
super(builder);
public FleshkinChestBlock(Properties properties, float destroySpeed) {
super(properties.destroyTime(-1).explosionResistance(1200)); //set destroy speed to -1f to make the block unbreakable for the Create Drill & other stuff
this.destroySpeed = destroySpeed;
registerDefaultState(stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false));
}

Expand Down Expand Up @@ -176,9 +179,10 @@ public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosi
@Override
public float getDestroyProgress(BlockState state, Player player, BlockGetter level, BlockPos pos) {
if (level.getBlockEntity(pos) instanceof IRestrictedInteraction interaction && interaction.isActionAllowed(player, Actions.DESTROY_BLOCK)) {
return super.getDestroyProgress(state, player, level, pos);
int i = ForgeHooks.isCorrectToolForDrops(state, player) ? 30 : 100;
return player.getDigSpeed(state, pos) / destroySpeed / i;
}
return 0f;
return 0;
}

@Override
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/github/elenterius/biomancy/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

public final class ModBlocks {

private static final float FLESH_DESTROY_SPEED = 3f;
private static final float FLESH_EXPLOSION_RESISTANCE = 3f;

public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, BiomancyMod.MOD_ID);

//## Manual Crafting
Expand All @@ -55,7 +58,7 @@ public final class ModBlocks {
public static final RegistryObject<StorageSacBlock> STORAGE_SAC = register("storage_sac", StorageSacBlock::new);
public static final RegistryObject<TongueBlock> TONGUE = register("tongue", TongueBlock::new);
public static final RegistryObject<MawHopperBlock> MAW_HOPPER = register("maw_hopper", MawHopperBlock::new);
public static final RegistryObject<FleshkinChestBlock> FLESHKIN_CHEST = register("fleshkin_chest", FleshkinChestBlock::new);
public static final RegistryObject<FleshkinChestBlock> FLESHKIN_CHEST = register("fleshkin_chest", properties -> new FleshkinChestBlock(properties, FLESH_DESTROY_SPEED));
public static final RegistryObject<OwnablePressurePlateBlock> FLESHKIN_PRESSURE_PLATE = register("fleshkin_pressure_plate", properties -> new OwnablePressurePlateBlock(properties, ModBlockSetTypes.FLESH_SET_TYPE.get()));

//## Building Materials
Expand Down Expand Up @@ -186,25 +189,25 @@ public static BlockBehaviour.Properties copyProperties(BlockBehaviour behaviour)
}

public static BlockBehaviour.Properties createFleshProperties() {
return BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_PINK).strength(3f, 3f).sound(ModSoundTypes.FLESH_BLOCK).isValidSpawn(ModBlocks::isValidFleshkinSpawn);
return BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_PINK).strength(FLESH_DESTROY_SPEED, FLESH_EXPLOSION_RESISTANCE).sound(ModSoundTypes.FLESH_BLOCK).isValidSpawn(ModBlocks::isValidFleshkinSpawn);
}

public static BlockBehaviour.Properties createFleshVeinsProperties() {
return BlockBehaviour.Properties.of()
.strength(3f, 3f)
// .forceSolidOff()
.strength(FLESH_DESTROY_SPEED, FLESH_EXPLOSION_RESISTANCE)
//.forceSolidOff()
.noCollission()
.pushReaction(PushReaction.DESTROY)
.sound(ModSoundTypes.FLESH_BLOCK)
.isValidSpawn(ModBlocks::isValidFleshkinSpawn);
}

public static BlockBehaviour.Properties createToughFleshProperties() {
return createFleshProperties().strength(6f, 12f);
return createFleshProperties().strength(FLESH_DESTROY_SPEED * 2, FLESH_EXPLOSION_RESISTANCE * 4);
}

public static BlockBehaviour.Properties createBonyFleshProperties() {
return BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_PINK).strength(4f, 6f).sound(ModSoundTypes.BONY_FLESH_BLOCK).isValidSpawn(ModBlocks::isValidFleshkinSpawn);
return BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_PINK).strength(FLESH_DESTROY_SPEED + 1, FLESH_EXPLOSION_RESISTANCE * 2).sound(ModSoundTypes.BONY_FLESH_BLOCK).isValidSpawn(ModBlocks::isValidFleshkinSpawn);
}

public static boolean isValidFleshkinSpawn(BlockState state, BlockGetter level, BlockPos pos, EntityType<?> entityType) {
Expand Down

0 comments on commit cc70b33

Please sign in to comment.