-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86bf486
commit 2afb176
Showing
9 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/github/elenterius/biomancy/block/MembraneBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.