diff --git a/src/main/java/com/minelittlepony/unicopia/block/USlab.java b/src/main/java/com/minelittlepony/unicopia/block/AbstractSlabBlock.java similarity index 84% rename from src/main/java/com/minelittlepony/unicopia/block/USlab.java rename to src/main/java/com/minelittlepony/unicopia/block/AbstractSlabBlock.java index 6d039cda..289927ca 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/USlab.java +++ b/src/main/java/com/minelittlepony/unicopia/block/AbstractSlabBlock.java @@ -5,7 +5,6 @@ import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SlabBlock; -import net.minecraft.block.enums.SlabType; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -13,13 +12,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -public abstract class USlab extends SlabBlock { +public abstract class AbstractSlabBlock extends SlabBlock { protected final T modelBlock; + protected final BlockState modelState; - public USlab(T model, Block.Settings settings) { + @SuppressWarnings("unchecked") + public AbstractSlabBlock(BlockState inherited, Block.Settings settings) { super(settings); - this.modelBlock = model; + modelState = inherited; + modelBlock = (T)inherited.getBlock(); } @Deprecated @@ -33,10 +35,6 @@ public abstract class USlab extends SlabBlock { return modelBlock.isAir(state); } - public boolean isDouble(BlockState state) { - return state.get(TYPE) == SlabType.DOUBLE; - } - @Override public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random rand) { modelBlock.scheduledTick(state, world, pos, rand); diff --git a/src/main/java/com/minelittlepony/unicopia/block/UStairs.java b/src/main/java/com/minelittlepony/unicopia/block/AbstractStairsBlock.java similarity index 84% rename from src/main/java/com/minelittlepony/unicopia/block/UStairs.java rename to src/main/java/com/minelittlepony/unicopia/block/AbstractStairsBlock.java index fe865f06..054ca87e 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UStairs.java +++ b/src/main/java/com/minelittlepony/unicopia/block/AbstractStairsBlock.java @@ -9,14 +9,15 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; -public class UStairs extends StairsBlock { +public abstract class AbstractStairsBlock extends StairsBlock { - protected final Block baseBlock; + protected final T baseBlock; protected final BlockState baseBlockState; - public UStairs(BlockState inherited, Settings settings) { + @SuppressWarnings("unchecked") + public AbstractStairsBlock(BlockState inherited, Settings settings) { super(inherited, settings); - baseBlock = inherited.getBlock(); + baseBlock = (T)inherited.getBlock(); baseBlockState = inherited; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java b/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java index 4bf4e397..41c1d180 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/GlowingGemBlock.java @@ -168,7 +168,7 @@ public class GlowingGemBlock extends TorchBlock implements Gas { } @Override - public CloudType getCloudMaterialType(BlockState blockState) { + public CloudType getGasType(BlockState blockState) { return CloudType.ENCHANTED; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockGrowingCuccoon.java b/src/main/java/com/minelittlepony/unicopia/block/SlimeDropBlock.java similarity index 97% rename from src/main/java/com/minelittlepony/unicopia/block/BlockGrowingCuccoon.java rename to src/main/java/com/minelittlepony/unicopia/block/SlimeDropBlock.java index 905446fa..703b9005 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockGrowingCuccoon.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SlimeDropBlock.java @@ -37,7 +37,7 @@ import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldView; -public class BlockGrowingCuccoon extends Block implements Climbable { +public class SlimeDropBlock extends Block implements Climbable { public static final IntProperty AGE = IntProperty.of("age", 0, 7); public static final EnumProperty SHAPE = EnumProperty.of("shape", Shape.class); @@ -55,7 +55,7 @@ public class BlockGrowingCuccoon extends Block implements Climbable { Block.createCuboidShape(2, 0, 2, 14, 12, 14), }; - public BlockGrowingCuccoon() { + public SlimeDropBlock() { super(FabricBlockSettings.of(UMaterials.HIVE) .ticksRandomly() .breakInstantly() @@ -135,7 +135,7 @@ public class BlockGrowingCuccoon extends Block implements Climbable { } return Math.min(higher.get(AGE), - ((BlockGrowingCuccoon)higher.getBlock()).getMaximumAge(world, pos.up(), higher, false) - 1 + ((SlimeDropBlock)higher.getBlock()).getMaximumAge(world, pos.up(), higher, false) - 1 ); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java index aa9ae4c7..e06ed7a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/block/UBlocks.java @@ -28,11 +28,11 @@ public interface UBlocks { CloudBlock ENCHANTED_CLOUD_BLOCK = register(new CloudBlock(CloudType.ENCHANTED), "enchanted_cloud_block"); CloudBlock DENSE_CLOUD_BLOCK = register(new CloudBlock(CloudType.DENSE), "dense_cloud_block"); - CloudStairsBlock CLOUD_STAIRS = register(new CloudStairsBlock(CLOUD_BLOCK.getDefaultState(), FabricBlockSettings.of(UMaterials.CLOUD).build()), "cloud_stairs"); + CloudStairsBlock CLOUD_STAIRS = register(new CloudStairsBlock<>(CLOUD_BLOCK.getDefaultState(), FabricBlockSettings.of(UMaterials.CLOUD).build()), "cloud_stairs"); - CloudSlabBlock CLOUD_SLAB = register(new CloudSlabBlock<>(CLOUD_BLOCK, UMaterials.CLOUD), "cloud_slab"); - CloudSlabBlock ENCHANTED_CLOUD_SLAB = register(new CloudSlabBlock<>(ENCHANTED_CLOUD_BLOCK, UMaterials.CLOUD), "enchanted_cloud_slab"); - CloudSlabBlock DENSE_CLOUD_SLAB = register(new CloudSlabBlock<>(ENCHANTED_CLOUD_BLOCK, UMaterials.CLOUD), "dense_cloud_slab"); + CloudSlabBlock CLOUD_SLAB = register(new CloudSlabBlock<>(CLOUD_BLOCK.getDefaultState(), UMaterials.CLOUD), "cloud_slab"); + CloudSlabBlock ENCHANTED_CLOUD_SLAB = register(new CloudSlabBlock<>(ENCHANTED_CLOUD_BLOCK.getDefaultState(), UMaterials.CLOUD), "enchanted_cloud_slab"); + CloudSlabBlock DENSE_CLOUD_SLAB = register(new CloudSlabBlock<>(ENCHANTED_CLOUD_BLOCK.getDefaultState(), UMaterials.CLOUD), "dense_cloud_slab"); CloudDoorBlock MISTED_GLASS_DOOR = register(new CloudDoorBlock(), "misted_glass_door"); DutchDoorBlock LIBRARY_DOOR = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "library_door"); @@ -54,7 +54,7 @@ public interface UBlocks { ChitinBlock CHITIN_SHELL_BLOCK = register(new ChitinBlock(), "chitin_shell_block"); Block CHISELED_CHITIN_SHELL_BLOCK = register(new ChiselledChitinBlock(), "chiseled_chitin_shell_block"); - BlockGrowingCuccoon SLIME_DROP = register(new BlockGrowingCuccoon(), "slime_drop"); + SlimeDropBlock SLIME_DROP = register(new SlimeDropBlock(), "slime_drop"); SlimeLayerBlock SLIME_LAYER = register(new SlimeLayerBlock(), "slime_layer"); Block SUGAR_BLOCK = register(new SugarBlock(), "sugar_block"); diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudAnvilBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudAnvilBlock.java index 5da31fa5..fabe852c 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudAnvilBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudAnvilBlock.java @@ -66,7 +66,7 @@ public class CloudAnvilBlock extends AnvilBlock implements Gas { BlockState below = world.getBlockState(pos.down()); if (below.getBlock() instanceof Gas) { - if (((Gas)below.getBlock()).isDense(below)) { + if (((Gas)below.getBlock()).getGasType(below).isDense()) { return; } } @@ -92,7 +92,7 @@ public class CloudAnvilBlock extends AnvilBlock implements Gas { @Override - public CloudType getCloudMaterialType(BlockState blockState) { + public CloudType getGasType(BlockState blockState) { return CloudType.NORMAL; } } diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudBlock.java index 619e2eb8..44dc3b1e 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudBlock.java @@ -10,10 +10,13 @@ import com.minelittlepony.unicopia.util.HoeUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemUsageContext; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; import net.minecraft.util.math.BlockPos; import net.minecraft.world.BlockView; import net.minecraft.world.World; @@ -33,7 +36,29 @@ public class CloudBlock extends Block implements Gas, HoeUtil.Tillable { @Override public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { - return variant == CloudType.NORMAL; + return getGasType(state).isTranslucent(); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getOutlineShape(state, view, pos, context); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getCollisionShape(state, view, pos, context); } @Override @@ -55,7 +80,7 @@ public class CloudBlock extends Block implements Gas, HoeUtil.Tillable { if (beside.getBlock() instanceof Gas) { Gas cloud = ((Gas)beside.getBlock()); - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + if (cloud.getGasType(beside) == getGasType(state)) { return true; } } @@ -94,7 +119,7 @@ public class CloudBlock extends Block implements Gas, HoeUtil.Tillable { } @Override - public CloudType getCloudMaterialType(BlockState blockState) { + public CloudType getGasType(BlockState blockState) { return variant; } diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudDoorBlock.java index 901fc686..30e51d6b 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudDoorBlock.java @@ -1,11 +1,10 @@ package com.minelittlepony.unicopia.gas; import com.minelittlepony.unicopia.block.AbstractDoorBlock; -import com.minelittlepony.unicopia.block.UMaterials; - import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.tools.FabricToolTags; import net.minecraft.block.BlockState; +import net.minecraft.block.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.sound.BlockSoundGroup; @@ -18,14 +17,19 @@ import net.minecraft.world.World; public class CloudDoorBlock extends AbstractDoorBlock implements Gas { public CloudDoorBlock() { - super(FabricBlockSettings.of(UMaterials.CLOUD) - .sounds(BlockSoundGroup.WOOL) + super(FabricBlockSettings.of(Material.GLASS) + .sounds(BlockSoundGroup.GLASS) .hardness(3) .resistance(200) - .breakByTool(FabricToolTags.SHOVELS, 0) + .breakByTool(FabricToolTags.PICKAXES, 0) .build()); } + @Override + public CloudType getGasType(BlockState blockState) { + return CloudType.NORMAL; + } + @Override public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (!getCanInteract(state, player)) { @@ -57,9 +61,4 @@ public class CloudDoorBlock extends AbstractDoorBlock implements Gas { } return -1; } - - @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return CloudType.NORMAL; - } } diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudFarmlandBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudFarmlandBlock.java index 3c4ededc..e895c79b 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudFarmlandBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudFarmlandBlock.java @@ -6,10 +6,13 @@ import com.minelittlepony.unicopia.ducks.Farmland; import net.minecraft.block.BlockState; import net.minecraft.block.FarmlandBlock; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction.Axis; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; @@ -26,7 +29,7 @@ public class CloudFarmlandBlock extends FarmlandBlock implements Farmland, Gas { Gas cloud = ((Gas)beside.getBlock()); if (face.getAxis() == Axis.Y || cloud == this) { - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + if (cloud.getGasType(beside) == getGasType(state)) { return true; } } @@ -56,6 +59,28 @@ public class CloudFarmlandBlock extends FarmlandBlock implements Farmland, Gas { } } + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getOutlineShape(state, view, pos, context); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getCollisionShape(state, view, pos, context); + } + @Deprecated @Override public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) { @@ -66,7 +91,7 @@ public class CloudFarmlandBlock extends FarmlandBlock implements Farmland, Gas { } @Override - public CloudType getCloudMaterialType(BlockState blockState) { + public CloudType getGasType(BlockState blockState) { return CloudType.NORMAL; } diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudFenceBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudFenceBlock.java index 02f35ecc..a7c197e3 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudFenceBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudFenceBlock.java @@ -3,8 +3,11 @@ package com.minelittlepony.unicopia.gas; import net.minecraft.block.BlockState; import net.minecraft.block.FenceBlock; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; @@ -19,11 +22,11 @@ public class CloudFenceBlock extends FenceBlock implements Gas { @Override public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { - return variant == CloudType.NORMAL; + return getGasType(state) == CloudType.NORMAL; } @Override - public CloudType getCloudMaterialType(BlockState blockState) { + public CloudType getGasType(BlockState blockState) { return variant; } @@ -41,6 +44,28 @@ public class CloudFenceBlock extends FenceBlock implements Gas { } } + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getOutlineShape(state, view, pos, context); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getCollisionShape(state, view, pos, context); + } + @Override public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) { if (!applyBouncyness(state, entity)) { diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudInteractionContext.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudInteractionContext.java new file mode 100644 index 00000000..2ef2d1b5 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudInteractionContext.java @@ -0,0 +1,69 @@ +package com.minelittlepony.unicopia.gas; + +import com.minelittlepony.unicopia.EquinePredicates; +import com.minelittlepony.unicopia.entity.CloudEntity; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; + +public interface CloudInteractionContext { + + static CloudInteractionContext of(Entity entity) { + return entity == null ? Impl.EMPTY : new Impl(entity); + } + + default boolean isPlayer() { + return false; + } + + default boolean isPegasis() { + return false; + } + + boolean canTouch(CloudType type); + + class Impl implements CloudInteractionContext { + private static final CloudInteractionContext EMPTY = type -> false; + + private final boolean isPlayer; + private final boolean isPegasis; + + private Impl(Entity entity) { + this.isPlayer = entity instanceof PlayerEntity; + this.isPegasis = isPegasis(entity); + } + + private boolean isPegasis(Entity entity) { + if (entity instanceof PlayerEntity) { + return EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)entity) + || (EquinePredicates.MAGI.test(entity) && CloudEntity.getFeatherEnchantStrength((PlayerEntity)entity) > 0); + } + + if (entity instanceof ItemEntity) { + return EquinePredicates.ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)entity); + } + + if (entity instanceof CloudEntity && entity.hasVehicle()) { + return isPegasis(entity.getVehicle()); + } + + return false; + } + + @Override + public boolean isPlayer() { + return isPlayer; + } + + @Override + public boolean isPegasis() { + return isPegasis; + } + + @Override + public boolean canTouch(CloudType type) { + return type.isTouchable(isPlayer()) || isPegasis(); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudSlabBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudSlabBlock.java index bef9aade..a3820cf7 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudSlabBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudSlabBlock.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.gas; -import com.minelittlepony.unicopia.block.USlab; +import com.minelittlepony.unicopia.block.AbstractSlabBlock; import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.minecraft.block.Block; @@ -8,27 +8,54 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Material; import net.minecraft.block.StairsBlock; import net.minecraft.block.enums.SlabType; +import net.minecraft.entity.EntityContext; import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; -public class CloudSlabBlock extends USlab implements Gas { +public class CloudSlabBlock extends AbstractSlabBlock implements Gas { - public CloudSlabBlock(T modelBlock, Material material) { - super(modelBlock, FabricBlockSettings.of(material).build()); + public CloudSlabBlock(BlockState inherited, Material material) { + super(inherited, FabricBlockSettings.of(material).build()); } @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return modelBlock.getCloudMaterialType(blockState); + public CloudType getGasType(BlockState blockState) { + return modelBlock.getGasType(blockState); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getOutlineShape(state, view, pos, context); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getCollisionShape(state, view, pos, context); } @Override public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { - if (isDouble(state)) { + if (state.get(TYPE) == SlabType.DOUBLE) { if (beside.getBlock() instanceof Gas) { Gas cloud = ((Gas)beside.getBlock()); - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + if (cloud.getGasType(beside) == getGasType(state)) { return true; } } @@ -38,7 +65,7 @@ public class CloudSlabBlock extends USlab implements G if (beside.getBlock() instanceof Gas) { Gas cloud = ((Gas)beside.getBlock()); - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + if (cloud.getGasType(beside) == getGasType(state)) { SlabType half = state.get(TYPE); diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudStairsBlock.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudStairsBlock.java index 923cd951..e74edb85 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudStairsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudStairsBlock.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.gas; -import com.minelittlepony.unicopia.block.UStairs; +import com.minelittlepony.unicopia.block.AbstractStairsBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -8,21 +8,51 @@ import net.minecraft.block.SlabBlock; import net.minecraft.block.enums.BlockHalf; import net.minecraft.block.enums.SlabType; import net.minecraft.entity.EntityContext; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; -public class CloudStairsBlock extends UStairs implements Gas { +public class CloudStairsBlock extends AbstractStairsBlock implements Gas { public CloudStairsBlock(BlockState inherited, Settings settings) { super(inherited, settings); } + @Override + public CloudType getGasType(BlockState state) { + return baseBlock.getGasType(baseBlockState); + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getOutlineShape(state, view, pos, context); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) { + CloudInteractionContext ctx = (CloudInteractionContext)context; + + if (!ctx.canTouch(getGasType(state))) { + return VoxelShapes.empty(); + } + + return super.getCollisionShape(state, view, pos, context); + } + @Override public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { if (beside.getBlock() instanceof Gas) { Gas cloud = ((Gas)beside.getBlock()); - if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { + if (cloud.getGasType(beside) == getGasType(state)) { Direction front = state.get(FACING); BlockHalf half = state.get(HALF); @@ -71,9 +101,4 @@ public class CloudStairsBlock extends UStairs implements Gas { return false; } - - @Override - public CloudType getCloudMaterialType(BlockState blockState) { - return CloudType.NORMAL; - } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/gas/CloudType.java b/src/main/java/com/minelittlepony/unicopia/gas/CloudType.java index 67174b8a..cf4c892e 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/CloudType.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/CloudType.java @@ -1,13 +1,8 @@ package com.minelittlepony.unicopia.gas; -import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.block.UMaterials; -import com.minelittlepony.unicopia.entity.CloudEntity; - import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.minecraft.entity.Entity; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.sound.BlockSoundGroup; public enum CloudType { @@ -25,33 +20,19 @@ public enum CloudType { return settings; } + public boolean isTranslucent() { + return this == NORMAL; + } + + public boolean isDense() { + return this != NORMAL; + } + + public boolean isTouchable(boolean isPlayer) { + return this == ENCHANTED || (this == DENSE && isPlayer); + } + public boolean canInteract(Entity e) { - if (e == null) { - return false; - } - - if (this == ENCHANTED) { - return true; - } - - if (e instanceof PlayerEntity) { - - if (this == DENSE) { - return true; - } - - return EquinePredicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)e) - || (EquinePredicates.MAGI.test(e) && CloudEntity.getFeatherEnchantStrength((PlayerEntity)e) > 0); - } - - if (e instanceof ItemEntity) { - return EquinePredicates.ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)e); - } - - if (e instanceof CloudEntity && e.hasVehicle()) { - return canInteract(e.getVehicle()); - } - - return false; + return CloudInteractionContext.of(e).canTouch(this); } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/gas/Gas.java b/src/main/java/com/minelittlepony/unicopia/gas/Gas.java index 35e5cc56..ec09d689 100644 --- a/src/main/java/com/minelittlepony/unicopia/gas/Gas.java +++ b/src/main/java/com/minelittlepony/unicopia/gas/Gas.java @@ -21,7 +21,7 @@ import net.minecraft.world.World; public interface Gas { - CloudType getCloudMaterialType(BlockState blockState); + CloudType getGasType(BlockState blockState); default boolean handleRayTraceSpecialCases(World world, BlockPos pos, BlockState state) { if (world.isClient) { @@ -35,7 +35,7 @@ public interface Gas { return true; } - CloudType type = getCloudMaterialType(state); + CloudType type = getGasType(state); ItemStack main = player.getMainHandStack(); if (main.isEmpty()) { @@ -51,7 +51,7 @@ public interface Gas { } if (block instanceof Gas) { - CloudType other = ((Gas)block).getCloudMaterialType(heldState); + CloudType other = ((Gas)block).getGasType(heldState); if (other.canInteract(player)) { return false; @@ -88,7 +88,6 @@ public interface Gas { } default boolean applyRebound(Entity entity) { - Vec3d vel = entity.getVelocity(); double y = vel.y; @@ -124,9 +123,8 @@ public interface Gas { return false; } - default boolean getCanInteract(BlockState state, Entity e) { - if (getCloudMaterialType(state).canInteract(e)) { + if (getGasType(state).canInteract(e)) { if (e instanceof ItemEntity) { // @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...") e.setNoGravity(true); @@ -137,10 +135,6 @@ public interface Gas { return false; } - default boolean isDense(BlockState blockState) { - return getCloudMaterialType(blockState) != CloudType.NORMAL; - } - /** * Determines whether falling sand entities should fall through this block. * @param state Our block state @@ -152,7 +146,7 @@ public interface Gas { * @fuf Hacked until we can get mixins to implement a proper hook */ default boolean allowsFallingBlockToPass(BlockState state, BlockView world, BlockPos pos) { - if (isDense(state)) { + if (this.getGasType(state).isDense()) { return false; } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntityContextImpl.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntityContextImpl.java new file mode 100644 index 00000000..881135f4 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinEntityContextImpl.java @@ -0,0 +1,37 @@ +package com.minelittlepony.unicopia.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.gas.CloudInteractionContext; +import com.minelittlepony.unicopia.gas.CloudType; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityContextImpl; + +@Mixin(EntityContextImpl.class) +abstract class MixinEntityContextImpl implements CloudInteractionContext { + private CloudInteractionContext cloudContext; + + @Inject(method = "(Lnet/minecraft/entity/Entity;)V", at = @At("RETURN")) + private void onInit(Entity e, CallbackInfo into) { + cloudContext = CloudInteractionContext.of(e); + } + + @Override + public boolean isPlayer() { + return cloudContext != null && cloudContext.isPlayer(); + } + + @Override + public boolean isPegasis() { + return cloudContext != null && cloudContext.isPegasis(); + } + + @Override + public boolean canTouch(CloudType type) { + return cloudContext != null && cloudContext.canTouch(type); + } +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 08ce4a4e..3c3d4b51 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -7,6 +7,7 @@ "mixins": [ "CriterionsRegistry", "MixinBlockItem", + "MixinEntityContextImpl", "MixinFarmlandBlock", "MixinHoeItem", "MixinItem",