diff --git a/src/main/java/com/yipkei/vanilladdition/VanillaAddition.java b/src/main/java/com/yipkei/vanilladdition/VanillaAddition.java index faad52f..9718ec0 100644 --- a/src/main/java/com/yipkei/vanilladdition/VanillaAddition.java +++ b/src/main/java/com/yipkei/vanilladdition/VanillaAddition.java @@ -9,8 +9,6 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.registry.FuelRegistry; -import net.fabricmc.fabric.impl.blockrenderlayer.BlockRenderLayerMapImpl; -import net.minecraft.client.render.RenderLayer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +39,6 @@ public void onInitialize() { FuelRegistry.INSTANCE.add(ModBlocks.COMPRESS_WOOL, 800); - BlockRenderLayerMapImpl blockRenderLayerMap = new BlockRenderLayerMapImpl(); - blockRenderLayerMap.putBlocks(RenderLayer.getTranslucent(), ModBlocks.ICE_SLAB, ModBlocks.ICE_STAIRS, ModBlocks.ICE_WALL); + } } \ No newline at end of file diff --git a/src/main/java/com/yipkei/vanilladdition/VanillaAdditionClient.java b/src/main/java/com/yipkei/vanilladdition/VanillaAdditionClient.java index fdc7485..5b8c67c 100644 --- a/src/main/java/com/yipkei/vanilladdition/VanillaAdditionClient.java +++ b/src/main/java/com/yipkei/vanilladdition/VanillaAdditionClient.java @@ -1,10 +1,14 @@ package com.yipkei.vanilladdition; +import com.yipkei.vanilladdition.init.ModBlocks; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.impl.blockrenderlayer.BlockRenderLayerMapImpl; +import net.minecraft.client.render.RenderLayer; public class VanillaAdditionClient implements ClientModInitializer { @Override public void onInitializeClient() { - + BlockRenderLayerMapImpl blockRenderLayerMap = new BlockRenderLayerMapImpl(); + blockRenderLayerMap.putBlocks(RenderLayer.getTranslucent(), ModBlocks.ICE_SLAB, ModBlocks.ICE_STAIRS, ModBlocks.ICE_WALL); } } diff --git a/src/main/java/com/yipkei/vanilladdition/block/TranslucentIce.java b/src/main/java/com/yipkei/vanilladdition/block/AbstractTranslucentBlock.java similarity index 50% rename from src/main/java/com/yipkei/vanilladdition/block/TranslucentIce.java rename to src/main/java/com/yipkei/vanilladdition/block/AbstractTranslucentBlock.java index 2ca2c26..f74d49a 100644 --- a/src/main/java/com/yipkei/vanilladdition/block/TranslucentIce.java +++ b/src/main/java/com/yipkei/vanilladdition/block/AbstractTranslucentBlock.java @@ -1,4 +1,4 @@ package com.yipkei.vanilladdition.block; -public interface TranslucentIce { +public interface AbstractTranslucentBlock { } diff --git a/src/main/java/com/yipkei/vanilladdition/block/IceSlab.java b/src/main/java/com/yipkei/vanilladdition/block/IceSlab.java deleted file mode 100644 index bbd7695..0000000 --- a/src/main/java/com/yipkei/vanilladdition/block/IceSlab.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.yipkei.vanilladdition.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.IceBlock; -import net.minecraft.block.SlabBlock; -import net.minecraft.block.enums.BlockHalf; -import net.minecraft.block.enums.SlabType; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.Direction; - -import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; - -public class IceSlab extends SlabBlock implements TranslucentIce { - public IceSlab(Settings settings) { - super(settings); - } - - @Override - protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { - if (!(stateFrom.getBlock() instanceof TranslucentIce)) { - return super.isSideInvisible(state, stateFrom, direction); - } - - if (stateFrom.getBlock() instanceof IceBlock){ - switch (state.get(Properties.SLAB_TYPE)){ - case DOUBLE -> { - return true; - } - case TOP -> { - if (direction != Direction.DOWN) return true; - return super.isSideInvisible(state, stateFrom, direction); - } - case BOTTOM -> { - if (direction != Direction.UP) return true; - return super.isSideInvisible(state, stateFrom, direction); - } - } - } - - if (stateFrom.getBlock() instanceof IceSlab) { - switch (state.get(Properties.SLAB_TYPE)){ - case DOUBLE -> { - if (hasCompleteSlabSurface(stateFrom,direction.getOpposite())) return true; - } - case TOP -> { - if ((direction == Direction.UP && stateFrom.get(Properties.SLAB_TYPE) != SlabType.TOP) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.SLAB_TYPE) != SlabType.BOTTOM)) return true; - } - case BOTTOM -> { - if ((direction == Direction.DOWN && stateFrom.get(Properties.SLAB_TYPE) != SlabType.BOTTOM)||((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.SLAB_TYPE) != SlabType.TOP)) return true; - } - } - return super.isSideInvisible(state, stateFrom, direction); - } - - if (stateFrom.getBlock() instanceof IceStairs){ - switch (state.get(Properties.SLAB_TYPE)){ - case DOUBLE -> { - if (hasCompleteStairSurface(stateFrom,direction.getOpposite())) return true; - } - case TOP -> { - if ((direction == Direction.UP && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.TOP)) return true; - } - case BOTTOM -> { - if ((direction == Direction.DOWN && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.TOP) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM)) return true; - } - - } - } - - - return super.isSideInvisible(state, stateFrom, direction); - } -} diff --git a/src/main/java/com/yipkei/vanilladdition/block/IceStairs.java b/src/main/java/com/yipkei/vanilladdition/block/IceStairs.java deleted file mode 100644 index 59c9bf1..0000000 --- a/src/main/java/com/yipkei/vanilladdition/block/IceStairs.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.yipkei.vanilladdition.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.IceBlock; -import net.minecraft.block.StairsBlock; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.Direction; - -import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; - -public class IceStairs extends StairsBlock implements TranslucentIce { - public IceStairs(BlockState baseBlockState, Settings settings) { - super(baseBlockState, settings); - } - - @Override - protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { - - if (!(stateFrom.getBlock() instanceof TranslucentIce)) - return super.isSideInvisible(state, stateFrom, direction); - - if (stateFrom.getBlock() instanceof IceBlock) return true; - - if (stateFrom.getBlock() instanceof IceStairs) { - if (hasCompleteStairSurface(stateFrom, direction.getOpposite())) return true; - Direction facing = state.get(Properties.HORIZONTAL_FACING); - if (state.get(Properties.BLOCK_HALF) == stateFrom.get(Properties.BLOCK_HALF)) { - if (direction.getAxis() == facing.getAxis()) { - if (facing == stateFrom.get(Properties.HORIZONTAL_FACING)) - return super.isSideInvisible(state, stateFrom, direction); - return true; - } - if (direction.getAxis() == Direction.Axis.Y){ - return super.isSideInvisible(state, stateFrom, direction); - } - return true; - } - - } - - if (stateFrom.getBlock() instanceof IceSlab && hasCompleteSlabSurface(stateFrom, direction.getOpposite())) - return true; - return super.isSideInvisible(state, stateFrom, direction); - } -} - diff --git a/src/main/java/com/yipkei/vanilladdition/block/IceWall.java b/src/main/java/com/yipkei/vanilladdition/block/IceWall.java deleted file mode 100644 index abf60e7..0000000 --- a/src/main/java/com/yipkei/vanilladdition/block/IceWall.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.yipkei.vanilladdition.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.IceBlock; -import net.minecraft.block.WallBlock; -import net.minecraft.util.math.Direction; - -import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; - -public class IceWall extends WallBlock implements TranslucentIce { - public IceWall(Settings settings) { - super(settings); - } - - @Override - protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { - if (!(stateFrom.getBlock() instanceof TranslucentIce)){ - return super.isSideInvisible(state, stateFrom, direction); - } - - if (stateFrom.getBlock() instanceof IceWall){ - return true; - } - - if (direction != Direction.UP){ - if (stateFrom.getBlock() instanceof IceBlock) return true; - if (stateFrom.getBlock() instanceof IceStairs) { - if (hasCompleteStairSurface(stateFrom,direction.getOpposite())) return true; - return super.isSideInvisible(state, stateFrom, direction); - } - if (stateFrom.getBlock() instanceof IceSlab){ - if (hasCompleteSlabSurface(stateFrom,direction.getOpposite())) return true; - return super.isSideInvisible(state, stateFrom, direction); - } - } - - return super.isSideInvisible(state, stateFrom, direction); - } -} diff --git a/src/main/java/com/yipkei/vanilladdition/block/TranslucentSlab.java b/src/main/java/com/yipkei/vanilladdition/block/TranslucentSlab.java new file mode 100644 index 0000000..cff6ed8 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/block/TranslucentSlab.java @@ -0,0 +1,71 @@ +package com.yipkei.vanilladdition.block; + +import net.minecraft.block.*; +import net.minecraft.block.enums.BlockHalf; +import net.minecraft.block.enums.SlabType; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.Direction; + +import static com.yipkei.vanilladdition.helper.BlockStateHelper.hasCompleteSlabSurface; +import static com.yipkei.vanilladdition.helper.BlockStateHelper.hasCompleteStairSurface; + +public class TranslucentSlab extends SlabBlock implements AbstractTranslucentBlock{ + public TranslucentSlab(AbstractBlock.Settings settings) { + super(settings); + } + + private Block blockSeries; + + public Block setBlockSeriesAtSetting(Block block){ + this.setBlockSeries(block); + return this; + } + + public void setBlockSeries(Block block){ + this.blockSeries = block; + } + + public Block getBlockSeries(){ + return blockSeries; + } + + @Override + protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + if (!(stateFrom.getBlock() instanceof AbstractTranslucentBlock)) { + return super.isSideInvisible(state, stateFrom, direction); + } + + if (stateFrom.getBlock() instanceof TranslucentBlock) { + if (this.getBlockSeries() != stateFrom.getBlock()){ + return super.isSideInvisible(state, stateFrom, direction); + } + return switch (state.get(Properties.SLAB_TYPE)) { + case DOUBLE -> true; + case TOP -> direction != Direction.DOWN || super.isSideInvisible(state, stateFrom, direction); + case BOTTOM -> direction != Direction.UP || super.isSideInvisible(state, stateFrom, direction); + }; + } + + if (stateFrom.getBlock() instanceof TranslucentSlab) { + if (this.getBlockSeries() != ((TranslucentSlab)(stateFrom.getBlock())).getBlockSeries()) + return super.isSideInvisible(state, stateFrom, direction); + return switch (state.get(Properties.SLAB_TYPE)){ + case DOUBLE -> (hasCompleteSlabSurface(stateFrom,direction.getOpposite())) || super.isSideInvisible(state, stateFrom, direction); + case TOP -> ((direction == Direction.UP && stateFrom.get(Properties.SLAB_TYPE) != SlabType.TOP) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.SLAB_TYPE) != SlabType.BOTTOM)) || super.isSideInvisible(state, stateFrom, direction); + case BOTTOM -> ((direction == Direction.DOWN && stateFrom.get(Properties.SLAB_TYPE) != SlabType.BOTTOM)||((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.SLAB_TYPE) != SlabType.TOP)) || super.isSideInvisible(state, stateFrom, direction); + }; + } + + if (stateFrom.getBlock() instanceof TranslucentStairs){ + if (this.getBlockSeries() != ((TranslucentStairs)(stateFrom.getBlock())).getBlockSeries()) + return super.isSideInvisible(state, stateFrom, direction); + return switch (state.get(Properties.SLAB_TYPE)){ + case DOUBLE -> (hasCompleteStairSurface(stateFrom,direction.getOpposite())) || super.isSideInvisible(state, stateFrom, direction); + case TOP -> ((direction == Direction.UP && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.TOP)) || super.isSideInvisible(state, stateFrom, direction); + case BOTTOM -> ((direction == Direction.DOWN && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.TOP) || ((direction.getAxis() != Direction.Axis.Y) && stateFrom.get(Properties.BLOCK_HALF) == BlockHalf.BOTTOM)) || super.isSideInvisible(state, stateFrom, direction); + }; + } + + return super.isSideInvisible(state, stateFrom, direction); + } +} diff --git a/src/main/java/com/yipkei/vanilladdition/block/TranslucentStairs.java b/src/main/java/com/yipkei/vanilladdition/block/TranslucentStairs.java new file mode 100644 index 0000000..247e4ed --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/block/TranslucentStairs.java @@ -0,0 +1,64 @@ +package com.yipkei.vanilladdition.block; + +import net.minecraft.block.*; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.Direction; + +import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; + +public class TranslucentStairs extends StairsBlock implements AbstractTranslucentBlock { + public TranslucentStairs(BlockState baseBlockState, Settings settings) { + super(baseBlockState, settings); + } + + private Block blockSeries; + + public Block setBlockSeriesAtSetting(Block block){ + this.setBlockSeries(block); + return this; + } + + public void setBlockSeries(Block block){ + this.blockSeries = block; + } + + public Block getBlockSeries(){ + return blockSeries; + } + + @Override + protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + + if (!(stateFrom.getBlock() instanceof AbstractTranslucentBlock)) + return super.isSideInvisible(state, stateFrom, direction); + + if (stateFrom.getBlock() instanceof TranslucentBlock) { + return (this.getBlockSeries() == stateFrom.getBlock()) || super.isSideInvisible(state, stateFrom, direction); + } + + if (this.getBlockSeries() == stateFrom.getBlock()) return true; + + if (stateFrom.getBlock() instanceof TranslucentStairs) { + if (this.getBlockSeries() != ((TranslucentStairs)(stateFrom.getBlock())).getBlockSeries()) + return super.isSideInvisible(state, stateFrom, direction); + if (hasCompleteStairSurface(stateFrom, direction.getOpposite())) return true; + Direction facing = state.get(Properties.HORIZONTAL_FACING); + if (state.get(Properties.BLOCK_HALF) == stateFrom.get(Properties.BLOCK_HALF)) { + if (direction.getAxis() == facing.getAxis()) { + if (facing == stateFrom.get(Properties.HORIZONTAL_FACING)) + return super.isSideInvisible(state, stateFrom, direction); + return true; + } + if (direction.getAxis() == Direction.Axis.Y){ + return super.isSideInvisible(state, stateFrom, direction); + } + return true; + } + } + + if (stateFrom.getBlock() instanceof TranslucentSlab && this.getBlockSeries() == ((TranslucentSlab)(stateFrom.getBlock())).getBlockSeries() && hasCompleteSlabSurface(stateFrom, direction.getOpposite())) + return true; + return super.isSideInvisible(state, stateFrom, direction); + } +} + diff --git a/src/main/java/com/yipkei/vanilladdition/block/TranslucentWall.java b/src/main/java/com/yipkei/vanilladdition/block/TranslucentWall.java new file mode 100644 index 0000000..9db9adc --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/block/TranslucentWall.java @@ -0,0 +1,48 @@ +package com.yipkei.vanilladdition.block; + +import net.minecraft.block.*; +import net.minecraft.util.math.Direction; + +import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; + +public class TranslucentWall extends WallBlock implements AbstractTranslucentBlock { + public TranslucentWall(Settings settings) { + super(settings); + } + + private Block blockSeries; + + public Block setBlockSeriesAtSetting(Block block){ + this.setBlockSeries(block); + return this; + } + + public void setBlockSeries(Block block){ + this.blockSeries = block; + } + + public Block getBlockSeries(){ + return blockSeries; + } + + @Override + protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + if (!(stateFrom.getBlock() instanceof AbstractTranslucentBlock)){ + return super.isSideInvisible(state, stateFrom, direction); + } + + if (stateFrom.getBlock() instanceof TranslucentBlock || stateFrom.getBlock() instanceof TranslucentWall) { + return (this.getBlockSeries() == stateFrom.getBlock()) || super.isSideInvisible(state, stateFrom, direction); + } + + if (stateFrom.getBlock() instanceof TranslucentStairs) { + return (this.getBlockSeries() == ((TranslucentStairs)(stateFrom.getBlock())).getBlockSeries() && hasCompleteStairSurface(stateFrom,direction.getOpposite())) || super.isSideInvisible(state, stateFrom, direction); + } + + if (stateFrom.getBlock() instanceof TranslucentSlab){ + return (this.getBlockSeries() == ((TranslucentSlab)(stateFrom.getBlock())).getBlockSeries() && hasCompleteSlabSurface(stateFrom,direction.getOpposite())) || super.isSideInvisible(state, stateFrom, direction); + } + return super.isSideInvisible(state, stateFrom, direction); + } + +} diff --git a/src/main/java/com/yipkei/vanilladdition/init/ModBlocks.java b/src/main/java/com/yipkei/vanilladdition/init/ModBlocks.java index ed15ce3..baf8394 100644 --- a/src/main/java/com/yipkei/vanilladdition/init/ModBlocks.java +++ b/src/main/java/com/yipkei/vanilladdition/init/ModBlocks.java @@ -1,9 +1,9 @@ package com.yipkei.vanilladdition.init; import com.yipkei.vanilladdition.VanillaAddition; -import com.yipkei.vanilladdition.block.IceSlab; -import com.yipkei.vanilladdition.block.IceStairs; -import com.yipkei.vanilladdition.block.IceWall; +import com.yipkei.vanilladdition.block.TranslucentSlab; +import com.yipkei.vanilladdition.block.TranslucentStairs; +import com.yipkei.vanilladdition.block.TranslucentWall; import net.minecraft.block.*; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; @@ -86,9 +86,9 @@ public class ModBlocks extends Blocks{ public static final Block GLOWSTONE_STAIRS = registerBlocks("glowstone_stairs", new StairsBlock(Blocks.GLOWSTONE.getDefaultState(),AbstractBlock.Settings.copy(GLOWSTONE))); public static final Block GLOWSTONE_SLAB = registerBlocks("glowstone_slab", new SlabBlock(AbstractBlock.Settings.copy(GLOWSTONE))); - public static final Block ICE_WALL = registerBlocks("ice_wall", new IceWall(AbstractBlock.Settings.copy(ICE).nonOpaque().solid().slipperiness(0.98f).solidBlock(Blocks::never))); - public static final Block ICE_STAIRS = registerBlocks("ice_stairs", new IceStairs(Blocks.ICE.getDefaultState(),AbstractBlock.Settings.copy(ICE).nonOpaque().slipperiness(0.98f).solidBlock(Blocks::never))); - public static final Block ICE_SLAB = registerBlocks("ice_slab", new IceSlab(AbstractBlock.Settings.copy(ICE).nonOpaque().slipperiness(0.98f).solidBlock(Blocks::never))); + public static final Block ICE_WALL = registerBlocks("ice_wall", new TranslucentWall(AbstractBlock.Settings.copy(ICE).nonOpaque().solid().slipperiness(0.98f).solidBlock(Blocks::never)).setBlockSeriesAtSetting(Blocks.ICE)); + public static final Block ICE_STAIRS = registerBlocks("ice_stairs", new TranslucentStairs(Blocks.ICE.getDefaultState(),AbstractBlock.Settings.copy(ICE).nonOpaque().slipperiness(0.98f).solidBlock(Blocks::never)).setBlockSeriesAtSetting(Blocks.ICE)); + public static final Block ICE_SLAB = registerBlocks("ice_slab", new TranslucentSlab(AbstractBlock.Settings.copy(ICE).nonOpaque().slipperiness(0.98f).solidBlock(Blocks::never)).setBlockSeriesAtSetting(Blocks.ICE)); public static final Block PACKED_ICE_WALL = registerBlocks("packed_ice_wall", new WallBlock(AbstractBlock.Settings.copy(PACKED_ICE).solid().slipperiness(0.98f))); public static final Block PACKED_ICE_STAIRS = registerBlocks("packed_ice_stairs", new StairsBlock(Blocks.PACKED_ICE.getDefaultState(),AbstractBlock.Settings.copy(PACKED_ICE).slipperiness(0.98f))); diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/BlocksMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/BlocksMixin.java new file mode 100644 index 0000000..dcc1a94 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/mixin/BlocksMixin.java @@ -0,0 +1,9 @@ +package com.yipkei.vanilladdition.mixin; + +import net.minecraft.block.Blocks; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(Blocks.class) +public class BlocksMixin { + +} diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/FlintAndSteelItemMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/FlintAndSteelItemMixin.java deleted file mode 100644 index 36612bf..0000000 --- a/src/main/java/com/yipkei/vanilladdition/mixin/FlintAndSteelItemMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.yipkei.vanilladdition.mixin; - -import net.fabricmc.fabric.api.item.v1.FabricItem; -import net.minecraft.item.FlintAndSteelItem; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(FlintAndSteelItem.class) -public class FlintAndSteelItemMixin implements FabricItem { - @Override - public final ItemStack getRecipeRemainder(ItemStack stack) { - if (stack.getDamage()< stack.getMaxDamage()-1){ - ItemStack processed = stack.copy(); - processed.setDamage(stack.getDamage()+1); - return processed; - } - return ItemStack.EMPTY; - } -} diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/IceBlockMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/IceBlockMixin.java deleted file mode 100644 index ccd06a2..0000000 --- a/src/main/java/com/yipkei/vanilladdition/mixin/IceBlockMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.yipkei.vanilladdition.mixin; - -import com.yipkei.vanilladdition.block.IceSlab; -import com.yipkei.vanilladdition.block.IceStairs; -import com.yipkei.vanilladdition.block.TranslucentIce; -import net.minecraft.block.BlockState; -import net.minecraft.block.IceBlock; -import net.minecraft.block.TranslucentBlock; -import net.minecraft.util.math.Direction; -import org.spongepowered.asm.mixin.Mixin; - -import static com.yipkei.vanilladdition.helper.BlockStateHelper.*; - -@Mixin(IceBlock.class) -public class IceBlockMixin extends TranslucentBlock implements TranslucentIce { - public IceBlockMixin(Settings settings) { - super(settings); - } - - @Override - protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction){ - if (!(stateFrom.getBlock() instanceof TranslucentIce)) { - return super.isSideInvisible(state, stateFrom, direction); - } - - if (stateFrom.getBlock() instanceof IceSlab){ - if (hasCompleteSlabSurface(stateFrom, direction.getOpposite())) return true; - } - - if (stateFrom.getBlock() instanceof IceStairs){ - if (hasCompleteStairSurface(stateFrom, direction.getOpposite())) return true; - } - - return super.isSideInvisible(state, stateFrom, direction); - } -} diff --git a/src/main/java/com/yipkei/vanilladdition/mixin/TranslucentBlockMixin.java b/src/main/java/com/yipkei/vanilladdition/mixin/TranslucentBlockMixin.java new file mode 100644 index 0000000..5cb2527 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/mixin/TranslucentBlockMixin.java @@ -0,0 +1,49 @@ +package com.yipkei.vanilladdition.mixin; + +import com.yipkei.vanilladdition.block.AbstractTranslucentBlock; +import com.yipkei.vanilladdition.block.TranslucentSlab; +import com.yipkei.vanilladdition.block.TranslucentStairs; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.TranslucentBlock; +import net.minecraft.util.math.Direction; +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.CallbackInfoReturnable; + +import static com.yipkei.vanilladdition.helper.BlockStateHelper.hasCompleteSlabSurface; +import static com.yipkei.vanilladdition.helper.BlockStateHelper.hasCompleteStairSurface; + +@Mixin(TranslucentBlock.class) +public class TranslucentBlockMixin extends Block implements AbstractTranslucentBlock { + + public TranslucentBlockMixin(Settings settings) { + super(settings); + } + + @Inject(method = "isSideInvisible", at = @At("HEAD"), cancellable = true) + protected void isSideInvisibleChanged(BlockState state, BlockState stateFrom, Direction direction, CallbackInfoReturnable cir){ + if (!(stateFrom.getBlock() instanceof AbstractTranslucentBlock)) { + cir.setReturnValue(super.isSideInvisible(state, stateFrom, direction)); + } + + if ( (stateFrom.getBlock() instanceof TranslucentBlock)){ + cir.setReturnValue(stateFrom.getBlock() == this || super.isSideInvisible(state, stateFrom, direction)); + } + + if (stateFrom.getBlock() instanceof TranslucentSlab){ + if (((TranslucentSlab)(stateFrom.getBlock())).getBlockSeries() != this) + cir.setReturnValue(super.isSideInvisible(state, stateFrom, direction)); + if (hasCompleteSlabSurface(stateFrom, direction.getOpposite())) + cir.setReturnValue(true); + } + + if (stateFrom.getBlock() instanceof TranslucentStairs){ + if (((TranslucentStairs)(stateFrom.getBlock())).getBlockSeries() != this) + cir.setReturnValue(super.isSideInvisible(state, stateFrom, direction)); + if (hasCompleteStairSurface(stateFrom, direction.getOpposite())) cir.setReturnValue(true); + } + } + +} diff --git a/src/main/java/com/yipkei/vanilladdition/settings/Rule.java b/src/main/java/com/yipkei/vanilladdition/settings/Rule.java new file mode 100644 index 0000000..5ce8083 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/settings/Rule.java @@ -0,0 +1,21 @@ +package com.yipkei.vanilladdition.settings; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Rule { + String[] categories(); + String[] options() default {}; + boolean strict() default true; + String appSource() default ""; + + Class[] conditions() default {}; + + interface Condition{ + boolean shouldRegister(); + } +} diff --git a/src/main/java/com/yipkei/vanilladdition/settings/SettingManager.java b/src/main/java/com/yipkei/vanilladdition/settings/SettingManager.java new file mode 100644 index 0000000..42bdb74 --- /dev/null +++ b/src/main/java/com/yipkei/vanilladdition/settings/SettingManager.java @@ -0,0 +1,25 @@ +package com.yipkei.vanilladdition.settings; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +public class SettingManager { + public void parseSettingClass(Class settingClass){ + nextRule : for (Field field : settingClass.getFields()){ + Class[] conditions; + Rule annotation = field.getAnnotation(Rule.class); + conditions = annotation.conditions(); + for (Class condition: conditions){ + try{ + Constructor constructor = condition.getDeclaredConstructor(); + constructor.setAccessible(true); + if (!constructor.newInstance().shouldRegister()) + continue nextRule; + } + catch (ReflectiveOperationException e){ + throw new IllegalArgumentException(e); + } + } + } + } +} diff --git a/src/main/java/com/yipkei/vanilladdition/util/VanillaTradeModifiers.java b/src/main/java/com/yipkei/vanilladdition/util/VanillaTradeModifiers.java index 371404e..fbe1a70 100644 --- a/src/main/java/com/yipkei/vanilladdition/util/VanillaTradeModifiers.java +++ b/src/main/java/com/yipkei/vanilladdition/util/VanillaTradeModifiers.java @@ -103,6 +103,7 @@ public static void registerVanillaVillageTrades(){ TradeOfferHelper.registerVillagerOffers(VillagerProfession.LEATHERWORKER, 3, factories -> factories .add(new TradeOffers.BuyItemFactory(Items.ARMADILLO_SCUTE, 4, 16, 10))); + TradeOfferHelper.registerVillagerOffers(VillagerProfession.LEATHERWORKER, 5, factories -> { factories.add(new TradeOffers.SellItemFactory(ModItems.IRON_HORSE_ARMOR_BLUEPRINT, 28, 1, 1,30,0.2f)); factories.add(new TradeOffers.SellItemFactory(ModItems.GOLDEN_HORSE_ARMOR_BLUEPRINT, 42, 1, 1, 30, 0.2f)); diff --git a/src/main/resources/vanilla-addition.mixins.json b/src/main/resources/vanilla-addition.mixins.json index 0d67024..38395c3 100644 --- a/src/main/resources/vanilla-addition.mixins.json +++ b/src/main/resources/vanilla-addition.mixins.json @@ -7,8 +7,7 @@ "BoneMealItemMixin", "EnchantmentScreenHandlerMixin", "EnderDragonFightMixin", - "FlintAndSteelItemMixin", - "IceBlockMixin", + "TranslucentBlockMixin", "MooshroomEntityMixin", "PumpkinBlockMixin", "ShearsItemMixin",