Skip to content

Commit

Permalink
feat: add Fleshy Membrane block
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Aug 11, 2023
1 parent 86bf486 commit 2afb176
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ private void addBlockTranslations() {
addBlock(ModBlocks.BLUE_BIO_LANTERN, "Blue Bio-Lantern", "A bioluminescent light source. This one is blue!");
addBlock(ModBlocks.TENDON_CHAIN, "Tendon Chain", "A chain made of tendons.");
addBlock(ModBlocks.VIAL_HOLDER, "Vial Holder", "Display and organize your serums.");
addBlock(ModBlocks.FLESH_MEMBRANE, "Fleshy Membrane", "Window made of gelatinous-like membrane reinforced with elastic fibers.\n\nBaby mobs diffuse through the membrane.");

addBlock(ModBlocks.PRIMAL_FLESH, "Primal Flesh Block", "Primitive and pure, you better not touch this with your dirty mitts.");
addBlock(ModBlocks.PRIMAL_FLESH_SLAB, "Primal Flesh Slab", "Primitive and pure, you better not touch this with your dirty mitts.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ protected void addTables() {
add(ModBlocks.MALIGNANT_FLESH_VEINS.get(), block -> createMultifaceBlockDrops(block, HAS_SHEARS_OR_SILK_TOUCH));

dropSelf(ModBlocks.VOICE_BOX.get());
dropSelf(ModBlocks.FLESH_MEMBRANE.get());
dropSelf(ModBlocks.FLESH_IRIS_DOOR.get());
dropSelf(ModBlocks.FLESH_FENCE.get());
dropSelf(ModBlocks.FLESH_FENCE_GATE.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected void registerStatesAndModels() {
irisDoor(ModBlocks.FLESH_IRIS_DOOR, true);
fleshDoor(ModBlocks.FLESH_DOOR);
fleshSpikes(ModBlocks.FLESH_SPIKE);
translucentBlockWithItem(ModBlocks.FLESH_MEMBRANE);
bioLantern(ModBlocks.YELLOW_BIO_LANTERN);
bioLantern(ModBlocks.BLUE_BIO_LANTERN);
tendonChain(ModBlocks.TENDON_CHAIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,13 @@ private void registerBioForgeRecipes(Consumer<FinishedRecipe> consumer) {
.setCategory(ModBioForgeTabs.BLOCKS)
.unlockedBy(ModItems.BONE_FRAGMENTS.get()).save(consumer);

BioForgeRecipeBuilder.create(ModItems.FLESH_MEMBRANE.get())
.addIngredient(ModItems.ELASTIC_FIBERS.get(), 2)
.addIngredient(ModItems.BILE.get(), 4)
.addIngredient(ModItems.GEM_FRAGMENTS.get(), 1)
.setCategory(ModBioForgeTabs.MISC)
.unlockedBy(ModItems.ELASTIC_FIBERS.get()).save(consumer);

BioForgeRecipeBuilder.create(ModItems.FLESH_FENCE.get(), 4)
.addIngredient(ModItems.FLESH_BITS.get(), fleshBlockCost)
.addIngredient(ModItems.BONE_FRAGMENTS.get(), 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected void addTags() {
ModBlocks.PRIMAL_FLESH_SLAB.get(),
ModBlocks.MALIGNANT_FLESH_SLAB.get()
);

tag(BlockTags.IMPERMEABLE).add(ModBlocks.FLESH_MEMBRANE.get());
}

private void addFleshyBlocksToHoeTag() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.github.elenterius.biomancy.block;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.HalfTransparentBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class MembraneBlock extends HalfTransparentBlock {

protected final IgnoreEntityCollisionPredicate ignoreEntityCollisionPredicate;

public MembraneBlock(BlockBehaviour.Properties properties, IgnoreEntityCollisionPredicate predicate) {
super(properties);
ignoreEntityCollisionPredicate = predicate;
}

public VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return Shapes.empty();
}

public float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) {
return 1f;
}

public boolean propagatesSkylightDown(BlockState state, BlockGetter level, BlockPos pos) {
return true;
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
if (context instanceof EntityCollisionContext entityContext && ignoreEntityCollisionPredicate.test(state, level, pos, entityContext.getEntity())) {
return Shapes.empty();
}
return state.getShape(level, pos);
}

/**
* WARNING: broken Forge API
* <p>
* Gets the path type of this block when an entity is pathfinding. When
* {@code null}, uses vanilla behavior.
*
* @param mob is always null
* @see <a href="https://github.com/MinecraftForge/MinecraftForge/issues/9283">Forge Issue 9283</a>
*/
@Override
public @Nullable BlockPathTypes getBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob) {
// if (ignoreEntityCollisionPredicate.test(state, level, pos, mob)) return BlockPathTypes.DOOR_OPEN; //doesn't work due to broken Forge API
return BlockPathTypes.STICKY_HONEY;
}

public interface IgnoreEntityCollisionPredicate {
IgnoreEntityCollisionPredicate IS_BABY_MOB = (state, level, pos, entity) -> entity instanceof LivingEntity livingEntity && livingEntity.isBaby();
IgnoreEntityCollisionPredicate IS_ADULT_MOB = (state, level, pos, entity) -> entity instanceof LivingEntity livingEntity && !livingEntity.isBaby();
IgnoreEntityCollisionPredicate IS_ITEM = (state, level, pos, entity) -> entity instanceof ItemEntity;

boolean test(BlockState state, BlockGetter level, BlockPos pos, @Nullable Entity entity);
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/github/elenterius/biomancy/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public final class ModBlocks {

//## Misc
public static final RegistryObject<VoiceBoxBlock> VOICE_BOX = register("voice_box", VoiceBoxBlock::new);
public static final RegistryObject<MembraneBlock> FLESH_MEMBRANE = register("flesh_membrane", props -> {
props = props.noOcclusion().isRedstoneConductor(ModBlocks::neverValid).isSuffocating(ModBlocks::neverValid).isViewBlocking(ModBlocks::neverValid);
return new MembraneBlock(props, MembraneBlock.IgnoreEntityCollisionPredicate.IS_BABY_MOB);
});
public static final RegistryObject<LadderBlock> FLESH_LADDER = register("flesh_ladder", () -> new LadderBlock(createFleshyBoneProperties().noOcclusion()));
public static final RegistryObject<FleshFenceBlock> FLESH_FENCE = register("flesh_fence", FleshFenceBlock::new);
public static final RegistryObject<FleshFenceGateBlock> FLESH_FENCE_GATE = register("flesh_fence_gate", () -> new FleshFenceGateBlock(createFleshyBoneProperties().noOcclusion()));
Expand Down Expand Up @@ -171,6 +175,15 @@ public static boolean isValidFleshkinSpawn(BlockState state, BlockGetter level,
return entityType.is(ModEntityTags.FLESHKIN) && state.isFaceSturdy(level, pos, Direction.UP);
}

public static boolean neverValid(BlockState state, BlockGetter level, BlockPos pos, EntityType<?> entityType) {
return false;
}

public static boolean neverValid(BlockState state, BlockGetter level, BlockPos pos) {
return false;
}


interface StairBlockFactory<T extends StairBlock> {
T create(Supplier<BlockState> state, BlockBehaviour.Properties properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public final class ModItems {

//## Misc
public static final RegistryObject<SimpleBlockItem> VOICE_BOX = registerSimpleBlockItem(ModBlocks.VOICE_BOX, () -> createProperties().tab(null));
public static final RegistryObject<SimpleBlockItem> FLESH_MEMBRANE = registerSimpleBlockItem(ModBlocks.FLESH_MEMBRANE);
public static final RegistryObject<SimpleBlockItem> FLESH_LADDER = registerSimpleBlockItem(ModBlocks.FLESH_LADDER);
public static final RegistryObject<SimpleBlockItem> FLESH_FENCE = registerSimpleBlockItem(ModBlocks.FLESH_FENCE);
public static final RegistryObject<SimpleBlockItem> FLESH_FENCE_GATE = registerSimpleBlockItem(ModBlocks.FLESH_FENCE_GATE);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2afb176

Please sign in to comment.