Skip to content

Commit

Permalink
Prototype Ectoplasm Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 22, 2024
1 parent 329284d commit 2366dea
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "trailiertales:block/ectoplasm_block"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "trailiertales:block/ectoplasm_block"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"trailiertales:ectoplasm_block"
]
}
5 changes: 5 additions & 0 deletions src/main/generated/data/minecraft/tags/block/impermeable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"trailiertales:ectoplasm_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ectoplasm_block": {
"conditions": {
"items": [
{
"items": "trailiertales:ectoplasm_block"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "minecraft:ectoplasm"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_ectoplasm_block"
]
],
"rewards": {
"recipes": [
"minecraft:ectoplasm"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ectoplasm": {
"conditions": {
"items": [
{
"items": "trailiertales:ectoplasm"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "minecraft:ectoplasm_block"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_ectoplasm"
]
],
"rewards": {
"recipes": [
"minecraft:ectoplasm_block"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "trailiertales:ectoplasm_block"
}
],
"rolls": 1.0
}
]
}
13 changes: 13 additions & 0 deletions src/main/generated/data/trailiertales/recipe/ectoplasm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "trailiertales:ectoplasm_block"
}
],
"result": {
"count": 9,
"id": "trailiertales:ectoplasm"
}
}
18 changes: 18 additions & 0 deletions src/main/generated/data/trailiertales/recipe/ectoplasm_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"#": {
"item": "trailiertales:ectoplasm"
}
},
"pattern": [
"###",
"###",
"###"
],
"result": {
"count": 1,
"id": "trailiertales:ectoplasm_block"
}
}
10 changes: 10 additions & 0 deletions src/main/java/net/frozenblock/trailiertales/TrailierTales.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.frozenblock.lib.FrozenBools;
import net.frozenblock.lib.entrypoint.api.FrozenModInitializer;
import net.frozenblock.lib.feature_flag.api.FrozenFeatureFlags;
import net.frozenblock.lib.gravity.api.GravityAPI;
import net.frozenblock.trailiertales.block.EctoplasmBlock;
import net.frozenblock.trailiertales.config.TTMiscConfig;
import net.frozenblock.trailiertales.datafix.trailiertales.TTDataFixer;
import net.frozenblock.trailiertales.mod_compat.TTModIntegrations;
Expand Down Expand Up @@ -85,6 +87,14 @@ public void onInitialize(String modId, ModContainer container) {
ResourcePackActivationType.DEFAULT_ENABLED : ResourcePackActivationType.NORMAL
);

GravityAPI.MODIFICATIONS.register(gravityContext -> {
if (gravityContext.entity != null) {
if (gravityContext.entity.getInBlockState().getBlock() instanceof EctoplasmBlock) {
gravityContext.gravity = gravityContext.gravity.scale(EctoplasmBlock.GRAVITY_SLOWDOWN);
}
}
});

ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public ResourceLocation getFabricId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.frozenblock.trailiertales.block;

import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

public class EctoplasmBlock extends HalfTransparentBlock {
public static final VoxelShape COLLISION_SHAPE = Shapes.empty();
public static final int LIGHT_BLOCK = 2;
public static final double GRAVITY_SLOWDOWN = 0.4D;
public static final MapCodec<EctoplasmBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
propertiesCodec()
).apply(instance, EctoplasmBlock::new));

public EctoplasmBlock(@NotNull Properties properties) {
super(properties.pushReaction(PushReaction.DESTROY));
}

@NotNull
@Override
protected MapCodec<? extends EctoplasmBlock> codec() {
return CODEC;
}

@Override
@NotNull
public VoxelShape getCollisionShape(@NotNull BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos, @NotNull CollisionContext collisionContext) {
return COLLISION_SHAPE;
}

@Override
public int getLightBlock(@NotNull BlockState blockState, @NotNull BlockGetter blockGetter, @NotNull BlockPos blockPos) {
return LIGHT_BLOCK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static void init() {
BlockEntityWithoutLevelRendererRegistry.register(TTBlocks.COFFIN, TTBlockEntityTypes.COFFIN);

BlockRenderLayerMap renderLayerRegistry = BlockRenderLayerMap.INSTANCE;
renderLayerRegistry.putBlock(TTBlocks.ECTOPLASM_BLOCK, RenderType.translucent());

renderLayerRegistry.putBlock(TTBlocks.POTTED_CYAN_ROSE, RenderType.cutout());
renderLayerRegistry.putBlock(TTBlocks.CYAN_ROSE, RenderType.cutout());
renderLayerRegistry.putBlock(TTBlocks.CYAN_ROSE_CROP, RenderType.cutout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public void generate() {
this.add(TTBlocks.SUSPICIOUS_CLAY, noDrop());
this.add(TTBlocks.COFFIN, noDrop());
this.dropSelf(TTBlocks.SURVEYOR);
this.dropSelf(TTBlocks.ECTOPLASM_BLOCK);
}

public LootTable.@NotNull Builder createMultifaceBlockDrops(Block drop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void generateBlockStateModels(@NotNull BlockModelGenerators generator) {
generator.createBrushableBlock(TTBlocks.SUSPICIOUS_DIRT);
generator.createBrushableBlock(TTBlocks.SUSPICIOUS_CLAY);

createEctoplasmBlock(generator);

generator.family(Blocks.POLISHED_GRANITE).generateFor(BlockFamilies.POLISHED_GRANITE);
generator.family(TTBlocks.GRANITE_BRICKS).generateFor(TTBlocks.FAMILY_GRANITE_BRICK);
generator.family(TTBlocks.MOSSY_GRANITE_BRICKS).generateFor(TTBlocks.FAMILY_MOSSY_GRANITE_BRICK);
Expand Down Expand Up @@ -316,4 +318,12 @@ private static void createDawntrailCrop(@NotNull BlockModelGenerators generator)
);
generator.blockStateOutput.accept(MultiVariantGenerator.multiVariant(crop).with(propertyDispatch));
}

private static void createEctoplasmBlock(@NotNull BlockModelGenerators generator) {
Block block = TTBlocks.ECTOPLASM_BLOCK;
ResourceLocation model = TTConstants.id("block/ectoplasm_block");

generator.blockStateOutput.accept( BlockModelGenerators.createSimpleBlock(block, model));
generator.delegateItemModel(block, model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
import net.minecraft.data.recipes.SimpleCookingRecipeBuilder;
Expand Down Expand Up @@ -43,6 +44,8 @@ public void buildRecipes(RecipeOutput recipeOutput) {
.unlockedBy("has_ectoplasm", has(TTItems.ECTOPLASM))
.save(recipeOutput);

RecipeProvider.nineBlockStorageRecipes(recipeOutput, RecipeCategory.MISC, TTItems.ECTOPLASM, RecipeCategory.MISC, TTBlocks.ECTOPLASM_BLOCK);

ShapedRecipeBuilder.shaped(RecipeCategory.MISC, Blocks.SUSPICIOUS_GRAVEL, 4)
.define('#', Items.GRAVEL)
.pattern(" # ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ protected void addTags(@NotNull HolderLookup.Provider arg) {
this.getOrCreateTagBuilder(BlockTags.FEATURES_CANNOT_REPLACE)
.add(TTBlocks.COFFIN);

this.getOrCreateTagBuilder(BlockTags.FALL_DAMAGE_RESETTING)
.add(TTBlocks.ECTOPLASM_BLOCK);

this.getOrCreateTagBuilder(BlockTags.IMPERMEABLE)
.add(TTBlocks.ECTOPLASM_BLOCK);

// WILDER WILD

this.getOrCreateTagBuilder(getTag("wilderwild:sculk_slab_replaceable_worldgen"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.frozenblock.trailiertales.impl;

public interface InEctoplasmBlockInterface {
void trailierTales$setClipInEctoplasm(boolean clipInEctoplasm);

boolean trailierTales$wasClipInEctoplasm();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.frozenblock.trailiertales.mixin.common.ectoplasm_block;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.frozenblock.trailiertales.block.EctoplasmBlock;
import net.frozenblock.trailiertales.impl.InEctoplasmBlockInterface;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BlockGetter.class)
public interface BlockGetterMixin {

@Shadow
BlockState getBlockState(BlockPos var1);

@Inject(method = "clip", at = @At("HEAD"))
default void trailierTales$setClipInEctoplasmBlock(ClipContext context, CallbackInfoReturnable<BlockHitResult> info) {
if (context.collisionContext instanceof EntityCollisionContext entityCollisionContext) {
Entity entity = entityCollisionContext.getEntity();
if (entity instanceof InEctoplasmBlockInterface inEctoplasmBlockInterface) {
BlockState eyeState = getBlockState(BlockPos.containing(entity.getEyePosition()));
if (eyeState != null) {
inEctoplasmBlockInterface.trailierTales$setClipInEctoplasm(eyeState.getBlock() instanceof EctoplasmBlock);
}
}
}
}

@WrapOperation(
method = "method_17743",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/BlockGetter;clipWithInteractionOverride(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/shapes/VoxelShape;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/phys/BlockHitResult;"
)
)
default BlockHitResult trailierTales$ectoplasmBlockClip(
BlockGetter instance, Vec3 startVec, Vec3 endVec, BlockPos pos, VoxelShape shape, BlockState state, Operation<BlockHitResult> operation,
ClipContext context
) {
if (context.collisionContext instanceof EntityCollisionContext entityCollisionContext) {
if (
entityCollisionContext.getEntity() instanceof InEctoplasmBlockInterface inEctoplasmBlockInterface
&& inEctoplasmBlockInterface.trailierTales$wasClipInEctoplasm()
&& state.getBlock() instanceof EctoplasmBlock
) {
shape = Shapes.empty();
}
}
return operation.call(instance, startVec, endVec, pos, shape, state);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.frozenblock.trailiertales.mixin.common.ectoplasm_block;

import net.frozenblock.trailiertales.impl.InEctoplasmBlockInterface;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(Entity.class)
public class EntityMixin implements InEctoplasmBlockInterface {

@Unique
private boolean trailierTales$clipInEctoplasm;

@Unique
@Override
public void trailierTales$setClipInEctoplasm(boolean clipInEctoplasm) {
this.trailierTales$clipInEctoplasm = clipInEctoplasm;
}

@Unique
@Override
public boolean trailierTales$wasClipInEctoplasm() {
return this.trailierTales$clipInEctoplasm;
}
}
Loading

0 comments on commit 2366dea

Please sign in to comment.