diff --git a/build.gradle b/build.gradle index fbed7c74..b1895389 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.6-SNAPSHOT' + id 'fabric-loom' version '0.7-SNAPSHOT' id 'maven-publish' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 99c200fc..a760d0e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/ru/betterend/BetterEnd.java b/src/main/java/ru/betterend/BetterEnd.java index 154a40a3..5ee920a1 100644 --- a/src/main/java/ru/betterend/BetterEnd.java +++ b/src/main/java/ru/betterend/BetterEnd.java @@ -39,7 +39,6 @@ import ru.betterend.world.surface.SurfaceBuilders; public class BetterEnd implements ModInitializer { public static final String MOD_ID = "betterend"; public static final Logger LOGGER = Logger.get(); - @Override public void onInitialize() { EndPortals.loadPortals(); @@ -67,41 +66,40 @@ public class BetterEnd implements ModInitializer { GeneratorOptions.init(); DataFixerUtil.init(); LootTableUtil.init(); - + if (hasGuideBook()) { GuideBookItem.register(); } - - FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class) - .forEach(BetterEndPlugin::register); + + FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class).forEach(BetterEndPlugin::register); Configs.saveConfigs(); - + if (hasGuideBook()) { - PlayerAdvancementsEvents.PLAYER_ADVANCEMENT_COMPLETE.register((player, advancement, criterionName) -> { + PlayerAdvancementsEvents.PLAYER_ADVENCEMENT_COMPLETE.register((player, advancement, criterionName) -> { ResourceLocation advId = new ResourceLocation("minecraft:end/enter_end_gateway"); if (advId.equals(advancement.getId())) { - player.giveItemStack(new ItemStack(GuideBookItem.GUIDE_BOOK)); + player.addItem(new ItemStack(GuideBookItem.GUIDE_BOOK)); } }); } } - + public static boolean hasGuideBook() { return FabricLoader.getInstance().isModLoaded("patchouli"); } - + public static ResourceLocation makeID(String path) { return new ResourceLocation(MOD_ID, path); } - + public static String getStringId(String id) { return String.format("%s:%s", MOD_ID, id); } - + public static boolean isDevEnvironment() { return FabricLoader.getInstance().isDevelopmentEnvironment(); } - + public static boolean isClient() { return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; } diff --git a/src/main/java/ru/betterend/blocks/AeterniumAnvil.java b/src/main/java/ru/betterend/blocks/AeterniumAnvil.java index fcebb3eb..5ce6eb48 100644 --- a/src/main/java/ru/betterend/blocks/AeterniumAnvil.java +++ b/src/main/java/ru/betterend/blocks/AeterniumAnvil.java @@ -1,10 +1,10 @@ package ru.betterend.blocks; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.resources.ResourceLocation; import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.item.material.EndToolMaterial; import ru.betterend.patterns.Patterns; @@ -12,11 +12,11 @@ import ru.betterend.registry.EndBlocks; public class AeterniumAnvil extends EndAnvilBlock { private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION_LONG; - + public AeterniumAnvil() { super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(DESTRUCTION); @@ -24,7 +24,7 @@ public class AeterniumAnvil extends EndAnvilBlock { } @Override - public IntegerProperty getDESTRUCTION() { + public IntegerProperty getDestructionProperty() { return DESTRUCTION; } diff --git a/src/main/java/ru/betterend/blocks/AeterniumBlock.java b/src/main/java/ru/betterend/blocks/AeterniumBlock.java index 32a52412..a8d98b32 100644 --- a/src/main/java/ru/betterend/blocks/AeterniumBlock.java +++ b/src/main/java/ru/betterend/blocks/AeterniumBlock.java @@ -5,17 +5,20 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SoundType; import ru.betterend.blocks.basis.BlockBase; public class AeterniumBlock extends BlockBase { public AeterniumBlock() { - super(FabricBlockSettings.of(Material.METAL, MaterialColor.COLOR_GRAY).hardness(65F).resistance(1200F) - .requiresTool().sounds(SoundType.NETHERITE_BLOCK)); + super(FabricBlockSettings.of(Material.METAL, MaterialColor.COLOR_GRAY) + .hardness(65F) + .resistance(1200F) + .requiresCorrectToolForDrops() + .sound(SoundType.NETHERITE_BLOCK)); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/ru/betterend/blocks/AmaranitaCapBlock.java b/src/main/java/ru/betterend/blocks/AmaranitaCapBlock.java index 717228df..173134db 100644 --- a/src/main/java/ru/betterend/blocks/AmaranitaCapBlock.java +++ b/src/main/java/ru/betterend/blocks/AmaranitaCapBlock.java @@ -2,12 +2,12 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; public class AmaranitaCapBlock extends BlockBase { public AmaranitaCapBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WOOD)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sound(SoundType.WOOD)); } } diff --git a/src/main/java/ru/betterend/blocks/AmaranitaHymenophoreBlock.java b/src/main/java/ru/betterend/blocks/AmaranitaHymenophoreBlock.java index 100c4d24..9aa743c7 100644 --- a/src/main/java/ru/betterend/blocks/AmaranitaHymenophoreBlock.java +++ b/src/main/java/ru/betterend/blocks/AmaranitaHymenophoreBlock.java @@ -2,15 +2,15 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; public class AmaranitaHymenophoreBlock extends BlockBase implements IRenderTypeable { public AmaranitaHymenophoreBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WOOD)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sound(SoundType.WOOD)); } @Override diff --git a/src/main/java/ru/betterend/blocks/AncientEmeraldIceBlock.java b/src/main/java/ru/betterend/blocks/AncientEmeraldIceBlock.java index 616279c7..61516a0a 100644 --- a/src/main/java/ru/betterend/blocks/AncientEmeraldIceBlock.java +++ b/src/main/java/ru/betterend/blocks/AncientEmeraldIceBlock.java @@ -3,11 +3,11 @@ package ru.betterend.blocks; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndParticles; @@ -16,13 +16,13 @@ import ru.betterend.util.MHelper; public class AncientEmeraldIceBlock extends BlockBase { public AncientEmeraldIceBlock() { - super(FabricBlockSettings.copyOf(Blocks.BLUE_ICE).ticksRandomly()); + super(FabricBlockSettings.copyOf(Blocks.BLUE_ICE).randomTicks()); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { Direction dir = BlocksHelper.randomDirection(random); - + if (random.nextBoolean()) { int x = MHelper.randRange(-2, 2, random); int y = MHelper.randRange(-2, 2, random); @@ -33,20 +33,20 @@ public class AncientEmeraldIceBlock extends BlockBase { makeParticles(world, p, random); } } - + pos = pos.relative(dir); state = world.getBlockState(pos); if (state.is(Blocks.WATER)) { world.setBlockAndUpdate(pos, EndBlocks.EMERALD_ICE.defaultBlockState()); makeParticles(world, pos, random); - } else if (state.is(EndBlocks.EMERALD_ICE)) { + } + else if (state.is(EndBlocks.EMERALD_ICE)) { world.setBlockAndUpdate(pos, EndBlocks.DENSE_EMERALD_ICE.defaultBlockState()); makeParticles(world, pos, random); } } - + private void makeParticles(ServerLevel world, BlockPos pos, Random random) { - world.sendParticles(EndParticles.SNOWFLAKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 20, 0.5, 0.5, - 0.5, 0); + world.sendParticles(EndParticles.SNOWFLAKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 20, 0.5, 0.5, 0.5, 0); } } diff --git a/src/main/java/ru/betterend/blocks/AuroraCrystalBlock.java b/src/main/java/ru/betterend/blocks/AuroraCrystalBlock.java index 73b3580a..9533b296 100644 --- a/src/main/java/ru/betterend/blocks/AuroraCrystalBlock.java +++ b/src/main/java/ru/betterend/blocks/AuroraCrystalBlock.java @@ -5,39 +5,47 @@ import java.util.List; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.Vec3i; import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.block.AbstractGlassBlock; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.SoundType; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.registry.EndItems; +import ru.betterend.registry.EndTags; import ru.betterend.util.MHelper; public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTypeable, IColorProvider { public static final Vec3i[] COLORS; private static final int MIN_DROP = 1; private static final int MAX_DROP = 4; - + public AuroraCrystalBlock() { - super(FabricBlockSettings.of(Material.GLASS).breakByTool(FabricToolTags.PICKAXES) - .suffocates((state, world, pos) -> false).hardness(1F).resistance(1F).sounds(SoundType.GLASS) - .luminance(15).nonOpaque()); + super(FabricBlockSettings.of(Material.GLASS) + .breakByTool(FabricToolTags.PICKAXES) + .breakByTool(EndTags.HAMMERS) + .hardness(1F) + .resistance(1F) + .luminance(15) + .noOcclusion() + .isSuffocating((state, world, pos) -> false) + .sound(SoundType.GLASS)); } @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ(); double delta = i * 0.1; @@ -45,28 +53,30 @@ public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTyp int index2 = (index + 1) & 3; delta -= index; index &= 3; - + Vec3i color1 = COLORS[index]; Vec3i color2 = COLORS[index2]; - + int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); - + return MHelper.color(r, g, b); }; } @Override public ItemColor getItemProvider() { - return (stack, tintIndex) -> MHelper.color(COLORS[3].getX(), COLORS[3].getY(), COLORS[3].getZ()); + return (stack, tintIndex) -> { + return MHelper.color(COLORS[3].getX(), COLORS[3].getY(), COLORS[3].getZ()); + }; } @Override public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -91,9 +101,13 @@ public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTyp } return Lists.newArrayList(); } - + static { - COLORS = new Vec3i[] { new Vec3i(247, 77, 161), new Vec3i(120, 184, 255), new Vec3i(120, 255, 168), - new Vec3i(243, 58, 255) }; + COLORS = new Vec3i[] { + new Vec3i(247, 77, 161), + new Vec3i(120, 184, 255), + new Vec3i(120, 255, 168), + new Vec3i(243, 58, 255) + }; } } diff --git a/src/main/java/ru/betterend/blocks/BlockProperties.java b/src/main/java/ru/betterend/blocks/BlockProperties.java index 5d153ab1..5a7df101 100644 --- a/src/main/java/ru/betterend/blocks/BlockProperties.java +++ b/src/main/java/ru/betterend/blocks/BlockProperties.java @@ -1,146 +1,163 @@ package ru.betterend.blocks; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.EnumProperty; +import net.minecraft.util.StringRepresentable; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.util.StringIdentifiable; import ru.betterend.registry.EndPortals; public class BlockProperties { - public static final EnumProperty HYDRALUX_SHAPE = EnumProperty.of("shape", HydraluxShape.class); - public final static EnumProperty PEDESTAL_STATE = EnumProperty.of("state", PedestalState.class); - public static final EnumProperty TRIPLE_SHAPE = EnumProperty.of("shape", TripleShape.class); - public static final EnumProperty PENTA_SHAPE = EnumProperty.of("shape", PentaShape.class); - - public static final BooleanProperty TRANSITION = BooleanProperty.of("transition"); - public static final BooleanProperty HAS_LIGHT = BooleanProperty.of("has_light"); - public static final BooleanProperty HAS_ITEM = BooleanProperty.of("has_item"); - public static final BooleanProperty IS_FLOOR = BooleanProperty.of("is_floor"); - public static final BooleanProperty NATURAL = BooleanProperty.of("natural"); - public static final BooleanProperty ACTIVE = BooleanProperty.of("active"); - public static final BooleanProperty SMALL = BooleanProperty.of("small"); - - public static final IntegerProperty DESTRUCTION_LONG = IntegerProperty.of("destruction", 0, 8); - public static final IntegerProperty DESTRUCTION = IntegerProperty.of("destruction", 0, 2); - public static final IntegerProperty ROTATION = IntegerProperty.of("rotation", 0, 3); - public static final IntegerProperty FULLNESS = IntegerProperty.of("fullness", 0, 3); - public static final IntegerProperty COLOR = IntegerProperty.of("color", 0, 7); - public static final IntegerProperty PORTAL = IntegerProperty.of("portal", 0, EndPortals.getCount()); - public static final IntegerProperty SIZE = IntegerProperty.of("size", 0, 7); - public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 3); - - public static enum TripleShape implements StringIdentifiable { - TOP("top"), MIDDLE("middle"), BOTTOM("bottom"); - + public static final EnumProperty HYDRALUX_SHAPE = EnumProperty.create("shape", HydraluxShape.class); + public final static EnumProperty PEDESTAL_STATE = EnumProperty.create("state", PedestalState.class); + public static final EnumProperty TRIPLE_SHAPE = EnumProperty.create("shape", TripleShape.class); + public static final EnumProperty PENTA_SHAPE = EnumProperty.create("shape", PentaShape.class); + + public static final BooleanProperty TRANSITION = BooleanProperty.create("transition"); + public static final BooleanProperty HAS_LIGHT = BooleanProperty.create("has_light"); + public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item"); + public static final BooleanProperty IS_FLOOR = BooleanProperty.create("is_floor"); + public static final BooleanProperty NATURAL = BooleanProperty.create("natural"); + public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); + public static final BooleanProperty SMALL = BooleanProperty.create("small"); + + public static final IntegerProperty DESTRUCTION_LONG = IntegerProperty.create("destruction", 0, 8); + public static final IntegerProperty DESTRUCTION = IntegerProperty.create("destruction", 0, 2); + public static final IntegerProperty ROTATION = IntegerProperty.create("rotation", 0, 3); + public static final IntegerProperty FULLNESS = IntegerProperty.create("fullness", 0, 3); + public static final IntegerProperty COLOR = IntegerProperty.create("color", 0, 7); + public static final IntegerProperty PORTAL = IntegerProperty.create("portal", 0, EndPortals.getCount()); + public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7); + public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); + + public static enum TripleShape implements StringRepresentable { + TOP("top"), + MIDDLE("middle"), + BOTTOM("bottom"); + private final String name; - + TripleShape(String name) { this.name = name; } @Override - public String asString() { + public String getSerializedName() { return name; } - + @Override public String toString() { return name; } } - public static enum PedestalState implements StringIdentifiable { - PEDESTAL_TOP("pedestal_top"), COLUMN_TOP("column_top"), BOTTOM("bottom"), PILLAR("pillar"), COLUMN("column"), + public static enum PedestalState implements StringRepresentable { + PEDESTAL_TOP("pedestal_top"), + COLUMN_TOP("column_top"), + BOTTOM("bottom"), + PILLAR("pillar"), + COLUMN("column"), DEFAULT("default"); - + private final String name; - + PedestalState(String name) { this.name = name; } - + @Override - public String asString() { + public String getSerializedName() { return this.name; } - + @Override public String toString() { return this.name; } } - - public static enum HydraluxShape implements StringIdentifiable { - FLOWER_BIG_BOTTOM("flower_big_bottom", true), FLOWER_BIG_TOP("flower_big_top", true), - FLOWER_SMALL_BOTTOM("flower_small_bottom", true), FLOWER_SMALL_TOP("flower_small_top", true), - VINE("vine", false), ROOTS("roots", false); - + + public static enum HydraluxShape implements StringRepresentable { + FLOWER_BIG_BOTTOM("flower_big_bottom", true), + FLOWER_BIG_TOP("flower_big_top", true), + FLOWER_SMALL_BOTTOM("flower_small_bottom", true), + FLOWER_SMALL_TOP("flower_small_top", true), + VINE("vine", false), + ROOTS("roots", false); + private final String name; private final boolean glow; - + HydraluxShape(String name, boolean glow) { this.name = name; this.glow = glow; } @Override - public String asString() { + public String getSerializedName() { return name; } - + @Override public String toString() { return name; } - + public boolean hasGlow() { return glow; } } - - public static enum PentaShape implements StringIdentifiable { - BOTTOM("bottom"), PRE_BOTTOM("pre_bottom"), MIDDLE("middle"), PRE_TOP("pre_top"), TOP("top"); - + + public static enum PentaShape implements StringRepresentable { + BOTTOM("bottom"), + PRE_BOTTOM("pre_bottom"), + MIDDLE("middle"), + PRE_TOP("pre_top"), + TOP("top"); + private final String name; - + PentaShape(String name) { this.name = name; } @Override - public String asString() { + public String getSerializedName() { return name; } - + @Override public String toString() { return name; } } - - public static enum LumecornShape implements StringIdentifiable { - LIGHT_TOP("light_top", 15), LIGHT_TOP_MIDDLE("light_top_middle", 15), LIGHT_MIDDLE("light_middle", 15), - LIGHT_BOTTOM("light_bottom", 15), MIDDLE("middle", 0), BOTTOM_BIG("bottom_big", 0), + + public static enum LumecornShape implements StringRepresentable { + LIGHT_TOP("light_top", 15), + LIGHT_TOP_MIDDLE("light_top_middle", 15), + LIGHT_MIDDLE("light_middle", 15), + LIGHT_BOTTOM("light_bottom", 15), + MIDDLE("middle", 0), + BOTTOM_BIG("bottom_big", 0), BOTTOM_SMALL("bottom_small", 0); - + private final String name; private final int light; - + LumecornShape(String name, int light) { this.name = name; this.light = light; } @Override - public String asString() { + public String getSerializedName() { return name; } - + @Override public String toString() { return name; } - + public int getLight() { return light; } diff --git a/src/main/java/ru/betterend/blocks/BlockSounds.java b/src/main/java/ru/betterend/blocks/BlockSounds.java index 75c2ac41..21f89213 100644 --- a/src/main/java/ru/betterend/blocks/BlockSounds.java +++ b/src/main/java/ru/betterend/blocks/BlockSounds.java @@ -1,10 +1,13 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.SoundType; import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.level.block.SoundType; public class BlockSounds { - public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, SoundEvents.BLOCK_STONE_BREAK, - SoundEvents.BLOCK_WART_BLOCK_STEP, SoundEvents.BLOCK_STONE_PLACE, SoundEvents.BLOCK_STONE_HIT, - SoundEvents.BLOCK_STONE_FALL); + public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, + SoundEvents.STONE_BREAK, + SoundEvents.WART_BLOCK_STEP, + SoundEvents.STONE_PLACE, + SoundEvents.STONE_HIT, + SoundEvents.STONE_FALL); } diff --git a/src/main/java/ru/betterend/blocks/BlueVineBlock.java b/src/main/java/ru/betterend/blocks/BlueVineBlock.java index 0d1b0643..9187d92b 100644 --- a/src/main/java/ru/betterend/blocks/BlueVineBlock.java +++ b/src/main/java/ru/betterend/blocks/BlueVineBlock.java @@ -3,19 +3,19 @@ package ru.betterend.blocks; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.UpDownPlantBlock; import ru.betterend.registry.EndBlocks; public class BlueVineBlock extends UpDownPlantBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override protected boolean isTerrain(BlockState state) { return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM; diff --git a/src/main/java/ru/betterend/blocks/BlueVineLanternBlock.java b/src/main/java/ru/betterend/blocks/BlueVineLanternBlock.java index 44de7d10..ac6671dd 100644 --- a/src/main/java/ru/betterend/blocks/BlueVineLanternBlock.java +++ b/src/main/java/ru/betterend/blocks/BlueVineLanternBlock.java @@ -2,44 +2,43 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; public class BlueVineLanternBlock extends BlockBase { public static final BooleanProperty NATURAL = BlockProperties.NATURAL; - + public BlueVineLanternBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WART_BLOCK) - .luminance(15)); - this.setDefaultState(this.stateManager.defaultBlockState().with(NATURAL, false)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WART_BLOCK)); + this.registerDefaultState(this.stateDefinition.any().setValue(NATURAL, false)); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return state.getValue(NATURAL) ? world.getBlockState(pos.below()).getBlock() == EndBlocks.BLUE_VINE : true; + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return !state.getValue(NATURAL) || world.getBlockState(pos.below()).getBlock() == EndBlocks.BLUE_VINE; } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(NATURAL); diff --git a/src/main/java/ru/betterend/blocks/BlueVineSeedBlock.java b/src/main/java/ru/betterend/blocks/BlueVineSeedBlock.java index 5c8e3b99..0d5d63a4 100644 --- a/src/main/java/ru/betterend/blocks/BlueVineSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/BlueVineSeedBlock.java @@ -1,12 +1,11 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.blocks.basis.FurBlock; @@ -22,40 +21,34 @@ public class BlueVineSeedBlock extends EndPlantWithAgeBlock { if (h < height + 1) { return; } - BlocksHelper.setWithoutUpdate(world, pos, - EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); + BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); for (int i = 1; i < height; i++) { - BlocksHelper.setWithoutUpdate(world, pos.up(i), - EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); + BlocksHelper.setWithoutUpdate(world, pos.above(i), EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); } - BlocksHelper.setWithoutUpdate(world, pos.up(height), - EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); - placeLantern(world, pos.up(height + 1)); + BlocksHelper.setWithoutUpdate(world, pos.above(height), EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); + placeLantern(world, pos.above(height + 1)); } - + private void placeLantern(WorldGenLevel world, BlockPos pos) { - BlocksHelper.setWithoutUpdate(world, pos, - EndBlocks.BLUE_VINE_LANTERN.defaultBlockState().with(BlueVineLanternBlock.NATURAL, true)); - for (Direction dir : BlocksHelper.HORIZONTAL) { + BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BLUE_VINE_LANTERN.defaultBlockState().setValue(BlueVineLanternBlock.NATURAL, true)); + for (Direction dir: BlocksHelper.HORIZONTAL) { BlockPos p = pos.relative(dir); - if (world.isAir(p)) { - BlocksHelper.setWithoutUpdate(world, p, - EndBlocks.BLUE_VINE_FUR.defaultBlockState().with(FurBlock.FACING, dir)); + if (world.isEmptyBlock(p)) { + BlocksHelper.setWithoutUpdate(world, p, EndBlocks.BLUE_VINE_FUR.defaultBlockState().setValue(FurBlock.FACING, dir)); } } - if (world.isAir(pos.up())) { - BlocksHelper.setWithoutUpdate(world, pos.up(), - EndBlocks.BLUE_VINE_FUR.defaultBlockState().with(FurBlock.FACING, Direction.UP)); + if (world.isEmptyBlock(pos.above())) { + BlocksHelper.setWithoutUpdate(world, pos.above(), EndBlocks.BLUE_VINE_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.UP)); } } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/blocks/BoluxMushroomBlock.java b/src/main/java/ru/betterend/blocks/BoluxMushroomBlock.java index 338016be..fb512f7d 100644 --- a/src/main/java/ru/betterend/blocks/BoluxMushroomBlock.java +++ b/src/main/java/ru/betterend/blocks/BoluxMushroomBlock.java @@ -2,54 +2,52 @@ package ru.betterend.blocks; import java.util.List; import java.util.Random; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import com.google.common.collect.Lists; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; public class BoluxMushroomBlock extends EndPlantBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(1, 0, 1, 15, 9, 15); - + private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 9, 15); + public BoluxMushroomBlock() { super(10); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.RUTISCUS); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Lists.newArrayList(new ItemStack(this)); diff --git a/src/main/java/ru/betterend/blocks/BrimstoneBlock.java b/src/main/java/ru/betterend/blocks/BrimstoneBlock.java index 50f5439a..92e34923 100644 --- a/src/main/java/ru/betterend/blocks/BrimstoneBlock.java +++ b/src/main/java/ru/betterend/blocks/BrimstoneBlock.java @@ -5,52 +5,51 @@ import java.util.Random; import org.jetbrains.annotations.Nullable; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemStack; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; public class BrimstoneBlock extends BlockBase { public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; - + public BrimstoneBlock() { - super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(MaterialColor.COLOR_BROWN).ticksRandomly()); - setDefaultState(stateManager.defaultBlockState().with(ACTIVATED, false)); + super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(MaterialColor.COLOR_BROWN).randomTicks()); + registerDefaultState(stateDefinition.any().setValue(ACTIVATED, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(ACTIVATED); } @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, - ItemStack itemStack) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { if (world.isClientSide()) { updateChunks((ClientLevel) world, pos); } } - - public void onBroken(LevelAccessor world, BlockPos pos, BlockState state) { + + public void destroy(LevelAccessor world, BlockPos pos, BlockState state) { if (world.isClientSide()) { updateChunks((ClientLevel) world, pos); } } - + private void updateChunks(ClientLevel world, BlockPos pos) { int y = pos.getY() >> 4; int x1 = (pos.getX() - 2) >> 4; @@ -59,41 +58,45 @@ public class BrimstoneBlock extends BlockBase { int z2 = (pos.getZ() + 2) >> 4; for (int x = x1; x <= x2; x++) { for (int z = z1; z <= z2; z++) { - world.scheduleBlockRenders(x, y, z); + world.setSectionDirtyWithNeighbors(x, y, z); } } } - + @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { boolean deactivate = true; - for (Direction dir : BlocksHelper.DIRECTIONS) { - if (world.getFluidState(pos.relative(dir)).getFluid().equals(Fluids.WATER)) { + for (Direction dir: BlocksHelper.DIRECTIONS) { + if (world.getFluidState(pos.relative(dir)).getType().equals(Fluids.WATER)) { deactivate = false; break; } } if (state.getValue(ACTIVATED)) { if (deactivate) { - world.setBlockAndUpdate(pos, getDefaultState().with(ACTIVATED, false)); - } else if (state.getValue(ACTIVATED) && random.nextInt(16) == 0) { + world.setBlockAndUpdate(pos, defaultBlockState().setValue(ACTIVATED, false)); + } + else if (state.getValue(ACTIVATED) && random.nextInt(16) == 0) { Direction dir = BlocksHelper.randomDirection(random); BlockPos side = pos.relative(dir); BlockState sideState = world.getBlockState(side); if (sideState.getBlock() instanceof SulphurCrystalBlock) { - if (sideState.get(SulphurCrystalBlock.AGE) < 2 && sideState.get(SulphurCrystalBlock.WATERLOGGED)) { - int age = sideState.get(SulphurCrystalBlock.AGE) + 1; - world.setBlockAndUpdate(side, sideState.with(SulphurCrystalBlock.AGE, age)); + if (sideState.getValue(SulphurCrystalBlock.AGE) < 2 && sideState.getValue(SulphurCrystalBlock.WATERLOGGED)) { + int age = sideState.getValue(SulphurCrystalBlock.AGE) + 1; + world.setBlockAndUpdate(side, sideState.setValue(SulphurCrystalBlock.AGE, age)); } - } else if (sideState.getFluidState().getFluid() == Fluids.WATER) { + } + else if (sideState.getFluidState().getType() == Fluids.WATER) { BlockState crystal = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState() - .with(SulphurCrystalBlock.FACING, dir).with(SulphurCrystalBlock.WATERLOGGED, true) - .with(SulphurCrystalBlock.AGE, 0); + .setValue(SulphurCrystalBlock.FACING, dir) + .setValue(SulphurCrystalBlock.WATERLOGGED, true) + .setValue(SulphurCrystalBlock.AGE, 0); world.setBlockAndUpdate(side, crystal); } } - } else if (!deactivate && !state.getValue(ACTIVATED)) { - world.setBlockAndUpdate(pos, getDefaultState().with(ACTIVATED, true)); + } + else if (!deactivate && !state.getValue(ACTIVATED)) { + world.setBlockAndUpdate(pos, defaultBlockState().setValue(ACTIVATED, true)); } } } diff --git a/src/main/java/ru/betterend/blocks/BubbleCoralBlock.java b/src/main/java/ru/betterend/blocks/BubbleCoralBlock.java index 4eed7a40..6ffc1849 100644 --- a/src/main/java/ru/betterend/blocks/BubbleCoralBlock.java +++ b/src/main/java/ru/betterend/blocks/BubbleCoralBlock.java @@ -6,30 +6,33 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.UnderwaterPlantBlock; public class BubbleCoralBlock extends UnderwaterPlantBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 14, 16); - + private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 14, 16); + public BubbleCoralBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.CORAL).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.CORAL_BLOCK) + .noCollission()); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } @Environment(EnvType.CLIENT) @@ -39,19 +42,19 @@ public class BubbleCoralBlock extends UnderwaterPlantBlock { double z = pos.getZ() + random.nextDouble(); world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/BulbVineBlock.java b/src/main/java/ru/betterend/blocks/BulbVineBlock.java index 53e2b1cf..50846ebc 100644 --- a/src/main/java/ru/betterend/blocks/BulbVineBlock.java +++ b/src/main/java/ru/betterend/blocks/BulbVineBlock.java @@ -1,15 +1,13 @@ package ru.betterend.blocks; import java.util.List; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import com.google.common.collect.Lists; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.VineBlock; import ru.betterend.registry.EndBlocks; @@ -20,27 +18,28 @@ public class BulbVineBlock extends VineBlock { public BulbVineBlock() { super(15, true); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(SHAPE) == TripleShape.BOTTOM) { return Lists.newArrayList(new ItemStack(EndItems.GLOWING_BULB)); - } else if (MHelper.RANDOM.nextInt(8) == 0) { + } + else if (MHelper.RANDOM.nextInt(8) == 0) { return Lists.newArrayList(new ItemStack(EndBlocks.BULB_VINE_SEED)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - boolean canPlace = super.canPlaceAt(state, world, pos); - return (state.is(this) && state.getValue(SHAPE) == TripleShape.BOTTOM) ? canPlace - : canPlace && world.getBlockState(pos.below()).is(this); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + boolean canPlace = super.canSurvive(state, world, pos); + return (state.is(this) && state.getValue(SHAPE) == TripleShape.BOTTOM) ? canPlace : canPlace && world.getBlockState(pos.below()).is(this); } } diff --git a/src/main/java/ru/betterend/blocks/BulbVineLanternBlock.java b/src/main/java/ru/betterend/blocks/BulbVineLanternBlock.java index 714bb717..d9d19915 100644 --- a/src/main/java/ru/betterend/blocks/BulbVineLanternBlock.java +++ b/src/main/java/ru/betterend/blocks/BulbVineLanternBlock.java @@ -7,17 +7,17 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndLanternBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -25,21 +25,26 @@ import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class BulbVineLanternBlock extends EndLanternBlock implements IRenderTypeable, BlockPatterned { - private static final VoxelShape SHAPE_CEIL = Block.createCuboidShape(4, 4, 4, 12, 16, 12); - private static final VoxelShape SHAPE_FLOOR = Block.createCuboidShape(4, 0, 4, 12, 12, 12); - + private static final VoxelShape SHAPE_CEIL = Block.box(4, 4, 4, 12, 16, 12); + private static final VoxelShape SHAPE_FLOOR = Block.box(4, 0, 4, 12, 12, 12); + public BulbVineLanternBlock() { - this(FabricBlockSettings.of(Material.METAL).sounds(SoundType.LANTERN).hardness(1).resistance(1) - .breakByTool(FabricToolTags.PICKAXES).materialColor(MaterialColor.LIGHT_GRAY).requiresTool() - .luminance(15)); + this(FabricBlockSettings.of(Material.METAL) + .hardness(1) + .resistance(1) + .breakByTool(FabricToolTags.PICKAXES) + .materialColor(MaterialColor.COLOR_LIGHT_GRAY) + .luminance(15) + .requiresCorrectToolForDrops() + .sound(SoundType.LANTERN)); } - - public BulbVineLanternBlock(FabricBlockSettings settings) { + + public BulbVineLanternBlock(Properties settings) { super(settings); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL; } @@ -47,13 +52,13 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -62,21 +67,22 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType map.put("%metal%", getMetalTexture(blockId)); if (block.contains("item") || block.contains("ceil")) { return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, map); - } else { + } + else { return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, map); } } - + protected String getMetalTexture(ResourceLocation blockId) { String name = blockId.getPath(); name = name.substring(0, name.indexOf('_')); return name + "_bulb_vine_lantern_metal"; } - + protected String getGlowTexture() { return "bulb_vine_lantern_bulb"; } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_BULB_LANTERN; diff --git a/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java b/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java index 80031b50..90d414b8 100644 --- a/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java +++ b/src/main/java/ru/betterend/blocks/BulbVineLanternColoredBlock.java @@ -13,7 +13,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements } @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { return getColor(); }; @@ -25,7 +25,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements return getColor(); }; } - + private int getColor() { int color = BlocksHelper.getBlockColor(this); int b = (color & 255); @@ -34,7 +34,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements float[] hsv = MHelper.fromRGBtoHSB(r, g, b); return MHelper.fromHSBtoRGB(hsv[0], hsv[1], hsv[1] > 0.2 ? 1 : hsv[2]); } - + @Override protected String getGlowTexture() { return "bulb_vine_lantern_overlay"; diff --git a/src/main/java/ru/betterend/blocks/BulbVineSeedBlock.java b/src/main/java/ru/betterend/blocks/BulbVineSeedBlock.java index bbcb470e..9ce91135 100644 --- a/src/main/java/ru/betterend/blocks/BulbVineSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/BulbVineSeedBlock.java @@ -1,12 +1,11 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.tags.BlockTags; import net.minecraft.core.BlockPos; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -15,23 +14,20 @@ import ru.betterend.util.BlocksHelper; public class BulbVineSeedBlock extends EndPlantWithAgeBlock { @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - BlockState up = world.getBlockState(pos.up()); - return up.isIn(EndTags.GEN_TERRAIN) || up.isIn(BlockTags.LOGS) || up.isIn(BlockTags.LEAVES); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + BlockState up = world.getBlockState(pos.above()); + return up.is(EndTags.GEN_TERRAIN) || up.is(BlockTags.LOGS) || up.is(BlockTags.LEAVES); } @Override public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { int h = BlocksHelper.downRay(world, pos, random.nextInt(24)) - 1; if (h > 2) { - BlocksHelper.setWithoutUpdate(world, pos, - EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); + BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); for (int i = 1; i < h; i++) { - BlocksHelper.setWithoutUpdate(world, pos.down(i), - EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); + BlocksHelper.setWithoutUpdate(world, pos.below(i), EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); } - BlocksHelper.setWithoutUpdate(world, pos.down(h), - EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); + BlocksHelper.setWithoutUpdate(world, pos.below(h), EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); } } } diff --git a/src/main/java/ru/betterend/blocks/CavePumpkinBlock.java b/src/main/java/ru/betterend/blocks/CavePumpkinBlock.java index ce6fe814..5121e6c4 100644 --- a/src/main/java/ru/betterend/blocks/CavePumpkinBlock.java +++ b/src/main/java/ru/betterend/blocks/CavePumpkinBlock.java @@ -4,18 +4,18 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -25,42 +25,41 @@ public class CavePumpkinBlock extends BlockBaseNotFull implements IRenderTypeabl public static final BooleanProperty SMALL = BlockProperties.SMALL; private static final VoxelShape SHAPE_SMALL; private static final VoxelShape SHAPE_BIG; - + public CavePumpkinBlock() { - super(FabricBlockSettings.copyOf(Blocks.PUMPKIN).luminance((state) -> state.getValue(SMALL) ? 10 : 15)); - setDefaultState(getDefaultState().with(SMALL, false)); + super(FabricBlockSettings.copyOf(Blocks.PUMPKIN).lightLevel((state) -> state.getValue(SMALL) ? 10 : 15)); + registerDefaultState(defaultBlockState().setValue(SMALL, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SMALL); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return state.getValue(SMALL) ? SHAPE_SMALL : SHAPE_BIG; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { - return state.getValue(SMALL) ? Collections.singletonList(new ItemStack(EndBlocks.CAVE_PUMPKIN_SEED)) - : Collections.singletonList(new ItemStack(this)); + return state.getValue(SMALL) ? Collections.singletonList(new ItemStack(EndBlocks.CAVE_PUMPKIN_SEED)) : Collections.singletonList(new ItemStack(this)); } - + static { - VoxelShape lantern = Block.createCuboidShape(1, 0, 1, 15, 13, 15); - VoxelShape cap = Block.createCuboidShape(0, 12, 0, 16, 15, 16); - VoxelShape top = Block.createCuboidShape(5, 15, 5, 11, 16, 11); - SHAPE_BIG = VoxelShapes.union(lantern, cap, top); - - lantern = Block.createCuboidShape(1, 7, 1, 15, 13, 15); - cap = Block.createCuboidShape(4, 12, 4, 12, 15, 12); - top = Block.createCuboidShape(6, 15, 6, 10, 16, 10); - SHAPE_SMALL = VoxelShapes.union(lantern, cap, top); + VoxelShape lantern = Block.box(1, 0, 1, 15, 13, 15); + VoxelShape cap = Block.box(0, 12, 0, 16, 15, 16); + VoxelShape top = Block.box(5, 15, 5, 11, 16, 11); + SHAPE_BIG = Shapes.or(lantern, cap, top); + + lantern = Block.box(1, 7, 1, 15, 13, 15); + cap = Block.box(4, 12, 4, 12, 15, 12); + top = Block.box(6, 15, 6, 10, 16, 10); + SHAPE_SMALL = Shapes.or(lantern, cap, top); } } diff --git a/src/main/java/ru/betterend/blocks/CavePumpkinVineBlock.java b/src/main/java/ru/betterend/blocks/CavePumpkinVineBlock.java index 592f5de0..e5754327 100644 --- a/src/main/java/ru/betterend/blocks/CavePumpkinVineBlock.java +++ b/src/main/java/ru/betterend/blocks/CavePumpkinVineBlock.java @@ -1,73 +1,69 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; public class CavePumpkinVineBlock extends EndPlantWithAgeBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 16, 12); - + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - BlockState down = world.getBlockState(pos.up()); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + BlockState down = world.getBlockState(pos.above()); return isTerrain(down); } - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { int age = state.getValue(AGE); BlockState down = world.getBlockState(pos.below()); - if (down.getMaterial().isReplaceable() - || (down.is(EndBlocks.CAVE_PUMPKIN) && down.get(BlockProperties.SMALL))) { + if (down.getMaterial().isReplaceable() || (down.is(EndBlocks.CAVE_PUMPKIN) && down.getValue(BlockProperties.SMALL))) { if (age < 3) { - world.setBlockAndUpdate(pos, state.with(AGE, age + 1)); + world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1)); } if (age == 2) { - world.setBlockAndUpdate(pos.below(), - EndBlocks.CAVE_PUMPKIN.defaultBlockState().with(BlockProperties.SMALL, true)); - } else if (age == 3) { + world.setBlockAndUpdate(pos.below(), EndBlocks.CAVE_PUMPKIN.defaultBlockState().setValue(BlockProperties.SMALL, true)); + } + else if (age == 3) { world.setBlockAndUpdate(pos.below(), EndBlocks.CAVE_PUMPKIN.defaultBlockState()); } } } @Override - public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { - } - + public void growAdult(WorldGenLevel world, Random random, BlockPos pos) {} + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { state = super.updateShape(state, facing, neighborState, world, pos, neighborPos); if (state.is(this) && state.getValue(BlockProperties.AGE) > 1) { BlockState down = world.getBlockState(pos.below()); if (!down.is(EndBlocks.CAVE_PUMPKIN)) { - state = state.with(BlockProperties.AGE, 1); + state = state.setValue(BlockProperties.AGE, 1); } } return state; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/blocks/ChandelierBlock.java b/src/main/java/ru/betterend/blocks/ChandelierBlock.java index 7f89ecb2..36d883df 100644 --- a/src/main/java/ru/betterend/blocks/ChandelierBlock.java +++ b/src/main/java/ru/betterend/blocks/ChandelierBlock.java @@ -6,16 +6,16 @@ import java.util.EnumMap; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -24,52 +24,55 @@ import ru.betterend.patterns.Patterns; public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockPatterned { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); - + public ChandelierBlock(Block source) { - super(FabricBlockSettings.copyOf(source).noCollision().nonOpaque().requiresTool().luminance(15)); + super(FabricBlockSettings.copyOf(source).luminance(15).noCollission().noOcclusion().requiresCorrectToolForDrops()); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); if (block.contains("item")) { return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath()); - } else if (block.contains("ceil")) { + } + else if (block.contains("ceil")) { return Patterns.createJson(Patterns.BLOCK_CHANDELIER_CEIL, blockId.getPath()); - } else if (block.contains("wall")) { + } + else if (block.contains("wall")) { return Patterns.createJson(Patterns.BLOCK_CHANDELIER_WALL, blockId.getPath()); - } else { + } + else { return Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, blockId.getPath()); } } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_CHANDELIER; } - + static { - BOUNDING_SHAPES.put(Direction.UP, Block.createCuboidShape(5, 0, 5, 11, 13, 11)); - BOUNDING_SHAPES.put(Direction.DOWN, Block.createCuboidShape(5, 3, 5, 11, 16, 11)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.UP, Block.box(5, 0, 5, 11, 13, 11)); + BOUNDING_SHAPES.put(Direction.DOWN, Block.box(5, 3, 5, 11, 16, 11)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); } } diff --git a/src/main/java/ru/betterend/blocks/CharniaBlock.java b/src/main/java/ru/betterend/blocks/CharniaBlock.java index ca03ed0b..86d510d6 100644 --- a/src/main/java/ru/betterend/blocks/CharniaBlock.java +++ b/src/main/java/ru/betterend/blocks/CharniaBlock.java @@ -1,16 +1,15 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Fluids; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluids; import ru.betterend.blocks.basis.UnderwaterPlantBlock; public class CharniaBlock extends UnderwaterPlantBlock { @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return sideCoversSmallSquare(world, pos.below(), Direction.UP) - && world.getFluidState(pos).getFluid() == Fluids.WATER; + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return canSupportCenter(world, pos.below(), Direction.UP) && world.getFluidState(pos).getType() == Fluids.WATER; } } diff --git a/src/main/java/ru/betterend/blocks/ChorusGrassBlock.java b/src/main/java/ru/betterend/blocks/ChorusGrassBlock.java index 66bb0d7d..71635d36 100644 --- a/src/main/java/ru/betterend/blocks/ChorusGrassBlock.java +++ b/src/main/java/ru/betterend/blocks/ChorusGrassBlock.java @@ -8,7 +8,7 @@ public class ChorusGrassBlock extends EndPlantBlock { public ChorusGrassBlock() { super(true); } - + @Override protected boolean isTerrain(BlockState state) { return state.getBlock() == EndBlocks.CHORUS_NYLIUM; diff --git a/src/main/java/ru/betterend/blocks/DenseSnowBlock.java b/src/main/java/ru/betterend/blocks/DenseSnowBlock.java index f369dd2a..f124f539 100644 --- a/src/main/java/ru/betterend/blocks/DenseSnowBlock.java +++ b/src/main/java/ru/betterend/blocks/DenseSnowBlock.java @@ -1,12 +1,12 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; public class DenseSnowBlock extends BlockBase { public DenseSnowBlock() { - super(FabricBlockSettings.of(Material.SNOW_BLOCK).strength(0.2F).sounds(SoundType.SNOW)); + super(FabricBlockSettings.of(Material.SNOW).strength(0.2F).sound(SoundType.SNOW)); } } diff --git a/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java b/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java index 7d909473..30494c1f 100644 --- a/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/DragonTreeSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.registry.EndBlocks; @@ -17,9 +17,9 @@ public class DragonTreeSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.DRAGON_TREE.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.SHADOW_GRASS); } } diff --git a/src/main/java/ru/betterend/blocks/EmeraldIceBlock.java b/src/main/java/ru/betterend/blocks/EmeraldIceBlock.java index dabdbeca..04b93080 100644 --- a/src/main/java/ru/betterend/blocks/EmeraldIceBlock.java +++ b/src/main/java/ru/betterend/blocks/EmeraldIceBlock.java @@ -8,28 +8,28 @@ import java.util.Random; import org.jetbrains.annotations.Nullable; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.TransparentBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; -import net.minecraft.world.LightType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HalfTransparentBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; -public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable, BlockPatterned { +public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderTypeable, BlockPatterned { public EmeraldIceBlock() { super(FabricBlockSettings.copyOf(Blocks.ICE)); } @@ -40,17 +40,16 @@ public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable } @Override - public void afterBreak(Level world, Player player, BlockPos pos, BlockState state, - @Nullable BlockEntity blockEntity, ItemStack stack) { - super.afterBreak(world, player, pos, state, blockEntity, stack); + public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack) { + super.playerDestroy(world, player, pos, state, blockEntity, stack); if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) == 0) { - if (world.getDimension().isUltrawarm()) { + if (world.dimensionType().ultraWarm()) { world.removeBlock(pos, false); return; } Material material = world.getBlockState(pos.below()).getMaterial(); - if (material.blocksMovement() || material.isLiquid()) { + if (material.blocksMotion() || material.isLiquid()) { world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState()); } } @@ -59,38 +58,39 @@ public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - if (world.getLightLevel(LightType.BLOCK, pos) > 11 - state.getOpacity(world, pos)) { + if (world.getBrightness(LightLayer.BLOCK, pos) > 11 - state.getLightBlock(world, pos)) { this.melt(state, world, pos); } } protected void melt(BlockState state, Level world, BlockPos pos) { - if (world.getDimension().isUltrawarm()) { + if (world.dimensionType().ultraWarm()) { world.removeBlock(pos, false); - } else { + } + else { world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState()); - world.updateNeighbor(pos, Blocks.WATER, pos); + world.neighborChanged(pos, Blocks.WATER, pos); } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/EndLilyBlock.java b/src/main/java/ru/betterend/blocks/EndLilyBlock.java index e6f300ee..0988db53 100644 --- a/src/main/java/ru/betterend/blocks/EndLilyBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLilyBlock.java @@ -10,26 +10,26 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.UnderwaterPlantBlock; import ru.betterend.registry.EndBlocks; @@ -38,80 +38,81 @@ import ru.betterend.util.MHelper; public class EndLilyBlock extends UnderwaterPlantBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(4, 0, 4, 12, 16, 12); - private static final VoxelShape SHAPE_TOP = Block.createCuboidShape(2, 0, 2, 14, 6, 14); - + private static final VoxelShape SHAPE_BOTTOM = Block.box(4, 0, 4, 12, 16, 12); + private static final VoxelShape SHAPE_TOP = Block.box(2, 0, 2, 14, 6, 14); + public EndLilyBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).breakByHand(true).luminance((state) -> { - return state.getValue(SHAPE) == TripleShape.TOP ? 13 : 0; - }).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .lightLevel((state) -> state.getValue(SHAPE) == TripleShape.TOP ? 13 : 0) + .noCollission()); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { - return state.getValue(SHAPE) == TripleShape.TOP ? Blocks.AIR.defaultBlockState() - : Blocks.WATER.defaultBlockState(); - } else { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { + return state.getValue(SHAPE) == TripleShape.TOP ? Blocks.AIR.defaultBlockState() : Blocks.WATER.defaultBlockState(); + } + else { return state; } } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); VoxelShape shape = state.getValue(SHAPE) == TripleShape.TOP ? SHAPE_TOP : SHAPE_BOTTOM; - return shape.offset(vec3d.x, vec3d.y, vec3d.z); + return shape.move(vec3d.x, vec3d.y, vec3d.z); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override public FluidState getFluidState(BlockState state) { - return state.getValue(SHAPE) == TripleShape.TOP ? Fluids.EMPTY.defaultBlockState() - : Fluids.WATER.getStill(false); + return state.getValue(SHAPE) == TripleShape.TOP ? Fluids.EMPTY.defaultFluidState() : Fluids.WATER.getSource(false); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { if (state.getValue(SHAPE) == TripleShape.TOP) { return world.getBlockState(pos.below()).getBlock() == this; - } else if (state.getValue(SHAPE) == TripleShape.BOTTOM) { + } + else if (state.getValue(SHAPE) == TripleShape.BOTTOM) { return isTerrain(world.getBlockState(pos.below())); - } else { - BlockState up = world.getBlockState(pos.up()); + } + else { + BlockState up = world.getBlockState(pos.above()); BlockState down = world.getBlockState(pos.below()); return up.getBlock() == this && down.getBlock() == this; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(SHAPE) == TripleShape.TOP) { - return Lists.newArrayList(new ItemStack(EndItems.END_LILY_LEAF, MHelper.randRange(1, 2, MHelper.RANDOM)), - new ItemStack(EndBlocks.END_LILY_SEED, MHelper.randRange(1, 2, MHelper.RANDOM))); + return Lists.newArrayList(new ItemStack(EndItems.END_LILY_LEAF, MHelper.randRange(1, 2, MHelper.RANDOM)), new ItemStack(EndBlocks.END_LILY_SEED, MHelper.randRange(1, 2, MHelper.RANDOM))); } return Collections.emptyList(); } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { return new ItemStack(EndBlocks.END_LILY_SEED); } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/EndLilySeedBlock.java b/src/main/java/ru/betterend/blocks/EndLilySeedBlock.java index aa158218..f2f67d4c 100644 --- a/src/main/java/ru/betterend/blocks/EndLilySeedBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLilySeedBlock.java @@ -1,10 +1,9 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.material.Fluids; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.material.Fluids; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -14,24 +13,21 @@ public class EndLilySeedBlock extends UnderwaterPlantWithAgeBlock { @Override public void grow(WorldGenLevel world, Random random, BlockPos pos) { if (canGrow(world, pos)) { - BlocksHelper.setWithoutUpdate(world, pos, - EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.BOTTOM)); - BlockPos up = pos.up(); - while (world.getFluidState(up).isStill()) { - BlocksHelper.setWithoutUpdate(world, up, - EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.MIDDLE)); - up = up.up(); + BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.BOTTOM)); + BlockPos up = pos.above(); + while (world.getFluidState(up).isSource()) { + BlocksHelper.setWithoutUpdate(world, up, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.MIDDLE)); + up = up.above(); } - BlocksHelper.setWithoutUpdate(world, up, - EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.TOP)); + BlocksHelper.setWithoutUpdate(world, up, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.TOP)); } } - + private boolean canGrow(WorldGenLevel world, BlockPos pos) { - BlockPos up = pos.up(); - while (world.getBlockState(up).getFluidState().getFluid().equals(Fluids.WATER.getStill())) { - up = up.up(); + BlockPos up = pos.above(); + while (world.getBlockState(up).getFluidState().getType().equals(Fluids.WATER.getSource())) { + up = up.above(); } - return world.isAir(up); + return world.isEmptyBlock(up); } } diff --git a/src/main/java/ru/betterend/blocks/EndLotusFlowerBlock.java b/src/main/java/ru/betterend/blocks/EndLotusFlowerBlock.java index 71f36555..58a56cc7 100644 --- a/src/main/java/ru/betterend/blocks/EndLotusFlowerBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLotusFlowerBlock.java @@ -7,57 +7,57 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.AbstractBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.util.MHelper; public class EndLotusFlowerBlock extends EndPlantBlock { - private static final VoxelShape SHAPE_OUTLINE = Block.createCuboidShape(2, 0, 2, 14, 14, 14); - private static final VoxelShape SHAPE_COLLISION = Block.createCuboidShape(0, 0, 0, 16, 2, 16); - + private static final VoxelShape SHAPE_OUTLINE = Block.box(2, 0, 2, 14, 14, 14); + private static final VoxelShape SHAPE_COLLISION = Block.box(0, 0, 0, 16, 2, 16); + public EndLotusFlowerBlock() { - super(FabricBlockSettings.of(Material.PLANT).nonOpaque().luminance(15)); + super(FabricBlockSettings.of(Material.PLANT).luminance(15).noOcclusion()); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_LOTUS_STEM); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE_OUTLINE; } - + @Override - public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE_COLLISION; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { int count = MHelper.randRange(1, 2, MHelper.RANDOM); return Lists.newArrayList(new ItemStack(EndBlocks.END_LOTUS_SEED, count)); } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { return new ItemStack(EndBlocks.END_LOTUS_SEED); } } diff --git a/src/main/java/ru/betterend/blocks/EndLotusLeafBlock.java b/src/main/java/ru/betterend/blocks/EndLotusLeafBlock.java index 4cf66025..f2167e6a 100644 --- a/src/main/java/ru/betterend/blocks/EndLotusLeafBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLotusLeafBlock.java @@ -3,23 +3,23 @@ package ru.betterend.blocks; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.fluid.WaterFluid; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.WaterFluid; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; @@ -28,48 +28,48 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; public class EndLotusLeafBlock extends BlockBaseNotFull implements IRenderTypeable { - public static final EnumProperty HORIZONTAL_FACING = Properties.HORIZONTAL_FACING; + public static final EnumProperty HORIZONTAL_FACING = BlockStateProperties.HORIZONTAL_FACING; public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - private static final VoxelShape VSHAPE = Block.createCuboidShape(0, 0, 0, 16, 1, 16); - + private static final VoxelShape VSHAPE = Block.box(0, 0, 0, 16, 1, 16); + public EndLotusLeafBlock() { - super(FabricBlockSettings.of(Material.PLANT).nonOpaque().sounds(SoundType.WET_GRASS)); + super(FabricBlockSettings.of(Material.PLANT).noOcclusion().sound(SoundType.WET_GRASS)); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); - return !down.getFluidState().isEmpty() && down.getFluidState().getFluid() instanceof WaterFluid; + return !down.getFluidState().isEmpty() && down.getFluidState().getType() instanceof WaterFluid; } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(SHAPE, HORIZONTAL_FACING); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return VSHAPE; } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, HORIZONTAL_FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, HORIZONTAL_FACING); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { return new ItemStack(EndBlocks.END_LOTUS_SEED); } } diff --git a/src/main/java/ru/betterend/blocks/EndLotusSeedBlock.java b/src/main/java/ru/betterend/blocks/EndLotusSeedBlock.java index c812c3b4..40111055 100644 --- a/src/main/java/ru/betterend/blocks/EndLotusSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLotusSeedBlock.java @@ -1,13 +1,12 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Fluids; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluids; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -17,103 +16,100 @@ public class EndLotusSeedBlock extends UnderwaterPlantWithAgeBlock { @Override public void grow(WorldGenLevel world, Random random, BlockPos pos) { if (canGrow(world, pos)) { - BlockState startLeaf = EndBlocks.END_LOTUS_STEM.defaultBlockState().with(EndLotusStemBlock.LEAF, true); - BlockState roots = EndBlocks.END_LOTUS_STEM.defaultBlockState() - .with(EndLotusStemBlock.SHAPE, TripleShape.BOTTOM).with(EndLotusStemBlock.WATERLOGGED, true); + BlockState startLeaf = EndBlocks.END_LOTUS_STEM.defaultBlockState().setValue(EndLotusStemBlock.LEAF, true); + BlockState roots = EndBlocks.END_LOTUS_STEM.defaultBlockState().setValue(EndLotusStemBlock.SHAPE, TripleShape.BOTTOM).setValue(EndLotusStemBlock.WATERLOGGED, true); BlockState stem = EndBlocks.END_LOTUS_STEM.defaultBlockState(); BlockState flower = EndBlocks.END_LOTUS_FLOWER.defaultBlockState(); - + BlocksHelper.setWithoutUpdate(world, pos, roots); MutableBlockPos bpos = new MutableBlockPos().set(pos); bpos.setY(bpos.getY() + 1); - while (world.getFluidState(bpos).isStill()) { - BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.WATERLOGGED, true)); + while (world.getFluidState(bpos).isSource()) { + BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.WATERLOGGED, true)); bpos.setY(bpos.getY() + 1); } - + int height = random.nextBoolean() ? 0 : random.nextBoolean() ? 1 : random.nextBoolean() ? 1 : -1; TripleShape shape = (height == 0) ? TripleShape.TOP : TripleShape.MIDDLE; Direction dir = BlocksHelper.randomHorizontal(random); - BlockPos leafCenter = bpos.immutable().offset(dir); + BlockPos leafCenter = bpos.immutable().relative(dir); if (hasLeaf(world, leafCenter)) { generateLeaf(world, leafCenter); - BlocksHelper.setWithoutUpdate(world, bpos, - startLeaf.with(EndLotusStemBlock.SHAPE, shape).with(EndLotusStemBlock.FACING, dir)); - } else { - BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.SHAPE, shape)); + BlocksHelper.setWithoutUpdate(world, bpos, startLeaf.setValue(EndLotusStemBlock.SHAPE, shape).setValue(EndLotusStemBlock.FACING, dir)); } - + else { + BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.SHAPE, shape)); + } + bpos.setY(bpos.getY() + 1); for (int i = 1; i <= height; i++) { - if (!world.isAir(bpos)) { + if (!world.isEmptyBlock(bpos)) { bpos.setY(bpos.getY() - 1); BlocksHelper.setWithoutUpdate(world, bpos, flower); bpos.setY(bpos.getY() - 1); stem = world.getBlockState(bpos); - BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.SHAPE, TripleShape.TOP)); + BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.SHAPE, TripleShape.TOP)); return; } BlocksHelper.setWithoutUpdate(world, bpos, stem); bpos.setY(bpos.getY() + 1); } - - if (!world.isAir(bpos) || height < 0) { + + if (!world.isEmptyBlock(bpos) || height < 0) { bpos.setY(bpos.getY() - 1); } - + BlocksHelper.setWithoutUpdate(world, bpos, flower); bpos.setY(bpos.getY() - 1); stem = world.getBlockState(bpos); if (!stem.is(EndBlocks.END_LOTUS_STEM)) { stem = EndBlocks.END_LOTUS_STEM.defaultBlockState(); if (!world.getBlockState(bpos.north()).getFluidState().isEmpty()) { - stem = stem.with(EndLotusStemBlock.WATERLOGGED, true); + stem = stem.setValue(EndLotusStemBlock.WATERLOGGED, true); } } - - if (world.getBlockState(bpos.offset(dir)).is(EndBlocks.END_LOTUS_LEAF)) { - stem = stem.with(EndLotusStemBlock.LEAF, true).with(EndLotusStemBlock.FACING, dir); + + if (world.getBlockState(bpos.relative(dir)).is(EndBlocks.END_LOTUS_LEAF)) { + stem = stem.setValue(EndLotusStemBlock.LEAF, true).setValue(EndLotusStemBlock.FACING, dir); } - - BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.SHAPE, TripleShape.TOP)); + + BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.SHAPE, TripleShape.TOP)); } } - + private boolean canGrow(WorldGenLevel world, BlockPos pos) { MutableBlockPos bpos = new MutableBlockPos(); bpos.set(pos); - while (world.getBlockState(bpos).getFluidState().getFluid().equals(Fluids.WATER.getStill())) { + while (world.getBlockState(bpos).getFluidState().getType().equals(Fluids.WATER.getSource())) { bpos.setY(bpos.getY() + 1); } - return world.isAir(bpos) && world.isAir(bpos.up()); + return world.isEmptyBlock(bpos) && world.isEmptyBlock(bpos.above()); } - + private void generateLeaf(WorldGenLevel world, BlockPos pos) { MutableBlockPos p = new MutableBlockPos(); BlockState leaf = EndBlocks.END_LOTUS_LEAF.defaultBlockState(); - BlocksHelper.setWithoutUpdate(world, pos, leaf.with(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM)); - for (Direction move : BlocksHelper.HORIZONTAL) { - BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf - .with(EndLotusLeafBlock.HORIZONTAL_FACING, move).with(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE)); + BlocksHelper.setWithoutUpdate(world, pos, leaf.setValue(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM)); + for (Direction move: BlocksHelper.HORIZONTAL) { + BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, move).setValue(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE)); } - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i ++) { Direction d1 = BlocksHelper.HORIZONTAL[i]; Direction d2 = BlocksHelper.HORIZONTAL[(i + 1) & 3]; - BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), - leaf.with(EndLotusLeafBlock.HORIZONTAL_FACING, d1).with(EndLotusLeafBlock.SHAPE, TripleShape.TOP)); + BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, d1).setValue(EndLotusLeafBlock.SHAPE, TripleShape.TOP)); } } - + private boolean hasLeaf(WorldGenLevel world, BlockPos pos) { MutableBlockPos p = new MutableBlockPos(); p.setY(pos.getY()); int count = 0; - for (int x = -1; x < 2; x++) { + for (int x = -1; x < 2; x ++) { p.setX(pos.getX() + x); - for (int z = -1; z < 2; z++) { + for (int z = -1; z < 2; z ++) { p.setZ(pos.getZ() + z); - if (world.isAir(p) && !world.getFluidState(p.below()).isEmpty()) - count++; + if (world.isEmptyBlock(p) && !world.getFluidState(p.below()).isEmpty()) + count ++; } } return count == 9; diff --git a/src/main/java/ru/betterend/blocks/EndLotusStemBlock.java b/src/main/java/ru/betterend/blocks/EndLotusStemBlock.java index 5e0e06eb..f007e202 100644 --- a/src/main/java/ru/betterend/blocks/EndLotusStemBlock.java +++ b/src/main/java/ru/betterend/blocks/EndLotusStemBlock.java @@ -5,96 +5,92 @@ import java.util.Map; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.util.BlocksHelper; -public class EndLotusStemBlock extends BlockBase implements Waterloggable, IRenderTypeable { - public static final EnumProperty FACING = Properties.FACING; - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - public static final BooleanProperty LEAF = BooleanProperty.of("leaf"); +public class EndLotusStemBlock extends BlockBase implements SimpleWaterloggedBlock, IRenderTypeable { + public static final EnumProperty FACING = BlockStateProperties.FACING; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static final BooleanProperty LEAF = BooleanProperty.create("leaf"); public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; private static final Map SHAPES = Maps.newEnumMap(Axis.class); - + public EndLotusStemBlock() { super(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)); - this.setDefaultState(getDefaultState().with(WATERLOGGED, false).with(SHAPE, TripleShape.MIDDLE) - .with(LEAF, false).with(FACING, Direction.UP)); + this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false).setValue(SHAPE, TripleShape.MIDDLE).setValue(LEAF, false).setValue(FACING, Direction.UP)); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(LEAF) ? SHAPES.get(Axis.Y) : SHAPES.get(state.getValue(FACING).getAxis()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, WATERLOGGED, SHAPE, LEAF); } - + @Override public FluidState getFluidState(BlockState state) { - return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { LevelAccessor worldAccess = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - return this.defaultBlockState() - .with(WATERLOGGED, worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER) - .with(FACING, ctx.getSide()); + BlockPos blockPos = ctx.getClickedPos(); + return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER).setValue(FACING, ctx.getClickedFace()); } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { if ((Boolean) state.getValue(WATERLOGGED)) { - world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return state; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + static { - SHAPES.put(Axis.X, Block.createCuboidShape(0, 6, 6, 16, 10, 10)); - SHAPES.put(Axis.Y, Block.createCuboidShape(6, 0, 6, 10, 16, 10)); - SHAPES.put(Axis.Z, Block.createCuboidShape(6, 6, 0, 10, 10, 16)); + SHAPES.put(Axis.X, Block.box(0, 6, 6, 16, 10, 10)); + SHAPES.put(Axis.Y, Block.box(6, 0, 6, 10, 16, 10)); + SHAPES.put(Axis.Z, Block.box(6, 6, 0, 10, 10, 16)); } } diff --git a/src/main/java/ru/betterend/blocks/EndPathBlock.java b/src/main/java/ru/betterend/blocks/EndPathBlock.java index 5381aa6c..0f24bb7f 100644 --- a/src/main/java/ru/betterend/blocks/EndPathBlock.java +++ b/src/main/java/ru/betterend/blocks/EndPathBlock.java @@ -7,36 +7,34 @@ import java.util.Map; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.patterns.Patterns; public class EndPathBlock extends BlockBaseNotFull { - private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 15, 16); - + private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); + public EndPathBlock(Block source) { - super(FabricBlockSettings.copyOf(source).allowsSpawning((state, world, pos, type) -> { - return false; - })); + super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; })); if (source instanceof EndTerrainBlock) { EndTerrainBlock terrain = (EndTerrainBlock) source; terrain.setPathBlock(this); } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -45,17 +43,17 @@ public class EndPathBlock extends BlockBaseNotFull { } return Collections.singletonList(new ItemStack(Blocks.END_STONE)); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override - public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override public String getModelPattern(String block) { String name = Registry.BLOCK.getKey(this).getPath(); @@ -64,7 +62,7 @@ public class EndPathBlock extends BlockBaseNotFull { map.put("%side%", name.replace("_path", "") + "_side"); return Patterns.createJson(Patterns.BLOCK_PATH, map); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_ROTATED_TOP; diff --git a/src/main/java/ru/betterend/blocks/EndPedestal.java b/src/main/java/ru/betterend/blocks/EndPedestal.java index 8a157ba4..d5756e44 100644 --- a/src/main/java/ru/betterend/blocks/EndPedestal.java +++ b/src/main/java/ru/betterend/blocks/EndPedestal.java @@ -2,10 +2,9 @@ package ru.betterend.blocks; import java.util.HashMap; import java.util.Map; - -import net.minecraft.world.level.block.Block; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.patterns.Patterns; @@ -15,7 +14,7 @@ public class EndPedestal extends PedestalBlock { public EndPedestal(Block parent) { super(parent); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(parent); @@ -23,7 +22,7 @@ public class EndPedestal extends PedestalBlock { Map textures = new HashMap() { private static final long serialVersionUID = 1L; { - put("%mod%", BetterEnd.MOD_ID); + put("%mod%", BetterEnd.MOD_ID ); put("%top%", name + "_polished"); put("%base%", name + "_polished"); put("%pillar%", name + "_pillar_side"); diff --git a/src/main/java/ru/betterend/blocks/EndPortalBlock.java b/src/main/java/ru/betterend/blocks/EndPortalBlock.java index dfed2978..3fc80413 100644 --- a/src/main/java/ru/betterend/blocks/EndPortalBlock.java +++ b/src/main/java/ru/betterend/blocks/EndPortalBlock.java @@ -6,29 +6,29 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.client.color.block.BlockColor; +import net.minecraft.client.color.item.ItemColor; +import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Direction.Axis; +import net.minecraft.core.Direction.AxisDirection; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.NetherPortalBlock; -import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.world.entity.Entity; -import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction.Axis; -import net.minecraft.core.Direction.AxisDirection; import net.minecraft.world.level.dimension.DimensionType; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IColorProvider; @@ -42,8 +42,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable public static final IntegerProperty PORTAL = BlockProperties.PORTAL; public EndPortalBlock() { - super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getExplosionResistance()) - .luminance(15)); + super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getExplosionResistance()).luminance(15)); } @Override @@ -51,13 +50,12 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable super.createBlockStateDefinition(builder); builder.add(PORTAL); } - + @Override @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { if (random.nextInt(100) == 0) { - world.playLocalSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.PORTAL_AMBIENT, - SoundSource.BLOCKS, 0.5F, random.nextFloat() * 0.4F + 0.8F, false); + world.playLocalSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.PORTAL_AMBIENT, SoundSource.BLOCKS, 0.5F, random.nextFloat() * 0.4F + 0.8F, false); } double x = pos.getX() + random.nextDouble(); @@ -74,24 +72,24 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable } @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { + public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {} + + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { return state; } - + @Override public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if (world.isClientSide() || !validate(entity)) - return; + if (world.isClientSide || !validate(entity)) return; entity.setPortalCooldown(); ServerLevel currentWorld = (ServerLevel) world; MinecraftServer server = currentWorld.getServer(); - ServerLevel targetWorld = EndPortals.getLevel(server, state.getValue(PORTAL)); + ServerLevel targetWorld = EndPortals.getWorld(server, state.getValue(PORTAL)); boolean isInEnd = currentWorld.dimension().equals(Level.END); ServerLevel destination = isInEnd ? targetWorld : server.getLevel(Level.END); BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity); - if (exitPos == null) - return; + if (exitPos == null) return; if (entity instanceof ServerPlayer) { ServerPlayer player = (ServerPlayer) entity; teleportPlayer(player, destination, exitPos); @@ -106,43 +104,39 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable } private boolean validate(Entity entity) { - return !entity.isPassenger() && !entity.isVehicle() && entity.canChangeDimensions() - && !entity.isOnPortalCooldown(); + return !entity.isPassenger() && !entity.isVehicle() && + entity.canChangeDimensions() && !entity.isOnPortalCooldown(); } private void teleportPlayer(ServerPlayer player, ServerLevel destination, BlockPos exitPos) { if (player.isCreative()) { - player.teleportTo(destination, exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5, player.yRot, - player.xRot); + player.teleportTo(destination, exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5, player.yRot, player.xRot); } else { TeleportingEntity teleEntity = (TeleportingEntity) player; teleEntity.beSetExitPos(exitPos); player.changeDimension(destination); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; } - - private BlockPos findExitPos(ServerLevel currentWorld, ServerLevel targetWorld, BlockPos currentPos, - Entity entity) { - if (targetWorld == null) - return null; + + private BlockPos findExitPos(ServerLevel currentWorld, ServerLevel targetWorld, BlockPos currentPos, Entity entity) { + if (targetWorld == null) return null; Registry registry = targetWorld.registryAccess().dimensionTypes(); ResourceLocation targetWorldId = targetWorld.dimension().location(); ResourceLocation currentWorldId = currentWorld.dimension().location(); double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).coordinateScale(); double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).coordinateScale(); double multiplier = targetMultiplier > currentMultiplier ? 1.0 / targetMultiplier : currentMultiplier; - BlockPos.MutableBlockPos basePos = currentPos.mutable().set(currentPos.getX() * multiplier, currentPos.getY(), - currentPos.getZ() * multiplier); + BlockPos.MutableBlockPos basePos = currentPos.mutable().set(currentPos.getX() * multiplier, currentPos.getY(), currentPos.getZ() * multiplier); BlockPos.MutableBlockPos checkPos = basePos.mutable(); BlockState currentState = currentWorld.getBlockState(currentPos); int radius = (EternalRitual.SEARCH_RADIUS >> 4) + 1; - checkPos = EternalRitual.findBlockPos(targetWorld, checkPos, radius, this, - state -> state.is(this) && state.getValue(PORTAL).equals(currentState.getValue(PORTAL))); + checkPos = EternalRitual.findBlockPos(targetWorld, checkPos, radius, this, state -> state.is(this) && + state.getValue(PORTAL).equals(currentState.getValue(PORTAL))); if (checkPos != null) { BlockState checkState = targetWorld.getBlockState(checkPos); Axis axis = checkState.getValue(AXIS); @@ -156,19 +150,17 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable entity.rotate(Rotation.CLOCKWISE_90); entityDir = entityDir.getClockWise(); } - return checkPos.move(entityDir); + return checkPos.relative(entityDir); } return null; } - + private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis) { return findCenter(world, pos, axis, 1); } - - private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis, - int step) { - if (step > 8) - return pos; + + private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis, int step) { + if (step > 8) return pos; BlockState right, left; Direction rightDir, leftDir; rightDir = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE); @@ -189,7 +181,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable } @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> EndPortals.getColor(state.getValue(PORTAL)); } diff --git a/src/main/java/ru/betterend/blocks/EndStoneBlock.java b/src/main/java/ru/betterend/blocks/EndStoneBlock.java index ddc17d9f..db65cd45 100644 --- a/src/main/java/ru/betterend/blocks/EndStoneBlock.java +++ b/src/main/java/ru/betterend/blocks/EndStoneBlock.java @@ -2,12 +2,12 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.basis.BlockBase; public class EndStoneBlock extends BlockBase { public EndStoneBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sounds(SoundType.STONE)); + super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(SoundType.STONE)); } } diff --git a/src/main/java/ru/betterend/blocks/EndStoneSmelter.java b/src/main/java/ru/betterend/blocks/EndStoneSmelter.java index bdcf1674..4e326c72 100644 --- a/src/main/java/ru/betterend/blocks/EndStoneSmelter.java +++ b/src/main/java/ru/betterend/blocks/EndStoneSmelter.java @@ -8,85 +8,89 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockRenderType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.HorizontalFacingBlock; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.ActionResult; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.BlockHitResult; import ru.betterend.blocks.basis.BaseBlockWithEntity; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; public class EndStoneSmelter extends BaseBlockWithEntity { - public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; - public static final BooleanProperty LIT = Properties.LIT; + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; + public static final BooleanProperty LIT = BlockStateProperties.LIT; public static final String ID = "end_stone_smelter"; public EndStoneSmelter() { - super(FabricBlockSettings.of(Material.STONE, MaterialColor.COLOR_GRAY).hardness(4F).resistance(100F) - .requiresTool().sounds(SoundType.STONE)); - this.setDefaultState(this.stateManager.defaultBlockState().with(FACING, Direction.NORTH).with(LIT, false)); + super(FabricBlockSettings.of(Material.STONE, MaterialColor.COLOR_GRAY) + .hardness(4F) + .resistance(100F) + .requiresCorrectToolForDrops() + .sound(SoundType.STONE)); + this.registerDefaultState(this.stateDefinition.any() + .setValue(FACING, Direction.NORTH) + .setValue(LIT, false)); } - - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { + + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (world.isClientSide) { - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } else { this.openScreen(world, pos, player); - return ActionResult.CONSUME; + return InteractionResult.CONSUME; } } private void openScreen(Level world, BlockPos pos, Player player) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EndStoneSmelterBlockEntity) { - player.openHandledScreen((EndStoneSmelterBlockEntity) blockEntity); + player.openMenu((EndStoneSmelterBlockEntity) blockEntity); } } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - return this.defaultBlockState().with(FACING, ctx.getPlayerFacing().getOpposite()); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite()); } - + @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new EndStoneSmelterBlockEntity(); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { List drop = Lists.newArrayList(new ItemStack(this)); - BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); + BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); if (blockEntity instanceof EndStoneSmelterBlockEntity) { EndStoneSmelterBlockEntity smelterBlockEntity = (EndStoneSmelterBlockEntity) blockEntity; - for (int i = 0; i < smelterBlockEntity.size(); i++) { - ItemStack item = smelterBlockEntity.getStack(i); + for (int i = 0; i < smelterBlockEntity.getContainerSize(); i++) { + ItemStack item = smelterBlockEntity.getItem(i); if (!item.isEmpty()) { drop.add(item); } @@ -96,36 +100,36 @@ public class EndStoneSmelter extends BaseBlockWithEntity { } @Override - public boolean hasComparatorOutput(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override - public int getComparatorOutput(BlockState state, Level world, BlockPos pos) { - // TODO - return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { + //TODO + return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos)); } @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } @Override public BlockState rotate(BlockState state, Rotation rotation) { - return (BlockState) state.with(FACING, rotation.rotate((Direction) state.getValue(FACING))); + return (BlockState)state.setValue(FACING, rotation.rotate((Direction)state.getValue(FACING))); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { - return state.rotate(mirror.getRotation((Direction) state.getValue(FACING))); + public BlockState mirror(BlockState state, Mirror mirror) { + return state.rotate(mirror.getRotation((Direction)state.getValue(FACING))); } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, LIT); } - + @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { if (state.getValue(LIT)) { @@ -133,16 +137,15 @@ public class EndStoneSmelter extends BaseBlockWithEntity { double y = pos.getY(); double z = pos.getZ() + 0.5D; if (random.nextDouble() < 0.1D) { - world.playLocalSound(x, y, z, SoundEvents.BLOCK_BLASTFURNACE_FIRE_CRACKLE, SoundSource.BLOCKS, 1.0F, - 1.0F, false); + world.playLocalSound(x, y, z, SoundEvents.BLASTFURNACE_FIRE_CRACKLE, SoundSource.BLOCKS, 1.0F, 1.0F, false); } - Direction direction = (Direction) state.getValue(FACING); + Direction direction = (Direction)state.getValue(FACING); Direction.Axis axis = direction.getAxis(); double defOffset = random.nextDouble() * 0.6D - 0.3D; - double offX = axis == Direction.Axis.X ? direction.getOffsetX() * 0.52D : defOffset; + double offX = axis == Direction.Axis.X ? direction.getStepX() * 0.52D : defOffset; double offY = random.nextDouble() * 9.0D / 16.0D; - double offZ = axis == Direction.Axis.Z ? direction.getOffsetZ() * 0.52D : defOffset; + double offZ = axis == Direction.Axis.Z ? direction.getStepZ() * 0.52D : defOffset; world.addParticle(ParticleTypes.SMOKE, x + offX, y + offY, z + offZ, 0.0D, 0.0D, 0.0D); } } diff --git a/src/main/java/ru/betterend/blocks/EndTerrainBlock.java b/src/main/java/ru/betterend/blocks/EndTerrainBlock.java index 765f1a27..2c378e88 100644 --- a/src/main/java/ru/betterend/blocks/EndTerrainBlock.java +++ b/src/main/java/ru/betterend/blocks/EndTerrainBlock.java @@ -9,62 +9,60 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SnowBlock; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; -import net.minecraft.world.chunk.light.ChunkLightProvider; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SnowLayerBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.LayerLightEngine; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.BlockHitResult; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.patterns.Patterns; public class EndTerrainBlock extends BlockBase { private Block pathBlock; - + public EndTerrainBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sounds(BlockSounds.TERRAIN_SOUND) - .ticksRandomly()); + super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks()); } - + public void setPathBlock(Block roadBlock) { this.pathBlock = roadBlock; } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (pathBlock != null && player.getMainHandStack().getItem().isIn(FabricToolTags.SHOVELS)) { - world.playLocalSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) { + world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { world.setBlockAndUpdate(pos, pathBlock.defaultBlockState()); - if (player != null && !player.isCreative()) { - player.getMainHandStack().damage(1, world.random, (ServerPlayer) player); + if (!player.isCreative()) { + player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player); } } - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } - return ActionResult.FAIL; + return InteractionResult.FAIL; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -73,7 +71,7 @@ public class EndTerrainBlock extends BlockBase { } return Collections.singletonList(new ItemStack(Blocks.END_STONE)); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { @@ -81,20 +79,22 @@ public class EndTerrainBlock extends BlockBase { } } - protected boolean canSurvive(BlockState state, WorldView worldView, BlockPos pos) { - BlockPos blockPos = pos.up(); + @Override + public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) { + BlockPos blockPos = pos.above(); BlockState blockState = worldView.getBlockState(blockPos); - if (blockState.is(Blocks.SNOW) && (Integer) blockState.get(SnowBlock.LAYERS) == 1) { + if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) { return true; - } else if (blockState.getFluidState().getLevel() == 8) { + } + else if (blockState.getFluidState().getAmount() == 8) { return false; - } else { - int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, - blockState.getOpacity(worldView, blockPos)); + } + else { + int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos)); return i < 5; } } - + @Override public String getModelPattern(String block) { String name = Registry.BLOCK.getKey(this).getPath(); @@ -104,7 +104,7 @@ public class EndTerrainBlock extends BlockBase { map.put("%bottom%", "minecraft:block/end_stone"); return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_ROTATED_TOP; diff --git a/src/main/java/ru/betterend/blocks/EnderBlock.java b/src/main/java/ru/betterend/blocks/EnderBlock.java index 3458aa07..bb20eb58 100644 --- a/src/main/java/ru/betterend/blocks/EnderBlock.java +++ b/src/main/java/ru/betterend/blocks/EnderBlock.java @@ -3,23 +3,26 @@ package ru.betterend.blocks; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import ru.betterend.blocks.basis.BlockBase; public class EnderBlock extends BlockBase { public EnderBlock() { - super(FabricBlockSettings.of(Material.STONE, MaterialColor.field_25708).hardness(5F).resistance(6F) - .requiresTool().sounds(SoundType.STONE)); + super(FabricBlockSettings.of(Material.STONE, MaterialColor.WARPED_WART_BLOCK) + .hardness(5F) + .resistance(6F) + .requiresCorrectToolForDrops() + .sound(SoundType.STONE)); } @Environment(EnvType.CLIENT) - public int getColor(BlockState state, BlockView world, BlockPos pos) { + public int getColor(BlockState state, BlockGetter world, BlockPos pos) { return 0xFF005548; } } diff --git a/src/main/java/ru/betterend/blocks/EndstoneDustBlock.java b/src/main/java/ru/betterend/blocks/EndstoneDustBlock.java index 51664204..ef5b51cc 100644 --- a/src/main/java/ru/betterend/blocks/EndstoneDustBlock.java +++ b/src/main/java/ru/betterend/blocks/EndstoneDustBlock.java @@ -7,31 +7,32 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FallingBlock; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import ru.betterend.util.MHelper; public class EndstoneDustBlock extends FallingBlock { @Environment(EnvType.CLIENT) private static final int COLOR = MHelper.color(226, 239, 168); - + public EndstoneDustBlock() { - super(FabricBlockSettings.copyOf(Blocks.SAND).breakByTool(FabricToolTags.SHOVELS) + super(FabricBlockSettings.copyOf(Blocks.SAND) + .breakByTool(FabricToolTags.SHOVELS) .materialColor(Blocks.END_STONE.defaultMaterialColor())); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } @Environment(EnvType.CLIENT) - public int getColor(BlockState state, BlockView world, BlockPos pos) { + public int getDustColor(BlockState state, BlockGetter world, BlockPos pos) { return COLOR; } } diff --git a/src/main/java/ru/betterend/blocks/EternalPedestal.java b/src/main/java/ru/betterend/blocks/EternalPedestal.java index fb17fd27..b857ac4c 100644 --- a/src/main/java/ru/betterend/blocks/EternalPedestal.java +++ b/src/main/java/ru/betterend/blocks/EternalPedestal.java @@ -1,27 +1,25 @@ package ru.betterend.blocks; import java.util.List; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.explosion.Explosion; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import com.google.common.collect.Lists; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.entities.EternalPedestalEntity; import ru.betterend.registry.EndBlocks; @@ -30,12 +28,12 @@ import ru.betterend.rituals.EternalRitual; public class EternalPedestal extends PedestalBlock { public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; - + public EternalPedestal() { super(EndBlocks.FLAVOLITE_RUNED_ETERNAL); - this.setDefaultState(getDefaultState().with(ACTIVATED, false)); + this.registerDefaultState(defaultBlockState().setValue(ACTIVATED, false)); } - + @Override public void checkRitual(Level world, BlockPos pos) { BlockEntity blockEntity = world.getBlockEntity(pos); @@ -56,12 +54,12 @@ public class EternalPedestal extends PedestalBlock { ritual.disablePortal(portalId); } } - world.setBlockAndUpdate(pos, updatedState.with(ACTIVATED, false).with(HAS_LIGHT, false)); + world.setBlockAndUpdate(pos, updatedState.setValue(ACTIVATED, false).setValue(HAS_LIGHT, false)); } else { - ItemStack itemStack = pedestal.getStack(0); - ResourceLocation id = Registry.ITEM.getId(itemStack.getItem()); + ItemStack itemStack = pedestal.getItem(0); + ResourceLocation id = Registry.ITEM.getKey(itemStack.getItem()); if (EndPortals.isAvailableItem(id)) { - world.setBlockAndUpdate(pos, updatedState.with(ACTIVATED, true).with(HAS_LIGHT, true)); + world.setBlockAndUpdate(pos, updatedState.setValue(ACTIVATED, true).setValue(HAS_LIGHT, true)); if (pedestal.hasRitual()) { pedestal.getRitual().checkStructure(); } else { @@ -72,54 +70,51 @@ public class EternalPedestal extends PedestalBlock { } } } - + @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { BlockState updated = super.updateShape(state, direction, newState, world, pos, posFrom); - if (!updated.is(this)) - return updated; + if (!updated.is(this)) return updated; if (!this.isPlaceable(updated)) { - return updated.with(ACTIVATED, false); + return updated.setValue(ACTIVATED, false); } return updated; } - + @Override - public float calcBlockBreakingDelta(BlockState state, Player player, BlockView world, BlockPos pos) { + public float getDestroyProgress(BlockState state, Player player, BlockGetter world, BlockPos pos) { return 0.0F; } - + @Override - public float getBlastResistance() { + public float getExplosionResistance() { return Blocks.BEDROCK.getExplosionResistance(); } - + @Override - public boolean shouldDropItemsOnExplosion(Explosion explosion) { + public boolean dropFromExplosion(Explosion explosion) { return false; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.is(this)) { BlockProperties.PedestalState currentState = state.getValue(BlockProperties.PEDESTAL_STATE); - if (currentState.equals(BlockProperties.PedestalState.BOTTOM) - || currentState.equals(BlockProperties.PedestalState.PILLAR)) { + if (currentState.equals(BlockProperties.PedestalState.BOTTOM) || currentState.equals(BlockProperties.PedestalState.PILLAR)) { return Lists.newArrayList(); } } List drop = Lists.newArrayList(); - BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); + BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); if (blockEntity instanceof EternalPedestalEntity) { EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity; if (!pedestal.isEmpty()) { - drop.add(pedestal.getStack(0)); + drop.add(pedestal.getItem(0)); } } return drop; } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { super.createBlockStateDefinition(stateManager); @@ -127,7 +122,7 @@ public class EternalPedestal extends PedestalBlock { } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new EternalPedestalEntity(); } } diff --git a/src/main/java/ru/betterend/blocks/EternalRunedFlavolite.java b/src/main/java/ru/betterend/blocks/EternalRunedFlavolite.java index a4590b69..a139eafb 100644 --- a/src/main/java/ru/betterend/blocks/EternalRunedFlavolite.java +++ b/src/main/java/ru/betterend/blocks/EternalRunedFlavolite.java @@ -1,35 +1,33 @@ package ru.betterend.blocks; import java.util.List; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.explosion.Explosion; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import com.google.common.collect.Lists; public class EternalRunedFlavolite extends RunedFlavolite { @Override - public float calcBlockBreakingDelta(BlockState state, Player player, BlockView world, BlockPos pos) { + public float getDestroyProgress(BlockState state, Player player, BlockGetter world, BlockPos pos) { return 0.0F; } - + @Override - public float getBlastResistance() { + public float getExplosionResistance() { return Blocks.BEDROCK.getExplosionResistance(); } - + @Override - public boolean shouldDropItemsOnExplosion(Explosion explosion) { + public boolean dropFromExplosion(Explosion explosion) { return false; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Lists.newArrayList(); diff --git a/src/main/java/ru/betterend/blocks/FilaluxLanternBlock.java b/src/main/java/ru/betterend/blocks/FilaluxLanternBlock.java index cb775ead..692ae394 100644 --- a/src/main/java/ru/betterend/blocks/FilaluxLanternBlock.java +++ b/src/main/java/ru/betterend/blocks/FilaluxLanternBlock.java @@ -2,13 +2,12 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; public class FilaluxLanternBlock extends BlockBase { public FilaluxLanternBlock() { - super(FabricBlockSettings.of(Material.WOOD).luminance(15).sounds(SoundType.WOOD) - .breakByTool(FabricToolTags.AXES)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WOOD)); } } diff --git a/src/main/java/ru/betterend/blocks/FlamaeaBlock.java b/src/main/java/ru/betterend/blocks/FlamaeaBlock.java index 4a9b575c..bba1a69d 100644 --- a/src/main/java/ru/betterend/blocks/FlamaeaBlock.java +++ b/src/main/java/ru/betterend/blocks/FlamaeaBlock.java @@ -6,44 +6,46 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.interfaces.ISpetialItem; public class FlamaeaBlock extends EndPlantBlock implements ISpetialItem { - private static final VoxelShape SHAPE = Block.createCuboidShape(0, 0, 0, 16, 1, 16); - + private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 1, 16); + public FlamaeaBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS) - .breakByHand(true)); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS)); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(Blocks.WATER); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Lists.newArrayList(new ItemStack(this)); diff --git a/src/main/java/ru/betterend/blocks/GlowingHymenophoreBlock.java b/src/main/java/ru/betterend/blocks/GlowingHymenophoreBlock.java index ab65538b..c6a01f77 100644 --- a/src/main/java/ru/betterend/blocks/GlowingHymenophoreBlock.java +++ b/src/main/java/ru/betterend/blocks/GlowingHymenophoreBlock.java @@ -2,13 +2,12 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; public class GlowingHymenophoreBlock extends BlockBase { public GlowingHymenophoreBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WART_BLOCK) - .luminance(15)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WART_BLOCK)); } } diff --git a/src/main/java/ru/betterend/blocks/GlowingMossBlock.java b/src/main/java/ru/betterend/blocks/GlowingMossBlock.java index 62814731..22191437 100644 --- a/src/main/java/ru/betterend/blocks/GlowingMossBlock.java +++ b/src/main/java/ru/betterend/blocks/GlowingMossBlock.java @@ -2,9 +2,9 @@ package ru.betterend.blocks; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; @@ -12,19 +12,19 @@ public class GlowingMossBlock extends EndPlantBlock { public GlowingMossBlock(int light) { super(light); } - + @Override protected boolean isTerrain(BlockState state) { return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM; } - + @Environment(EnvType.CLIENT) - public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { - return true; - } + public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) { + return true; + } - @Environment(EnvType.CLIENT) - public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { - return 1F; - } + @Environment(EnvType.CLIENT) + public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) { + return 1F; + } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/GlowingPillarLuminophorBlock.java b/src/main/java/ru/betterend/blocks/GlowingPillarLuminophorBlock.java index ec778642..3eeb97ce 100644 --- a/src/main/java/ru/betterend/blocks/GlowingPillarLuminophorBlock.java +++ b/src/main/java/ru/betterend/blocks/GlowingPillarLuminophorBlock.java @@ -2,45 +2,49 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; public class GlowingPillarLuminophorBlock extends BlockBase { public static final BooleanProperty NATURAL = BlockProperties.NATURAL; - + public GlowingPillarLuminophorBlock() { - super(FabricBlockSettings.of(Material.LEAVES).materialColor(MaterialColor.COLOR_ORANGE) - .breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).strength(0.2F).luminance(15)); - this.setDefaultState(this.stateManager.defaultBlockState().with(NATURAL, false)); + super(FabricBlockSettings.of(Material.LEAVES) + .materialColor(MaterialColor.COLOR_ORANGE) + .breakByTool(FabricToolTags.SHEARS) + .strength(0.2F) + .luminance(15) + .sound(SoundType.GRASS)); + this.registerDefaultState(this.stateDefinition.any().setValue(NATURAL, false)); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return state.getValue(NATURAL) ? world.getBlockState(pos.below()).is(EndBlocks.GLOWING_PILLAR_ROOTS) : true; + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return !state.getValue(NATURAL) || world.getBlockState(pos.below()).is(EndBlocks.GLOWING_PILLAR_ROOTS); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(NATURAL); diff --git a/src/main/java/ru/betterend/blocks/GlowingPillarRootsBlock.java b/src/main/java/ru/betterend/blocks/GlowingPillarRootsBlock.java index ddc4aeb9..4057fa93 100644 --- a/src/main/java/ru/betterend/blocks/GlowingPillarRootsBlock.java +++ b/src/main/java/ru/betterend/blocks/GlowingPillarRootsBlock.java @@ -2,33 +2,33 @@ package ru.betterend.blocks; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.state.properties.EnumProperty; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.UpDownPlantBlock; import ru.betterend.registry.EndBlocks; public class GlowingPillarRootsBlock extends UpDownPlantBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.AMBER_MOSS); } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { return new ItemStack(EndBlocks.GLOWING_PILLAR_SEED); } } diff --git a/src/main/java/ru/betterend/blocks/GlowingPillarSeedBlock.java b/src/main/java/ru/betterend/blocks/GlowingPillarSeedBlock.java index e3c2e41d..8a239f8a 100644 --- a/src/main/java/ru/betterend/blocks/GlowingPillarSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/GlowingPillarSeedBlock.java @@ -4,15 +4,15 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -21,11 +21,15 @@ import ru.betterend.util.MHelper; public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock { public GlowingPillarSeedBlock() { - super(FabricBlockSettings.of(Material.PLANT).luminance((state) -> { - return state.getValue(AGE) * 3 + 3; - }).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true).ticksRandomly().noCollision()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .lightLevel(state -> state.getValue(AGE) * 3 + 3) + .randomTicks() + .noCollission()); } - + @Override public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { int height = MHelper.randRange(1, 2, random); @@ -33,41 +37,39 @@ public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock { if (h < height) { return; } - + MutableBlockPos mut = new MutableBlockPos().set(pos); BlockState roots = EndBlocks.GLOWING_PILLAR_ROOTS.defaultBlockState(); if (height < 2) { - BlocksHelper.setWithUpdate(world, mut, roots.with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); - mut.move(Direction.UP); - } else { - BlocksHelper.setWithUpdate(world, mut, roots.with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); - mut.move(Direction.UP); - BlocksHelper.setWithUpdate(world, mut, roots.with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); + BlocksHelper.setWithUpdate(world, mut, roots.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); mut.move(Direction.UP); } - BlocksHelper.setWithUpdate(world, mut, - EndBlocks.GLOWING_PILLAR_LUMINOPHOR.defaultBlockState().with(BlueVineLanternBlock.NATURAL, true)); - for (Direction dir : BlocksHelper.DIRECTIONS) { - pos = mut.offset(dir); - if (world.isAir(pos)) { - BlocksHelper.setWithUpdate(world, pos, - EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().with(Properties.FACING, dir)); + else { + BlocksHelper.setWithUpdate(world, mut, roots.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); + mut.move(Direction.UP); + BlocksHelper.setWithUpdate(world, mut, roots.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); + mut.move(Direction.UP); + } + BlocksHelper.setWithUpdate(world, mut, EndBlocks.GLOWING_PILLAR_LUMINOPHOR.defaultBlockState().setValue(BlueVineLanternBlock.NATURAL, true)); + for (Direction dir: BlocksHelper.DIRECTIONS) { + pos = mut.relative(dir); + if (world.isEmptyBlock(pos)) { + BlocksHelper.setWithUpdate(world, pos, EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().setValue(BlockStateProperties.FACING, dir)); } } mut.move(Direction.UP); - if (world.isAir(mut)) { - BlocksHelper.setWithUpdate(world, mut, - EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().with(Properties.FACING, Direction.UP)); + if (world.isEmptyBlock(mut)) { + BlocksHelper.setWithUpdate(world, mut, EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().setValue(BlockStateProperties.FACING, Direction.UP)); } } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.AMBER_MOSS); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/blocks/HelixTreeLeavesBlock.java b/src/main/java/ru/betterend/blocks/HelixTreeLeavesBlock.java index 02808f0a..453af173 100644 --- a/src/main/java/ru/betterend/blocks/HelixTreeLeavesBlock.java +++ b/src/main/java/ru/betterend/blocks/HelixTreeLeavesBlock.java @@ -7,22 +7,22 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.util.Mth; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.interfaces.IColorProvider; import ru.betterend.noise.OpenSimplexNoise; @@ -32,20 +32,23 @@ import ru.betterend.util.MHelper; public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider { public static final IntegerProperty COLOR = BlockProperties.COLOR; private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); - + public HelixTreeLeavesBlock() { - super(FabricBlockSettings.of(Material.LEAVES).materialColor(MaterialColor.COLOR_ORANGE) - .breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WART_BLOCK).sounds(SoundType.GRASS) + super(FabricBlockSettings.of(Material.LEAVES) + .materialColor(MaterialColor.COLOR_ORANGE) + .breakByTool(FabricToolTags.SHEARS) + .sound(SoundType.WART_BLOCK) + .sound(SoundType.GRASS) .strength(0.2F)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(COLOR); } @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { return MHelper.color(237, getGreen(state.getValue(COLOR)), 20); }; @@ -57,26 +60,25 @@ public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider { return MHelper.color(237, getGreen(4), 20); }; } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - double px = ctx.getBlockPos().getX() * 0.1; - double py = ctx.getBlockPos().getY() * 0.1; - double pz = ctx.getBlockPos().getZ() * 0.1; - return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + double px = ctx.getClickedPos().getX() * 0.1; + double py = ctx.getClickedPos().getY() * 0.1; + double pz = ctx.getClickedPos().getZ() * 0.1; + return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); } - + private int getGreen(int color) { float delta = color / 7F; return (int) Mth.lerp(delta, 80, 158); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); if (tool != null) { - if (tool.getItem().isIn(FabricToolTags.SHEARS) || tool.isCorrectToolForDrops(state) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool.getItem().is(FabricToolTags.SHEARS) || tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Collections.singletonList(new ItemStack(this)); } int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); @@ -85,7 +87,6 @@ public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider { } return Lists.newArrayList(); } - return MHelper.RANDOM.nextInt(32) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING)) - : Lists.newArrayList(); + return MHelper.RANDOM.nextInt(32) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING)) : Lists.newArrayList(); } } diff --git a/src/main/java/ru/betterend/blocks/HydraluxBlock.java b/src/main/java/ru/betterend/blocks/HydraluxBlock.java index eff201bb..17d64d4e 100644 --- a/src/main/java/ru/betterend/blocks/HydraluxBlock.java +++ b/src/main/java/ru/betterend/blocks/HydraluxBlock.java @@ -10,18 +10,18 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.blocks.BlockProperties.HydraluxShape; import ru.betterend.blocks.basis.UnderwaterPlantBlock; import ru.betterend.registry.EndBlocks; @@ -30,56 +30,60 @@ import ru.betterend.util.MHelper; public class HydraluxBlock extends UnderwaterPlantBlock { public static final EnumProperty SHAPE = BlockProperties.HYDRALUX_SHAPE; - + public HydraluxBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).breakByHand(true).luminance((state) -> { - return state.getValue(SHAPE).hasGlow() ? 15 : 0; - }).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .lightLevel((state) -> state.getValue(SHAPE).hasGlow() ? 15 : 0) + .noCollission()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); HydraluxShape shape = state.getValue(SHAPE); if (shape == HydraluxShape.FLOWER_BIG_TOP || shape == HydraluxShape.FLOWER_SMALL_TOP) { return down.is(this); - } else if (shape == HydraluxShape.ROOTS) { - return down.is(EndBlocks.SULPHURIC_ROCK.stone) && world.getBlockState(pos.up()).is(this); - } else { - return down.is(this) && world.getBlockState(pos.up()).is(this); + } + else if (shape == HydraluxShape.ROOTS) { + return down.is(EndBlocks.SULPHURIC_ROCK.stone) && world.getBlockState(pos.above()).is(this); + } + else { + return down.is(this) && world.getBlockState(pos.above()).is(this); } } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { return new ItemStack(EndBlocks.HYDRALUX_SAPLING); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { HydraluxShape shape = state.getValue(SHAPE); if (shape == HydraluxShape.FLOWER_BIG_BOTTOM || shape == HydraluxShape.FLOWER_SMALL_BOTTOM) { return Lists.newArrayList(new ItemStack(EndItems.HYDRALUX_PETAL, MHelper.randRange(1, 4, MHelper.RANDOM))); - } else if (shape == HydraluxShape.ROOTS) { - return Lists - .newArrayList(new ItemStack(EndBlocks.HYDRALUX_SAPLING, MHelper.randRange(1, 2, MHelper.RANDOM))); + } + else if (shape == HydraluxShape.ROOTS) { + return Lists.newArrayList(new ItemStack(EndBlocks.HYDRALUX_SAPLING, MHelper.randRange(1, 2, MHelper.RANDOM))); } return Collections.emptyList(); } diff --git a/src/main/java/ru/betterend/blocks/HydraluxPetalBlock.java b/src/main/java/ru/betterend/blocks/HydraluxPetalBlock.java index 7a111875..0d5ded08 100644 --- a/src/main/java/ru/betterend/blocks/HydraluxPetalBlock.java +++ b/src/main/java/ru/betterend/blocks/HydraluxPetalBlock.java @@ -2,25 +2,29 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; import ru.betterend.blocks.basis.BlockBase; public class HydraluxPetalBlock extends BlockBase { public HydraluxPetalBlock() { - this(FabricBlockSettings.of(Material.PLANT).materialColor(MaterialColor.SPRUCE).sounds(SoundType.WART_BLOCK) - .breakByTool(FabricToolTags.AXES).hardness(1).resistance(1).breakByHand(true)); + this(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.AXES) + .breakByHand(true) + .hardness(1) + .resistance(1) + .materialColor(MaterialColor.PODZOL) + .sound(SoundType.WART_BLOCK)); } - - public HydraluxPetalBlock(FabricBlockSettings settings) { + + public HydraluxPetalBlock(Properties settings) { super(settings); } - + @Override - public void onLandedUpon(Level world, BlockPos pos, Entity entity, float distance) { - } + public void fallOn(Level world, BlockPos pos, Entity entity, float distance) {} } diff --git a/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java b/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java index e8c3731f..89cb5897 100644 --- a/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java +++ b/src/main/java/ru/betterend/blocks/HydraluxPetalColoredBlock.java @@ -14,9 +14,9 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo public HydraluxPetalColoredBlock(FabricBlockSettings settings) { super(settings); } - + @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { return BlocksHelper.getBlockColor(this); }; @@ -28,19 +28,19 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo return BlocksHelper.getBlockColor(this); }; } - + @Override public String getStatesPattern(Reader data) { String path = "betterend:block/block_petal_colored"; return Patterns.createJson(data, path, path); } - + @Override public String getModelPattern(String block) { String path = "betterend:block/block_petal_colored"; return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_DIRECT; diff --git a/src/main/java/ru/betterend/blocks/HydraluxSaplingBlock.java b/src/main/java/ru/betterend/blocks/HydraluxSaplingBlock.java index 2e1171c3..9afb2681 100644 --- a/src/main/java/ru/betterend/blocks/HydraluxSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/HydraluxSaplingBlock.java @@ -1,12 +1,11 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties.HydraluxShape; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -18,32 +17,30 @@ public class HydraluxSaplingBlock extends UnderwaterPlantWithAgeBlock { public void grow(WorldGenLevel world, Random random, BlockPos pos) { int h = MHelper.randRange(4, 8, random); MutableBlockPos mut = new MutableBlockPos().set(pos); - + for (int i = 1; i < h; i++) { mut.setY(pos.getY() + i); if (!world.getBlockState(mut).is(Blocks.WATER)) { return; } } - + mut.setY(pos.getY()); BlockState state = EndBlocks.HYDRALUX.defaultBlockState(); - BlocksHelper.setWithoutUpdate(world, pos, state.with(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.ROOTS)); + BlocksHelper.setWithoutUpdate(world, pos, state.setValue(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.ROOTS)); for (int i = 1; i < h - 2; i++) { mut.setY(pos.getY() + i); - BlocksHelper.setWithoutUpdate(world, mut, state.with(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.VINE)); + BlocksHelper.setWithoutUpdate(world, mut, state.setValue(BlockProperties.HYDRALUX_SHAPE, HydraluxShape.VINE)); } - + mut.setY(mut.getY() + 1); boolean big = random.nextBoolean(); - BlocksHelper.setWithoutUpdate(world, mut, state.with(BlockProperties.HYDRALUX_SHAPE, - big ? HydraluxShape.FLOWER_BIG_BOTTOM : HydraluxShape.FLOWER_SMALL_BOTTOM)); - + BlocksHelper.setWithoutUpdate(world, mut, state.setValue(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_BOTTOM : HydraluxShape.FLOWER_SMALL_BOTTOM)); + mut.setY(mut.getY() + 1); - BlocksHelper.setWithoutUpdate(world, mut, state.with(BlockProperties.HYDRALUX_SHAPE, - big ? HydraluxShape.FLOWER_BIG_TOP : HydraluxShape.FLOWER_SMALL_TOP)); + BlocksHelper.setWithoutUpdate(world, mut, state.setValue(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_TOP : HydraluxShape.FLOWER_SMALL_TOP)); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.SULPHURIC_ROCK.stone); diff --git a/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java b/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java index 917db1b1..e8b39590 100644 --- a/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java +++ b/src/main/java/ru/betterend/blocks/HydrothermalVentBlock.java @@ -8,125 +8,124 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockEntityProvider; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.blocks.entities.BlockEntityHydrothermalVent; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndParticles; import ru.betterend.util.BlocksHelper; -public class HydrothermalVentBlock extends BlockBaseNotFull - implements BlockEntityProvider, FluidFillable, Waterloggable { - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; +public class HydrothermalVentBlock extends BlockBaseNotFull implements EntityBlock, LiquidBlockContainer, SimpleWaterloggedBlock { + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; - private static final VoxelShape SHAPE = Block.createCuboidShape(1, 1, 1, 15, 16, 15); - + private static final VoxelShape SHAPE = Block.box(1, 1, 1, 15, 16, 15); + public HydrothermalVentBlock() { - super(FabricBlockSettings.of(Material.STONE).breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.STONE) - .noCollision().requiresTool()); - this.setDefaultState(getDefaultState().with(WATERLOGGED, true).with(ACTIVATED, false)); + super(FabricBlockSettings.of(Material.STONE) + .breakByTool(FabricToolTags.PICKAXES) + .sound(SoundType.STONE) + .noCollission() + .requiresCorrectToolForDrops()); + this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, true).setValue(ACTIVATED, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(WATERLOGGED, ACTIVATED); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { state = world.getBlockState(pos.below()); return state.is(EndBlocks.SULPHURIC_ROCK.stone); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.WATER.defaultBlockState(); - } else if (state.getValue(WATERLOGGED) && facing == Direction.UP && neighborState.is(Blocks.WATER)) { - world.getBlockTickScheduler().schedule(pos, this, 20); + } + else if (state.getValue(WATERLOGGED) && facing == Direction.UP && neighborState.is(Blocks.WATER)) { + world.getBlockTicks().scheduleTick(pos, this, 20); } return state; } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { LevelAccessor worldAccess = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - return this.defaultBlockState().with(WATERLOGGED, - worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER); + BlockPos blockPos = ctx.getClickedPos(); + return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER); } - + @Override public FluidState getFluidState(BlockState state) { - return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new BlockEntityHydrothermalVent(); } @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - BlockPos up = pos.up(); + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + BlockPos up = pos.above(); if (world.getBlockState(up).is(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, up, EndBlocks.VENT_BUBBLE_COLUMN); - world.getBlockTickScheduler().schedule(up, EndBlocks.VENT_BUBBLE_COLUMN, 5); + world.getBlockTicks().scheduleTick(up, EndBlocks.VENT_BUBBLE_COLUMN, 5); } } - + @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, - ItemStack itemStack) { - if (world instanceof ServerLevel && state.getValue(WATERLOGGED) - && world.getBlockState(pos.up()).is(Blocks.WATER)) { - scheduledTick(state, (ServerLevel) world, pos, world.random); + public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { + if (world instanceof ServerLevel && state.getValue(WATERLOGGED) && world.getBlockState(pos.above()).is(Blocks.WATER)) { + tick(state,(ServerLevel) world, pos, world.random); } } - + @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { if (!state.getValue(ACTIVATED) && random.nextBoolean()) { @@ -136,7 +135,8 @@ public class HydrothermalVentBlock extends BlockBaseNotFull double z = pos.getZ() + random.nextDouble(); if (state.getValue(WATERLOGGED)) { world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); - } else { + } + else { world.addParticle(ParticleTypes.SMOKE, x, y, z, 0, 0, 0); } } diff --git a/src/main/java/ru/betterend/blocks/InfusionPedestal.java b/src/main/java/ru/betterend/blocks/InfusionPedestal.java index 081cc4aa..2cfd9506 100644 --- a/src/main/java/ru/betterend/blocks/InfusionPedestal.java +++ b/src/main/java/ru/betterend/blocks/InfusionPedestal.java @@ -1,15 +1,15 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.rituals.InfusionRitual; @@ -22,7 +22,7 @@ public class InfusionPedestal extends PedestalBlock { super(Blocks.OBSIDIAN); this.height = 1.08F; } - + @Override public void checkRitual(Level world, BlockPos pos) { BlockEntity blockEntity = world.getBlockEntity(pos); @@ -37,41 +37,41 @@ public class InfusionPedestal extends PedestalBlock { } } } - + @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new InfusionPedestalEntity(); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { if (state.is(this)) { - switch (state.getValue(STATE)) { - case PEDESTAL_TOP: { - return SHAPE_PEDESTAL_TOP; - } - case DEFAULT: { - return SHAPE_DEFAULT; - } - default: { - return super.getOutlineShape(state, world, pos, context); - } + switch(state.getValue(STATE)) { + case PEDESTAL_TOP: { + return SHAPE_PEDESTAL_TOP; + } + case DEFAULT: { + return SHAPE_DEFAULT; + } + default: { + return super.getShape(state, world, pos, context); + } } } - return super.getOutlineShape(state, world, pos, context); + return super.getShape(state, world, pos, context); } - + static { - VoxelShape basinUp = Block.createCuboidShape(2, 3, 2, 14, 4, 14); - VoxelShape basinDown = Block.createCuboidShape(0, 0, 0, 16, 3, 16); - VoxelShape pedestalTop = Block.createCuboidShape(1, 9, 1, 15, 11, 15); - VoxelShape pedestalDefault = Block.createCuboidShape(1, 13, 1, 15, 15, 15); - VoxelShape pillar = Block.createCuboidShape(3, 0, 3, 13, 9, 13); - VoxelShape pillarDefault = Block.createCuboidShape(3, 4, 3, 13, 13, 13); - VoxelShape eyeDefault = Block.createCuboidShape(4, 15, 4, 12, 16, 12); - VoxelShape eyeTop = Block.createCuboidShape(4, 11, 4, 12, 12, 12); - VoxelShape basin = VoxelShapes.union(basinDown, basinUp); - SHAPE_DEFAULT = VoxelShapes.union(basin, pillarDefault, pedestalDefault, eyeDefault); - SHAPE_PEDESTAL_TOP = VoxelShapes.union(pillar, pedestalTop, eyeTop); + VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14); + VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16); + VoxelShape pedestalTop = Block.box(1, 9, 1, 15, 11, 15); + VoxelShape pedestalDefault = Block.box(1, 13, 1, 15, 15, 15); + VoxelShape pillar = Block.box(3, 0, 3, 13, 9, 13); + VoxelShape pillarDefault = Block.box(3, 4, 3, 13, 13, 13); + VoxelShape eyeDefault = Block.box(4, 15, 4, 12, 16, 12); + VoxelShape eyeTop = Block.box(4, 11, 4, 12, 12, 12); + VoxelShape basin = Shapes.or(basinDown, basinUp); + SHAPE_DEFAULT = Shapes.or(basin, pillarDefault, pedestalDefault, eyeDefault); + SHAPE_PEDESTAL_TOP = Shapes.or(pillar, pedestalTop, eyeTop); } } diff --git a/src/main/java/ru/betterend/blocks/JellyshroomCapBlock.java b/src/main/java/ru/betterend/blocks/JellyshroomCapBlock.java index 411f0598..3e105494 100644 --- a/src/main/java/ru/betterend/blocks/JellyshroomCapBlock.java +++ b/src/main/java/ru/betterend/blocks/JellyshroomCapBlock.java @@ -6,21 +6,21 @@ import java.util.List; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SlimeBlock; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.core.Registry; +import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.core.Vec3i; -import net.minecraft.core.Registry; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SlimeBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IRenderTypeable; @@ -35,55 +35,55 @@ public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable, private final Vec3i colorStart; private final Vec3i colorEnd; private final int coloritem; - + public JellyshroomCapBlock(int r1, int g1, int b1, int r2, int g2, int b2) { super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK)); colorStart = new Vec3i(r1, g1, b1); colorEnd = new Vec3i(r2, g2, b2); coloritem = MHelper.color((r1 + r2) >> 1, (g1 + g2) >> 1, (b1 + b2) >> 1); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - double px = ctx.getBlockPos().getX() * 0.1; - double py = ctx.getBlockPos().getY() * 0.1; - double pz = ctx.getBlockPos().getZ() * 0.1; - return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + double px = ctx.getClickedPos().getX() * 0.1; + double py = ctx.getClickedPos().getY() * 0.1; + double pz = ctx.getClickedPos().getZ() * 0.1; + return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(COLOR); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Lists.newArrayList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap"); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; } - + @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { float delta = (float) state.getValue(COLOR) / 7F; int r = Mth.floor(Mth.lerp(delta, colorStart.getX() / 255F, colorEnd.getX() / 255F) * 255F); diff --git a/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java b/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java index 403485c1..72063a4c 100644 --- a/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/LacugroveSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.registry.EndBlocks; @@ -17,10 +17,9 @@ public class LacugroveSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.LACUGROVE.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) - || world.getBlockState(pos.below()).is(EndBlocks.ENDSTONE_DUST); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.ENDSTONE_DUST); } } diff --git a/src/main/java/ru/betterend/blocks/LanceleafBlock.java b/src/main/java/ru/betterend/blocks/LanceleafBlock.java index ed5294b3..c6378032 100644 --- a/src/main/java/ru/betterend/blocks/LanceleafBlock.java +++ b/src/main/java/ru/betterend/blocks/LanceleafBlock.java @@ -2,19 +2,18 @@ package ru.betterend.blocks; import java.util.Collections; import java.util.List; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.blocks.BlockProperties.PentaShape; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; @@ -23,44 +22,45 @@ import ru.betterend.util.MHelper; public class LanceleafBlock extends EndPlantBlock { public static final EnumProperty SHAPE = BlockProperties.PENTA_SHAPE; public static final IntegerProperty ROTATION = BlockProperties.ROTATION; - + public LanceleafBlock() { super(); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE, ROTATION); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { PentaShape shape = state.getValue(SHAPE); if (shape == PentaShape.TOP) { return world.getBlockState(pos.below()).is(this); - } else if (shape == PentaShape.BOTTOM) { - return world.getBlockState(pos.below()).is(EndBlocks.AMBER_MOSS) && world.getBlockState(pos.up()).is(this); - } else { - return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.up()).is(this); + } + else if (shape == PentaShape.BOTTOM) { + return world.getBlockState(pos.below()).is(EndBlocks.AMBER_MOSS) && world.getBlockState(pos.above()).is(this); + } + else { + return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.above()).is(this); } } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(SHAPE) == PentaShape.BOTTOM) { return Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED)); } - return MHelper.RANDOM.nextBoolean() ? Collections.emptyList() - : Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED)); + return MHelper.RANDOM.nextBoolean() ? Collections.emptyList() : Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED)); } } diff --git a/src/main/java/ru/betterend/blocks/LanceleafSeedBlock.java b/src/main/java/ru/betterend/blocks/LanceleafSeedBlock.java index 4cf6142f..3f631b57 100644 --- a/src/main/java/ru/betterend/blocks/LanceleafSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/LanceleafSeedBlock.java @@ -1,13 +1,12 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties.PentaShape; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; @@ -24,27 +23,23 @@ public class LanceleafSeedBlock extends EndPlantWithAgeBlock { } int rotation = random.nextInt(4); MutableBlockPos mut = new MutableBlockPos().set(pos); - BlockState plant = EndBlocks.LANCELEAF.defaultBlockState().with(BlockProperties.ROTATION, rotation); - BlocksHelper.setWithoutUpdate(world, mut, plant.with(BlockProperties.PENTA_SHAPE, PentaShape.BOTTOM)); - BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), - plant.with(BlockProperties.PENTA_SHAPE, PentaShape.PRE_BOTTOM)); + BlockState plant = EndBlocks.LANCELEAF.defaultBlockState().setValue(BlockProperties.ROTATION, rotation); + BlocksHelper.setWithoutUpdate(world, mut, plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.BOTTOM)); + BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.PRE_BOTTOM)); for (int i = 2; i < height - 2; i++) { - BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), - plant.with(BlockProperties.PENTA_SHAPE, PentaShape.MIDDLE)); + BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.MIDDLE)); } - BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), - plant.with(BlockProperties.PENTA_SHAPE, PentaShape.PRE_TOP)); - BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), - plant.with(BlockProperties.PENTA_SHAPE, PentaShape.TOP)); + BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.PRE_TOP)); + BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.TOP)); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.AMBER_MOSS); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/blocks/LargeAmaranitaBlock.java b/src/main/java/ru/betterend/blocks/LargeAmaranitaBlock.java index fac9f8d2..befeb7c9 100644 --- a/src/main/java/ru/betterend/blocks/LargeAmaranitaBlock.java +++ b/src/main/java/ru/betterend/blocks/LargeAmaranitaBlock.java @@ -4,75 +4,77 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; public class LargeAmaranitaBlock extends EndPlantBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(4, 0, 4, 12, 14, 12); - private static final VoxelShape SHAPE_TOP = VoxelShapes.union(Block.createCuboidShape(1, 3, 1, 15, 16, 15), - SHAPE_BOTTOM); - + private static final VoxelShape SHAPE_BOTTOM = Block.box(4, 0, 4, 12, 14, 12); + private static final VoxelShape SHAPE_TOP = Shapes.or(Block.box(1, 3, 1, 15, 16, 15), SHAPE_BOTTOM); + public LargeAmaranitaBlock() { super(FabricBlockSettings.of(Material.PLANT) - .luminance((state) -> (state.getValue(SHAPE) == TripleShape.TOP) ? 15 : 0) - .breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true)); + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .lightLevel((state) -> (state.getValue(SHAPE) == TripleShape.TOP) ? 15 : 0)); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(SHAPE) == TripleShape.TOP ? SHAPE_TOP : SHAPE_BOTTOM; } - + @Override protected boolean isTerrain(BlockState state) { - return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) - || state.is(EndBlocks.MOSSY_DRAGON_BONE); + return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) || state.is(EndBlocks.MOSSY_DRAGON_BONE); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.BOTTOM) { - return isTerrain(world.getBlockState(pos.below())) && world.getBlockState(pos.up()).is(this); - } else if (shape == TripleShape.TOP) { + return isTerrain(world.getBlockState(pos.below())) && world.getBlockState(pos.above()).is(this); + } + else if (shape == TripleShape.TOP) { return world.getBlockState(pos.below()).is(this); - } else { - return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.up()).is(this); + } + else { + return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.above()).is(this); } } - + @Override public OffsetType getOffsetType() { return OffsetType.NONE; } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/LumecornBlock.java b/src/main/java/ru/betterend/blocks/LumecornBlock.java index a1ccdd25..9f782340 100644 --- a/src/main/java/ru/betterend/blocks/LumecornBlock.java +++ b/src/main/java/ru/betterend/blocks/LumecornBlock.java @@ -7,21 +7,21 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.LumecornShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; @@ -32,17 +32,19 @@ import ru.betterend.registry.EndTags; import ru.betterend.util.MHelper; public class LumecornBlock extends BlockBaseNotFull implements IRenderTypeable { - public static final EnumProperty SHAPE = EnumProperty.of("shape", LumecornShape.class); - private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(6, 0, 6, 10, 16, 10); - private static final VoxelShape SHAPE_TOP = Block.createCuboidShape(6, 0, 6, 10, 8, 10); - + public static final EnumProperty SHAPE = EnumProperty.create("shape", LumecornShape.class); + private static final VoxelShape SHAPE_BOTTOM = Block.box(6, 0, 6, 10, 16, 10); + private static final VoxelShape SHAPE_TOP = Block.box(6, 0, 6, 10, 8, 10); + public LumecornBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).hardness(0.5F) - .luminance((state) -> { - return state.getValue(SHAPE).getLight(); - })); + super(FabricBlockSettings.of(Material.WOOD) + .breakByTool(FabricToolTags.AXES) + .hardness(0.5F) + .lightLevel((state) -> { + return state.getValue(SHAPE).getLight(); + })); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); @@ -52,48 +54,48 @@ public class LumecornBlock extends BlockBaseNotFull implements IRenderTypeable { public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(SHAPE) == LumecornShape.LIGHT_TOP ? SHAPE_TOP : SHAPE_BOTTOM; } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { LumecornShape shape = state.getValue(SHAPE); if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL) { - return world.getBlockState(pos.below()).isIn(EndTags.END_GROUND); - } else if (shape == LumecornShape.LIGHT_TOP) { + return world.getBlockState(pos.below()).is(EndTags.END_GROUND); + } + else if (shape == LumecornShape.LIGHT_TOP) { return world.getBlockState(pos.below()).is(this); - } else { - return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.up()).is(this); + } + else { + return world.getBlockState(pos.below()).is(this) && world.getBlockState(pos.above()).is(this); } } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { LumecornShape shape = state.getValue(SHAPE); if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) { - return Collections - .singletonList(new ItemStack(EndBlocks.LUMECORN_SEED, MHelper.randRange(1, 2, MHelper.RANDOM))); + return Collections.singletonList(new ItemStack(EndBlocks.LUMECORN_SEED, MHelper.randRange(1, 2, MHelper.RANDOM))); } - return MHelper.RANDOM.nextBoolean() ? Collections.singletonList(new ItemStack(EndItems.LUMECORN_ROD)) - : Collections.emptyList(); + return MHelper.RANDOM.nextBoolean() ? Collections.singletonList(new ItemStack(EndItems.LUMECORN_ROD)) : Collections.emptyList(); } - + @Override @Environment(EnvType.CLIENT) - public ItemStack getPickStack(BlockView world, BlockPos pos, BlockState state) { + public ItemStack getCloneItemStack(BlockGetter world, BlockPos pos, BlockState state) { LumecornShape shape = state.getValue(SHAPE); if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) { return new ItemStack(EndBlocks.LUMECORN_SEED); diff --git a/src/main/java/ru/betterend/blocks/LumecornSeedBlock.java b/src/main/java/ru/betterend/blocks/LumecornSeedBlock.java index 9046228d..c3e6a14c 100644 --- a/src/main/java/ru/betterend/blocks/LumecornSeedBlock.java +++ b/src/main/java/ru/betterend/blocks/LumecornSeedBlock.java @@ -1,11 +1,10 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; @@ -15,14 +14,14 @@ public class LumecornSeedBlock extends EndPlantWithAgeBlock { public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { EndFeatures.LUMECORN.getFeature().place(world, null, random, pos, null); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/blocks/MengerSpongeBlock.java b/src/main/java/ru/betterend/blocks/MengerSpongeBlock.java index 5454173d..b2958584 100644 --- a/src/main/java/ru/betterend/blocks/MengerSpongeBlock.java +++ b/src/main/java/ru/betterend/blocks/MengerSpongeBlock.java @@ -5,20 +5,20 @@ import java.util.Queue; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FluidBlock; -import net.minecraft.world.level.block.FluidDrainable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.tags.FluidTags; -import net.minecraft.util.Pair; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.Tuple; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -26,19 +26,18 @@ import ru.betterend.registry.EndBlocks; public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeable { public MengerSpongeBlock() { - super(FabricBlockSettings.copyOf(Blocks.SPONGE).nonOpaque()); + super(FabricBlockSettings.copyOf(Blocks.SPONGE).noOcclusion()); } - + @Override - public void onBlockAdded(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { + public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { if (absorbWater(world, pos)) { world.setBlockAndUpdate(pos, EndBlocks.MENGER_SPONGE_WET.defaultBlockState()); } } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (absorbWater(world, pos)) { return EndBlocks.MENGER_SPONGE_WET.defaultBlockState(); } @@ -46,46 +45,44 @@ public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeab } private boolean absorbWater(LevelAccessor world, BlockPos pos) { - Queue> queue = Lists.newLinkedList(); - queue.add(new Pair(pos, 0)); + Queue> queue = Lists.newLinkedList(); + queue.add(new Tuple(pos, 0)); int i = 0; while (!queue.isEmpty()) { - Pair pair = queue.poll(); - BlockPos blockPos = (BlockPos) pair.getLeft(); - int j = (Integer) pair.getRight(); + Tuple pair = queue.poll(); + BlockPos blockPos = (BlockPos) pair.getA(); + int j = (Integer) pair.getB(); Direction[] var8 = Direction.values(); int var9 = var8.length; for (int var10 = 0; var10 < var9; ++var10) { Direction direction = var8[var10]; - BlockPos blockPos2 = blockPos.offset(direction); + BlockPos blockPos2 = blockPos.relative(direction); BlockState blockState = world.getBlockState(blockPos2); FluidState fluidState = world.getFluidState(blockPos2); Material material = blockState.getMaterial(); - if (fluidState.isIn(FluidTags.WATER)) { - if (blockState.getBlock() instanceof FluidDrainable && ((FluidDrainable) blockState.getBlock()) - .tryDrainFluid(world, blockPos2, blockState) != Fluids.EMPTY) { + if (fluidState.is(FluidTags.WATER)) { + if (blockState.getBlock() instanceof BucketPickup && ((BucketPickup) blockState.getBlock()).takeLiquid(world, blockPos2, blockState) != Fluids.EMPTY) { ++i; if (j < 6) { - queue.add(new Pair(blockPos2, j + 1)); + queue.add(new Tuple(blockPos2, j + 1)); } - } else if (blockState.getBlock() instanceof FluidBlock) { - world.setBlockAndUpdate(blockPos2, Blocks.AIR.defaultBlockState(), 3); + } + else if (blockState.getBlock() instanceof LiquidBlock) { + world.setBlock(blockPos2, Blocks.AIR.defaultBlockState(), 3); ++i; if (j < 6) { - queue.add(new Pair(blockPos2, j + 1)); + queue.add(new Tuple(blockPos2, j + 1)); } - } else if (material == Material.UNDERWATER_PLANT - || material == Material.REPLACEABLE_UNDERWATER_PLANT) { - BlockEntity blockEntity = blockState.getBlock().hasBlockEntity() - ? world.getBlockEntity(blockPos2) - : null; - dropStacks(blockState, world, blockPos2, blockEntity); - world.setBlockAndUpdate(blockPos2, Blocks.AIR.defaultBlockState(), 3); + } + else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) { + BlockEntity blockEntity = blockState.getBlock().isEntityBlock() ? world.getBlockEntity(blockPos2) : null; + dropResources(blockState, world, blockPos2, blockEntity); + world.setBlock(blockPos2, Blocks.AIR.defaultBlockState(), 3); ++i; if (j < 6) { - queue.add(new Pair(blockPos2, j + 1)); + queue.add(new Tuple(blockPos2, j + 1)); } } } @@ -98,7 +95,7 @@ public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeab return i > 0; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; diff --git a/src/main/java/ru/betterend/blocks/MengerSpongeWetBlock.java b/src/main/java/ru/betterend/blocks/MengerSpongeWetBlock.java index 4cab2fbc..90d219eb 100644 --- a/src/main/java/ru/betterend/blocks/MengerSpongeWetBlock.java +++ b/src/main/java/ru/betterend/blocks/MengerSpongeWetBlock.java @@ -5,20 +5,20 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemStack; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.GameRules; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -27,27 +27,26 @@ import ru.betterend.util.BlocksHelper; public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTypeable { public MengerSpongeWetBlock() { - super(FabricBlockSettings.copyOf(Blocks.WET_SPONGE).nonOpaque()); + super(FabricBlockSettings.copyOf(Blocks.WET_SPONGE).noOcclusion()); } @Override - public void onBlockAdded(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { - if (world.getDimension().isUltrawarm()) { - world.setBlockAndUpdate(pos, EndBlocks.MENGER_SPONGE.defaultBlockState(), 3); - world.syncWorldEvent(2009, pos, 0); - world.playLocalSound((Player) null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundSource.BLOCKS, 1.0F, - (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F); + public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { + if (world.dimensionType().ultraWarm()) { + world.setBlock(pos, EndBlocks.MENGER_SPONGE.defaultBlockState(), 3); + world.levelEvent(2009, pos, 0); + world.playSound((Player) null, pos, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 1.0F, (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F); } } @Override @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { - Direction direction = Direction.random(random); + Direction direction = Direction.getRandom(random); if (direction != Direction.UP) { BlockPos blockPos = pos.relative(direction); BlockState blockState = world.getBlockState(blockPos); - if (!state.isOpaque() || !blockState.isSideSolidFullSquare(world, blockPos, direction.getOpposite())) { + if (!state.canOcclude() || !blockState.isFaceSturdy(world, blockPos, direction.getOpposite())) { double x = (double) pos.getX(); double y = (double) pos.getY(); double z = (double) pos.getZ(); @@ -55,20 +54,24 @@ public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTyp y -= 0.05; x += random.nextDouble(); z += random.nextDouble(); - } else { + } + else { y += random.nextDouble() * 0.8; if (direction.getAxis() == Direction.Axis.X) { z += random.nextDouble(); if (direction == Direction.EAST) { ++x; - } else { + } + else { x += 0.05; } - } else { + } + else { x += random.nextDouble(); if (direction == Direction.SOUTH) { ++z; - } else { + } + else { z += 0.05; } } @@ -80,25 +83,24 @@ public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTyp } @Override - public void onBreak(Level world, BlockPos pos, BlockState state, Player player) { + public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) { BlocksHelper.setWithUpdate(world, pos, Blocks.AIR); if (!world.isClientSide()) { - world.syncWorldEvent(2001, pos, getRawIdFromState(state)); + world.levelEvent(2001, pos, getId(state)); } - if (world.getGameRules().getBoolean(GameRules.DO_TILE_DROPS) && (player == null || !player.isCreative())) { - ItemEntity drop = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(this)); - world.spawnEntity(drop); + if (world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && (player == null || !player.isCreative())) { + ItemEntity drop = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); + world.addFreshEntity(drop); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public FluidState getFluidState(BlockState state) { - return Fluids.WATER.getStill(false); + return Fluids.WATER.getSource(false); } } diff --git a/src/main/java/ru/betterend/blocks/MossyDragonBoneBlock.java b/src/main/java/ru/betterend/blocks/MossyDragonBoneBlock.java index fe928885..662481cc 100644 --- a/src/main/java/ru/betterend/blocks/MossyDragonBoneBlock.java +++ b/src/main/java/ru/betterend/blocks/MossyDragonBoneBlock.java @@ -5,27 +5,27 @@ import java.util.List; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SnowBlock; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.WorldView; -import net.minecraft.world.chunk.light.ChunkLightProvider; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SnowLayerBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.LayerLightEngine; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.betterend.blocks.basis.EndPillarBlock; import ru.betterend.registry.EndBlocks; public class MossyDragonBoneBlock extends EndPillarBlock { public MossyDragonBoneBlock() { - super(FabricBlockSettings.copyOf(Blocks.BONE_BLOCK).hardness(0.5F).ticksRandomly()); + super(FabricBlockSettings.copyOf(Blocks.BONE_BLOCK).hardness(0.5F).randomTicks()); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -34,25 +34,25 @@ public class MossyDragonBoneBlock extends EndPillarBlock { } return Collections.singletonList(new ItemStack(EndBlocks.DRAGON_BONE_BLOCK)); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { - world.setBlockAndUpdate(pos, Blocks.BONE_BLOCK.defaultBlockState().with(AXIS, state.getValue(AXIS))); + world.setBlockAndUpdate(pos, Blocks.BONE_BLOCK.defaultBlockState().setValue(AXIS, state.getValue(AXIS))); } } - public static boolean canSurvive(BlockState state, WorldView worldView, BlockPos pos) { - BlockPos blockPos = pos.up(); - BlockState blockState = worldView.getBlockState(blockPos); - if (blockState.is(Blocks.SNOW) && (Integer) blockState.get(SnowBlock.LAYERS) == 1) { - return true; - } else if (blockState.getFluidState().getLevel() == 8) { - return false; - } else { - int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, - blockState.getOpacity(worldView, blockPos)); - return i < 5; - } - } + @Override + public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) { + BlockPos blockPos = pos.above(); + BlockState blockState = worldView.getBlockState(blockPos); + if (blockState.is(Blocks.SNOW) && blockState.getValue(SnowLayerBlock.LAYERS) == 1) { + return true; + } else if (blockState.getFluidState().getAmount() == 8) { + return false; + } else { + int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos)); + return i < 5; + } + } } diff --git a/src/main/java/ru/betterend/blocks/MossyGlowshroomCapBlock.java b/src/main/java/ru/betterend/blocks/MossyGlowshroomCapBlock.java index bec58eb8..8ba518da 100644 --- a/src/main/java/ru/betterend/blocks/MossyGlowshroomCapBlock.java +++ b/src/main/java/ru/betterend/blocks/MossyGlowshroomCapBlock.java @@ -2,27 +2,26 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.item.ItemPlacementContext; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; public class MossyGlowshroomCapBlock extends BlockBase { public static final BooleanProperty TRANSITION = BlockProperties.TRANSITION; - + public MossyGlowshroomCapBlock() { - super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WOOD)); - this.setDefaultState(this.stateManager.defaultBlockState().with(TRANSITION, false)); + super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sound(SoundType.WOOD)); + this.registerDefaultState(this.stateDefinition.any().setValue(TRANSITION, false)); } - - public BlockState getPlacementState(ItemPlacementContext ctx) { - return this.defaultBlockState().with(TRANSITION, - EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(ctx.getLevel().getBlockState(ctx.getBlockPos().below()))); + + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + return this.defaultBlockState().setValue(TRANSITION, EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(ctx.getLevel().getBlockState(ctx.getClickedPos().below()))); } protected void createBlockStateDefinition(StateDefinition.Builder builder) { diff --git a/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java b/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java index 3359b6be..3781d6ba 100644 --- a/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/MossyGlowshroomSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.registry.EndBlocks; @@ -17,10 +17,9 @@ public class MossyGlowshroomSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.MOSSY_GLOWSHROOM.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) - || world.getBlockState(pos.below()).is(EndBlocks.END_MYCELIUM); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.END_MYCELIUM); } } diff --git a/src/main/java/ru/betterend/blocks/MossyObsidian.java b/src/main/java/ru/betterend/blocks/MossyObsidian.java index ecb15503..4d2e3a12 100644 --- a/src/main/java/ru/betterend/blocks/MossyObsidian.java +++ b/src/main/java/ru/betterend/blocks/MossyObsidian.java @@ -5,26 +5,26 @@ import java.util.List; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SnowBlock; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.WorldView; -import net.minecraft.world.chunk.light.ChunkLightProvider; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SnowLayerBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.LayerLightEngine; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.betterend.blocks.basis.BlockBase; public class MossyObsidian extends BlockBase { public MossyObsidian() { - super(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).hardness(3).ticksRandomly()); + super(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).hardness(3).randomTicks()); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -33,25 +33,24 @@ public class MossyObsidian extends BlockBase { } return Collections.singletonList(new ItemStack(Blocks.OBSIDIAN)); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { world.setBlockAndUpdate(pos, Blocks.OBSIDIAN.defaultBlockState()); } } - - public static boolean canSurvive(BlockState state, WorldView worldView, BlockPos pos) { - BlockPos blockPos = pos.up(); - BlockState blockState = worldView.getBlockState(blockPos); - if (blockState.is(Blocks.SNOW) && (Integer) blockState.get(SnowBlock.LAYERS) == 1) { - return true; - } else if (blockState.getFluidState().getLevel() == 8) { - return false; - } else { - int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, - blockState.getOpacity(worldView, blockPos)); - return i < 5; - } - } + + public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) { + BlockPos blockPos = pos.above(); + BlockState blockState = worldView.getBlockState(blockPos); + if (blockState.is(Blocks.SNOW) && (Integer)blockState.getValue(SnowLayerBlock.LAYERS) == 1) { + return true; + } else if (blockState.getFluidState().getAmount() == 8) { + return false; + } else { + int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos)); + return i < 5; + } + } } diff --git a/src/main/java/ru/betterend/blocks/MurkweedBlock.java b/src/main/java/ru/betterend/blocks/MurkweedBlock.java index 893fc86d..cd7ec961 100644 --- a/src/main/java/ru/betterend/blocks/MurkweedBlock.java +++ b/src/main/java/ru/betterend/blocks/MurkweedBlock.java @@ -4,16 +4,16 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.pathing.NavigationType; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.pathfinder.PathComputationType; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; @@ -27,21 +27,21 @@ public class MurkweedBlock extends EndPlantBlock { double v = random.nextDouble() * 0.1; world.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, v, v, v); } - + @Override public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - if (entity instanceof LivingEntity && !((LivingEntity) entity).hasMobEffect(MobEffects.BLINDNESS)) { - ((LivingEntity) entity).addMobEffect(new MobEffectInstance(MobEffects.BLINDNESS, 50)); + if (entity instanceof LivingEntity && !((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS)) { + ((LivingEntity) entity).addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 50)); } } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.SHADOW_GRASS); } - + @Override - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType type) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/NeedlegrassBlock.java b/src/main/java/ru/betterend/blocks/NeedlegrassBlock.java index 1b5f83dd..00abb588 100644 --- a/src/main/java/ru/betterend/blocks/NeedlegrassBlock.java +++ b/src/main/java/ru/betterend/blocks/NeedlegrassBlock.java @@ -5,20 +5,20 @@ import java.util.List; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.core.BlockPos; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.pathing.NavigationType; -import net.minecraft.world.entity.damage.DamageSource; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.core.BlockPos; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.util.MHelper; @@ -27,28 +27,28 @@ public class NeedlegrassBlock extends EndPlantBlock { @Override public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { if (entity instanceof LivingEntity) { - entity.damage(DamageSource.CACTUS, 0.1F); + entity.hurt(DamageSource.CACTUS, 0.1F); } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM))); } } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.SHADOW_GRASS); } @Override - public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { + public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType type) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/NeonCactusBlock.java b/src/main/java/ru/betterend/blocks/NeonCactusBlock.java index f0a95711..58fc1ac1 100644 --- a/src/main/java/ru/betterend/blocks/NeonCactusBlock.java +++ b/src/main/java/ru/betterend/blocks/NeonCactusBlock.java @@ -5,137 +5,134 @@ import java.util.EnumMap; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.util.BlocksHelper; -public class NeonCactusBlock extends BlockBaseNotFull implements Waterloggable, IRenderTypeable { +public class NeonCactusBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, IRenderTypeable { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - public static final DirectionProperty FACING = Properties.FACING; - + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static final DirectionProperty FACING = BlockStateProperties.FACING; + private static final EnumMap MEDIUM_SHAPES_OPEN = Maps.newEnumMap(Direction.class); private static final EnumMap SMALL_SHAPES_OPEN = Maps.newEnumMap(Direction.class); private static final EnumMap MEDIUM_SHAPES = Maps.newEnumMap(Axis.class); private static final EnumMap SMALL_SHAPES = Maps.newEnumMap(Axis.class); - + public NeonCactusBlock() { - super(FabricBlockSettings.copyOf(Blocks.CACTUS).luminance(state -> { + super(FabricBlockSettings.copyOf(Blocks.CACTUS).lightLevel(state -> { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.TOP) { return 15; } return shape == TripleShape.MIDDLE ? 13 : 10; })); - setDefaultState( - getDefaultState().with(WATERLOGGED, false).with(FACING, Direction.UP).with(SHAPE, TripleShape.TOP)); + registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false).setValue(FACING, Direction.UP).setValue(SHAPE, TripleShape.TOP)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE, WATERLOGGED, FACING); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { LevelAccessor worldAccess = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - return this.defaultBlockState() - .with(WATERLOGGED, worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER) - .with(FACING, ctx.getSide()); + BlockPos blockPos = ctx.getClickedPos(); + return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER).setValue(FACING, ctx.getClickedFace()); } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } - + @Override public FluidState getFluidState(BlockState state) { - return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } - + @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { if ((Boolean) state.getValue(WATERLOGGED)) { - world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return state; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { TripleShape shape = state.getValue(SHAPE); - + if (shape == TripleShape.BOTTOM) { - return VoxelShapes.fullCube(); + return Shapes.block(); } Direction dir = state.getValue(FACING); BlockState next = view.getBlockState(pos.relative(dir)); if (next.is(this)) { Axis axis = dir.getAxis(); return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES.get(axis) : SMALL_SHAPES.get(axis); - } else { + } + else { return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES_OPEN.get(dir) : SMALL_SHAPES_OPEN.get(dir); } } - + static { - MEDIUM_SHAPES.put(Axis.X, Block.createCuboidShape(0, 2, 2, 16, 14, 14)); - MEDIUM_SHAPES.put(Axis.Y, Block.createCuboidShape(2, 0, 2, 14, 16, 14)); - MEDIUM_SHAPES.put(Axis.Z, Block.createCuboidShape(2, 2, 0, 14, 14, 16)); - - SMALL_SHAPES.put(Axis.X, Block.createCuboidShape(0, 4, 4, 16, 12, 12)); - SMALL_SHAPES.put(Axis.Y, Block.createCuboidShape(4, 0, 4, 12, 16, 12)); - SMALL_SHAPES.put(Axis.Z, Block.createCuboidShape(4, 4, 0, 12, 12, 16)); - - MEDIUM_SHAPES_OPEN.put(Direction.UP, Block.createCuboidShape(2, 0, 2, 14, 14, 14)); - MEDIUM_SHAPES_OPEN.put(Direction.DOWN, Block.createCuboidShape(2, 2, 2, 14, 16, 14)); - MEDIUM_SHAPES_OPEN.put(Direction.NORTH, Block.createCuboidShape(2, 2, 2, 14, 14, 16)); - MEDIUM_SHAPES_OPEN.put(Direction.SOUTH, Block.createCuboidShape(2, 2, 0, 14, 14, 14)); - MEDIUM_SHAPES_OPEN.put(Direction.WEST, Block.createCuboidShape(2, 2, 2, 16, 14, 14)); - MEDIUM_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 2, 2, 14, 14, 14)); - - SMALL_SHAPES_OPEN.put(Direction.UP, Block.createCuboidShape(4, 0, 4, 12, 12, 12)); - SMALL_SHAPES_OPEN.put(Direction.DOWN, Block.createCuboidShape(4, 4, 4, 12, 16, 12)); - SMALL_SHAPES_OPEN.put(Direction.NORTH, Block.createCuboidShape(4, 4, 4, 12, 12, 16)); - SMALL_SHAPES_OPEN.put(Direction.SOUTH, Block.createCuboidShape(4, 4, 0, 12, 12, 12)); - SMALL_SHAPES_OPEN.put(Direction.WEST, Block.createCuboidShape(4, 4, 4, 16, 12, 12)); - SMALL_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 4, 4, 12, 12, 12)); + MEDIUM_SHAPES.put(Axis.X, Block.box(0, 2, 2, 16, 14, 14)); + MEDIUM_SHAPES.put(Axis.Y, Block.box(2, 0, 2, 14, 16, 14)); + MEDIUM_SHAPES.put(Axis.Z, Block.box(2, 2, 0, 14, 14, 16)); + + SMALL_SHAPES.put(Axis.X, Block.box(0, 4, 4, 16, 12, 12)); + SMALL_SHAPES.put(Axis.Y, Block.box(4, 0, 4, 12, 16, 12)); + SMALL_SHAPES.put(Axis.Z, Block.box(4, 4, 0, 12, 12, 16)); + + MEDIUM_SHAPES_OPEN.put(Direction.UP, Block.box(2, 0, 2, 14, 14, 14)); + MEDIUM_SHAPES_OPEN.put(Direction.DOWN, Block.box(2, 2, 2, 14, 16, 14)); + MEDIUM_SHAPES_OPEN.put(Direction.NORTH, Block.box(2, 2, 2, 14, 14, 16)); + MEDIUM_SHAPES_OPEN.put(Direction.SOUTH, Block.box(2, 2, 0, 14, 14, 14)); + MEDIUM_SHAPES_OPEN.put(Direction.WEST, Block.box(2, 2, 2, 16, 14, 14)); + MEDIUM_SHAPES_OPEN.put(Direction.EAST, Block.box(0, 2, 2, 14, 14, 14)); + + SMALL_SHAPES_OPEN.put(Direction.UP, Block.box(4, 0, 4, 12, 12, 12)); + SMALL_SHAPES_OPEN.put(Direction.DOWN, Block.box(4, 4, 4, 12, 16, 12)); + SMALL_SHAPES_OPEN.put(Direction.NORTH, Block.box(4, 4, 4, 12, 12, 16)); + SMALL_SHAPES_OPEN.put(Direction.SOUTH, Block.box(4, 4, 0, 12, 12, 12)); + SMALL_SHAPES_OPEN.put(Direction.WEST, Block.box(4, 4, 4, 16, 12, 12)); + SMALL_SHAPES_OPEN.put(Direction.EAST, Block.box(0, 4, 4, 12, 12, 12)); } } diff --git a/src/main/java/ru/betterend/blocks/PedestalVanilla.java b/src/main/java/ru/betterend/blocks/PedestalVanilla.java index a25460c1..292303fb 100644 --- a/src/main/java/ru/betterend/blocks/PedestalVanilla.java +++ b/src/main/java/ru/betterend/blocks/PedestalVanilla.java @@ -2,10 +2,9 @@ package ru.betterend.blocks; import java.util.HashMap; import java.util.Map; - -import net.minecraft.world.level.block.Block; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.patterns.Patterns; @@ -14,7 +13,7 @@ public class PedestalVanilla extends PedestalBlock { public PedestalVanilla(Block parent) { super(parent); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(parent); @@ -22,7 +21,7 @@ public class PedestalVanilla extends PedestalBlock { Map textures = new HashMap() { private static final long serialVersionUID = 1L; { - put("%mod%", blockId.getNamespace()); + put("%mod%", blockId.getNamespace() ); put("%top%", "polished_" + name); put("%base%", "polished_" + name); put("%pillar%", name + "_pillar"); diff --git a/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java b/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java index 55f92caa..2455e3b8 100644 --- a/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/PythadendronSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.registry.EndBlocks; @@ -17,9 +17,9 @@ public class PythadendronSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.PYTHADENDRON_TREE.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.CHORUS_NYLIUM); } } diff --git a/src/main/java/ru/betterend/blocks/RespawnObeliskBlock.java b/src/main/java/ru/betterend/blocks/RespawnObeliskBlock.java index 46579bd6..74208609 100644 --- a/src/main/java/ru/betterend/blocks/RespawnObeliskBlock.java +++ b/src/main/java/ru/betterend/blocks/RespawnObeliskBlock.java @@ -7,34 +7,34 @@ import org.jetbrains.annotations.Nullable; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; @@ -47,89 +47,94 @@ import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IRenderTypeable { - private static final VoxelShape VOXEL_SHAPE_BOTTOM = Block.createCuboidShape(1, 0, 1, 15, 16, 15); - private static final VoxelShape VOXEL_SHAPE_MIDDLE_TOP = Block.createCuboidShape(2, 0, 2, 14, 16, 14); - + private static final VoxelShape VOXEL_SHAPE_BOTTOM = Block.box(1, 0, 1, 15, 16, 15); + private static final VoxelShape VOXEL_SHAPE_MIDDLE_TOP = Block.box(2, 0, 2, 14, 16, 14); + public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - + public RespawnObeliskBlock() { - super(FabricBlockSettings.copyOf(Blocks.END_STONE).luminance((state) -> { + super(FabricBlockSettings.copyOf(Blocks.END_STONE).lightLevel((state) -> { return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? 0 : 15; })); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? VOXEL_SHAPE_BOTTOM : VOXEL_SHAPE_MIDDLE_TOP; } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { for (int i = 0; i < 3; i++) { - if (!world.getBlockState(pos.up(i)).getMaterial().isReplaceable()) { + if (!world.getBlockState(pos.above(i)).getMaterial().isReplaceable()) { return false; } } return true; } - + @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, - ItemStack itemStack) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { state = this.defaultBlockState(); - BlocksHelper.setWithUpdate(world, pos, state.with(SHAPE, TripleShape.BOTTOM)); - BlocksHelper.setWithUpdate(world, pos.up(), state.with(SHAPE, TripleShape.MIDDLE)); - BlocksHelper.setWithUpdate(world, pos.up(2), state.with(SHAPE, TripleShape.TOP)); + BlocksHelper.setWithUpdate(world, pos, state.setValue(SHAPE, TripleShape.BOTTOM)); + BlocksHelper.setWithUpdate(world, pos.above(), state.setValue(SHAPE, TripleShape.MIDDLE)); + BlocksHelper.setWithUpdate(world, pos.above(2), state.setValue(SHAPE, TripleShape.TOP)); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.BOTTOM) { - if (world.getBlockState(pos.up()).is(this)) { + if (world.getBlockState(pos.above()).is(this)) { return state; - } else { + } + else { return Blocks.AIR.defaultBlockState(); } - } else if (shape == TripleShape.MIDDLE) { - if (world.getBlockState(pos.up()).is(this) && world.getBlockState(pos.below()).is(this)) { + } + else if (shape == TripleShape.MIDDLE) { + if (world.getBlockState(pos.above()).is(this) && world.getBlockState(pos.below()).is(this)) { return state; - } else { + } + else { return Blocks.AIR.defaultBlockState(); } - } else { + } + else { if (world.getBlockState(pos.below()).is(this)) { return state; - } else { + } + else { return Blocks.AIR.defaultBlockState(); } } } - + @Override - public void onBreak(Level world, BlockPos pos, BlockState state, Player player) { + public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) { if (player.isCreative()) { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.MIDDLE) { BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR); - } else if (shape == TripleShape.TOP) { - BlocksHelper.setWithUpdate(world, pos.down(2), Blocks.AIR); + } + else if (shape == TripleShape.TOP) { + BlocksHelper.setWithUpdate(world, pos.below(2), Blocks.AIR); } } - super.onBreak(world, pos, state, player); + super.playerWillDestroy(world, pos, state, player); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(SHAPE) == TripleShape.BOTTOM) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } @@ -138,12 +143,12 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; } - + @Override - public BlockColor getBlockProvider() { - return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getBlockProvider(); + public BlockColor getProvider() { + return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getProvider(); } - + @Override public ItemColor getItemProvider() { return (stack, tintIndex) -> { @@ -152,20 +157,20 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR } @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - ItemStack itemStack = player.getStackInHand(hand); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + ItemStack itemStack = player.getItemInHand(hand); boolean canActivate = itemStack.getItem() == EndItems.AMBER_GEM && itemStack.getCount() > 5; - if (hand != Hand.MAIN_HAND || !canActivate) { + if (hand != InteractionHand.MAIN_HAND || !canActivate) { if (!world.isClientSide && !(itemStack.getItem() instanceof BlockItem) && !player.isCreative()) { ServerPlayer serverPlayerEntity = (ServerPlayer) player; - serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.fail_spawn"), true); + serverPlayerEntity.displayClientMessage(new TranslatableComponent("message.betterend.fail_spawn"), true); } - return ActionResult.FAIL; - } else if (!world.isClientSide) { + return InteractionResult.FAIL; + } + else if (!world.isClientSide) { ServerPlayer serverPlayerEntity = (ServerPlayer) player; - serverPlayerEntity.setSpawnPoint(world.dimension(), pos, 0.0F, false, false); - serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.set_spawn"), true); + serverPlayerEntity.setRespawnPosition(world.dimension(), pos, 0.0F, false, false); + serverPlayerEntity.displayClientMessage(new TranslatableComponent("message.betterend.set_spawn"), true); double px = pos.getX() + 0.5; double py = pos.getY() + 0.5; double pz = pos.getZ() + 0.5; @@ -176,21 +181,22 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR if (state.getValue(SHAPE) == TripleShape.BOTTOM) { py1 += 1; py2 += 2; - } else if (state.getValue(SHAPE) == TripleShape.MIDDLE) { + } + else if (state.getValue(SHAPE) == TripleShape.MIDDLE) { py1 += 0; py2 += 1; - } else { + } + else { py1 -= 2; } ((ServerLevel) world).sendParticles(particle, px, py1, pz, 20, 0.14, 0.5, 0.14, 0.1); ((ServerLevel) world).sendParticles(particle, px, py2, pz, 20, 0.14, 0.3, 0.14, 0.1); } - world.playLocalSound(null, px, py, py, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1F, - 1F); - if (!player.isCreative()) { - itemStack.decrement(6); - } + world.playSound(null, px, py, py, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1F, 1F); + if (!player.isCreative()) { + itemStack.shrink(6); + } } - return player.isCreative() ? ActionResult.PASS : ActionResult.success(world.isClientSide); + return player.isCreative() ? InteractionResult.PASS : InteractionResult.sidedSuccess(world.isClientSide); } } diff --git a/src/main/java/ru/betterend/blocks/RunedFlavolite.java b/src/main/java/ru/betterend/blocks/RunedFlavolite.java index d1f66d6a..9cefae39 100644 --- a/src/main/java/ru/betterend/blocks/RunedFlavolite.java +++ b/src/main/java/ru/betterend/blocks/RunedFlavolite.java @@ -2,10 +2,10 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; +import net.minecraft.world.level.block.state.properties.BooleanProperty; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; @@ -13,13 +13,12 @@ public class RunedFlavolite extends BlockBase { public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; public RunedFlavolite() { - super(FabricBlockSettings.copyOf(EndBlocks.FLAVOLITE.polished) - .resistance(Blocks.OBSIDIAN.getExplosionResistance()).luminance(state -> { - return state.getValue(ACTIVATED) ? 8 : 0; - })); - this.setDefaultState(stateManager.defaultBlockState().with(ACTIVATED, false)); + super(FabricBlockSettings.copyOf(EndBlocks.FLAVOLITE.polished).resistance(Blocks.OBSIDIAN.getExplosionResistance()).lightLevel(state -> { + return state.getValue(ACTIVATED) ? 8 : 0; + })); + this.registerDefaultState(stateDefinition.any().setValue(ACTIVATED, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(ACTIVATED); diff --git a/src/main/java/ru/betterend/blocks/ShadowBerryBlock.java b/src/main/java/ru/betterend/blocks/ShadowBerryBlock.java index 781fbdf6..0bbe5d06 100644 --- a/src/main/java/ru/betterend/blocks/ShadowBerryBlock.java +++ b/src/main/java/ru/betterend/blocks/ShadowBerryBlock.java @@ -1,24 +1,24 @@ package ru.betterend.blocks; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndCropBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public class ShadowBerryBlock extends EndCropBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(1, 0, 1, 15, 8, 15); - + private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 8, 15); + public ShadowBerryBlock() { super(EndItems.SHADOW_BERRY_RAW, EndBlocks.SHADOW_GRASS); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } } diff --git a/src/main/java/ru/betterend/blocks/ShadowGrassBlock.java b/src/main/java/ru/betterend/blocks/ShadowGrassBlock.java index a9b1c26f..955c4688 100644 --- a/src/main/java/ru/betterend/blocks/ShadowGrassBlock.java +++ b/src/main/java/ru/betterend/blocks/ShadowGrassBlock.java @@ -4,10 +4,10 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.MaterialColor; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.registry.EndParticles; public class ShadowGrassBlock extends EndTerrainBlock { @@ -19,8 +19,7 @@ public class ShadowGrassBlock extends EndTerrainBlock { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { super.animateTick(state, world, pos, random); if (random.nextInt(32) == 0) { - world.addParticle(EndParticles.BLACK_SPORE, (double) pos.getX() + random.nextDouble(), - (double) pos.getY() + 1.1D, (double) pos.getZ() + random.nextDouble(), 0.0D, 0.0D, 0.0D); + world.addParticle(EndParticles.BLACK_SPORE, (double) pos.getX() + random.nextDouble(), (double) pos.getY() + 1.1D, (double) pos.getZ() + random.nextDouble(), 0.0D, 0.0D, 0.0D); } } } diff --git a/src/main/java/ru/betterend/blocks/SilkMothHiveBlock.java b/src/main/java/ru/betterend/blocks/SilkMothHiveBlock.java index cc53adf6..ea66f3ca 100644 --- a/src/main/java/ru/betterend/blocks/SilkMothHiveBlock.java +++ b/src/main/java/ru/betterend/blocks/SilkMothHiveBlock.java @@ -4,31 +4,31 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.ActionResult; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.entity.SilkMothEntity; import ru.betterend.registry.EndEntities; @@ -37,36 +37,35 @@ import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; public class SilkMothHiveBlock extends BlockBase { - public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; + public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final IntegerProperty FULLNESS = BlockProperties.FULLNESS; - + public SilkMothHiveBlock() { - super(FabricBlockSettings.of(Material.WOOD).hardness(0.5F).resistance(0.1F).sounds(SoundType.WOOL).nonOpaque() - .ticksRandomly().breakByHand(true)); - this.setDefaultState(getDefaultState().with(FULLNESS, 0)); + super(FabricBlockSettings.of(Material.WOOD).breakByHand(true).hardness(0.5F).resistance(0.1F).sound(SoundType.WOOL).noOcclusion().randomTicks()); + this.registerDefaultState(defaultBlockState().setValue(FULLNESS, 0)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(FACING, FULLNESS); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - Direction dir = ctx.getPlayerFacing().getOpposite(); - return this.defaultBlockState().with(FACING, dir); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + Direction dir = ctx.getHorizontalDirection().getOpposite(); + return this.defaultBlockState().setValue(FACING, dir); } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { Direction dir = state.getValue(FACING); @@ -74,45 +73,42 @@ public class SilkMothHiveBlock extends BlockBase { if (!world.getBlockState(spawn).isAir()) { return; } - int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> { - return true; - }).size(); + int count = world.getEntities(EndEntities.SILK_MOTH, new AABB(pos).inflate(16), (entity) -> { return true; }).size(); if (count > 6) { return; } SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world); - moth.refreshPositionAndAngles(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.asRotation(), 0); - moth.setVelocity(new Vec3d(dir.getOffsetX() * 0.4, 0, dir.getOffsetZ() * 0.4)); + moth.moveTo(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.toYRot(), 0); + moth.setDeltaMovement(new Vec3(dir.getStepX() * 0.4, 0, dir.getStepZ() * 0.4)); moth.setHive(world, pos); - world.spawnEntity(moth); - world.playLocalSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); + world.addFreshEntity(moth); + world.playSound(null, pos, SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (hand == Hand.MAIN_HAND) { - ItemStack stack = player.getMainHandStack(); - if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.getValue(FULLNESS) == 3) { - BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0)); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (hand == InteractionHand.MAIN_HAND) { + ItemStack stack = player.getMainHandItem(); + if (stack.getItem().is(FabricToolTags.SHEARS) && state.getValue(FULLNESS) == 3) { + BlocksHelper.setWithUpdate(world, pos, state.setValue(FULLNESS, 0)); Direction dir = state.getValue(FACING); - double px = pos.getX() + dir.getOffsetX() + 0.5; - double py = pos.getY() + dir.getOffsetY() + 0.5; - double pz = pos.getZ() + dir.getOffsetZ() + 0.5; + double px = pos.getX() + dir.getStepX() + 0.5; + double py = pos.getY() + dir.getStepY() + 0.5; + double pz = pos.getZ() + dir.getStepZ() + 0.5; ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(8, 16, world.getRandom())); ItemEntity entity = new ItemEntity(world, px, py, pz, drop); - world.spawnEntity(entity); + world.addFreshEntity(entity); if (world.getRandom().nextInt(4) == 0) { drop = new ItemStack(EndItems.SILK_MOTH_MATRIX); entity = new ItemEntity(world, px, py, pz, drop); - world.spawnEntity(entity); + world.addFreshEntity(entity); } if (!player.isCreative()) { - stack.setDamage(stack.getDamage() + 1); + stack.setDamageValue(stack.getDamageValue() + 1); } - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } diff --git a/src/main/java/ru/betterend/blocks/SilkMothNestBlock.java b/src/main/java/ru/betterend/blocks/SilkMothNestBlock.java index 281e7d2e..358d8cbc 100644 --- a/src/main/java/ru/betterend/blocks/SilkMothNestBlock.java +++ b/src/main/java/ru/betterend/blocks/SilkMothNestBlock.java @@ -6,39 +6,39 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.ActionResult; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.client.render.ERenderLayer; import ru.betterend.entity.SilkMothEntity; @@ -50,24 +50,23 @@ import ru.betterend.util.MHelper; public class SilkMothNestBlock extends BlockBase implements IRenderTypeable { public static final BooleanProperty ACTIVE = BlockProperties.ACTIVE; - public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; + public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final IntegerProperty FULLNESS = BlockProperties.FULLNESS; - private static final VoxelShape TOP = createCuboidShape(6, 0, 6, 10, 16, 10); - private static final VoxelShape BOTTOM = createCuboidShape(0, 0, 0, 16, 16, 16); - + private static final VoxelShape TOP = box(6, 0, 6, 10, 16, 10); + private static final VoxelShape BOTTOM = box(0, 0, 0, 16, 16, 16); + public SilkMothNestBlock() { - super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sounds(SoundType.WOOL).nonOpaque() - .ticksRandomly()); - this.setDefaultState(getDefaultState().with(ACTIVE, true).with(FULLNESS, 0)); + super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sound(SoundType.WOOL).noOcclusion().randomTicks()); + this.registerDefaultState(defaultBlockState().setValue(ACTIVE, true).setValue(FULLNESS, 0)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(ACTIVE, FACING, FULLNESS); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(ACTIVE) ? BOTTOM : TOP; } @@ -75,54 +74,53 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable { public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - Direction dir = ctx.getPlayerFacing().getOpposite(); - return this.defaultBlockState().with(FACING, dir); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + Direction dir = ctx.getHorizontalDirection().getOpposite(); + return this.defaultBlockState().setValue(FACING, dir); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!state.getValue(ACTIVE)) { - if (sideCoversSmallSquare(world, pos.up(), Direction.DOWN) - || world.getBlockState(pos.up()).isIn(BlockTags.LEAVES)) { + if (canSupportCenter(world, pos.above(), Direction.DOWN) || world.getBlockState(pos.above()).is(BlockTags.LEAVES)) { return state; - } else { + } + else { return Blocks.AIR.defaultBlockState(); } } return state; } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return state.getValue(ACTIVE) ? Collections.singletonList(new ItemStack(this)) : Collections.emptyList(); } - + @Override - public void onBreak(Level world, BlockPos pos, BlockState state, Player player) { + public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) { if (!state.getValue(ACTIVE) && player.isCreative()) { BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR); } - BlockState up = world.getBlockState(pos.up()); - if (up.is(this) && !up.get(ACTIVE)) { - BlocksHelper.setWithUpdate(world, pos.up(), Blocks.AIR); + BlockState up = world.getBlockState(pos.above()); + if (up.is(this) && !up.getValue(ACTIVE)) { + BlocksHelper.setWithUpdate(world, pos.above(), Blocks.AIR); } - super.onBreak(world, pos, state, player); + super.playerWillDestroy(world, pos, state, player); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (!state.getValue(ACTIVE)) { @@ -136,44 +134,40 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable { if (!world.getBlockState(spawn).isAir()) { return; } - int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> { - return true; - }).size(); + int count = world.getEntities(EndEntities.SILK_MOTH, new AABB(pos).inflate(16), (entity) -> { return true; }).size(); if (count > 6) { return; } SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world); - moth.refreshPositionAndAngles(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.asRotation(), 0); - moth.setVelocity(new Vec3d(dir.getOffsetX() * 0.4, 0, dir.getOffsetZ() * 0.4)); + moth.moveTo(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.toYRot(), 0); + moth.setDeltaMovement(new Vec3(dir.getStepX() * 0.4, 0, dir.getStepZ() * 0.4)); moth.setHive(world, pos); - world.spawnEntity(moth); - world.playLocalSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); + world.addFreshEntity(moth); + world.playSound(null, pos, SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (hand == Hand.MAIN_HAND) { - ItemStack stack = player.getMainHandStack(); - if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.getValue(ACTIVE) - && state.getValue(FULLNESS) == 3) { - BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0)); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (hand == InteractionHand.MAIN_HAND) { + ItemStack stack = player.getMainHandItem(); + if (stack.getItem().is(FabricToolTags.SHEARS) && state.getValue(ACTIVE) && state.getValue(FULLNESS) == 3) { + BlocksHelper.setWithUpdate(world, pos, state.setValue(FULLNESS, 0)); Direction dir = state.getValue(FACING); - double px = pos.getX() + dir.getOffsetX() + 0.5; - double py = pos.getY() + dir.getOffsetY() + 0.5; - double pz = pos.getZ() + dir.getOffsetZ() + 0.5; + double px = pos.getX() + dir.getStepX() + 0.5; + double py = pos.getY() + dir.getStepY() + 0.5; + double pz = pos.getZ() + dir.getStepZ() + 0.5; ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(1, 4, world.getRandom())); ItemEntity entity = new ItemEntity(world, px, py, pz, drop); - world.spawnEntity(entity); + world.addFreshEntity(entity); drop = new ItemStack(EndItems.SILK_MOTH_MATRIX, MHelper.randRange(1, 3, world.getRandom())); entity = new ItemEntity(world, px, py, pz, drop); - world.spawnEntity(entity); + world.addFreshEntity(entity); if (!player.isCreative()) { - stack.setDamage(stack.getDamage() + 1); + stack.setDamageValue(stack.getDamageValue() + 1); } - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } diff --git a/src/main/java/ru/betterend/blocks/SmallAmaranitaBlock.java b/src/main/java/ru/betterend/blocks/SmallAmaranitaBlock.java index a3c23dfc..9bf881c3 100644 --- a/src/main/java/ru/betterend/blocks/SmallAmaranitaBlock.java +++ b/src/main/java/ru/betterend/blocks/SmallAmaranitaBlock.java @@ -1,33 +1,31 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.util.BlocksHelper; public class SmallAmaranitaBlock extends EndPlantBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 10, 12); - + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 10, 12); + @Override protected boolean isTerrain(BlockState state) { - return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) - || state.is(EndBlocks.MOSSY_DRAGON_BONE); + return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) || state.is(EndBlocks.MOSSY_DRAGON_BONE); } - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { BlockPos bigPos = growBig(world, pos); if (bigPos != null) { if (EndFeatures.GIGANTIC_AMARANITA.getFeature().place(world, null, random, bigPos, null)) { @@ -40,13 +38,13 @@ public class SmallAmaranitaBlock extends EndPlantBlock { } EndFeatures.LARGE_AMARANITA.getFeature().place(world, null, random, pos, null); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); - return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); + return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } - + private BlockPos growBig(ServerLevel world, BlockPos pos) { for (int x = -1; x < 2; x++) { for (int z = -1; z < 2; z++) { @@ -58,20 +56,22 @@ public class SmallAmaranitaBlock extends EndPlantBlock { } return null; } - + private boolean checkFrame(ServerLevel world, BlockPos pos) { - return world.getBlockState(pos).is(this) && world.getBlockState(pos.south()).is(this) - && world.getBlockState(pos.east()).is(this) && world.getBlockState(pos.south().east()).is(this); + return world.getBlockState(pos).is(this) && + world.getBlockState(pos.south()).is(this) && + world.getBlockState(pos.east()).is(this) && + world.getBlockState(pos.south().east()).is(this); } - + private void replaceMushroom(ServerLevel world, BlockPos pos) { if (world.getBlockState(pos).is(this)) { BlocksHelper.setWithUpdate(world, pos, Blocks.AIR); } } - + @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return random.nextInt(8) == 0; } } diff --git a/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java b/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java index 66213bb0..f9f6b212 100644 --- a/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java +++ b/src/main/java/ru/betterend/blocks/SmallJellyshroomBlock.java @@ -9,26 +9,26 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -36,64 +36,67 @@ import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; -public class SmallJellyshroomBlock extends AttachedBlock implements IRenderTypeable, Fertilizable { +public class SmallJellyshroomBlock extends AttachedBlock implements IRenderTypeable, BonemealableBlock { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); - + public SmallJellyshroomBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.NETHER_WART) - .breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.NETHER_WART) + .noCollission()); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); BlockState support = world.getBlockState(blockPos); - return sideCoversSmallSquare(world, blockPos, direction) && support.isOpaque() && support.getLuminance() == 0; + return canSupportCenter(world, blockPos, direction) && support.canOcclude() && support.getLightEmission() == 0; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + static { - BOUNDING_SHAPES.put(Direction.UP, Block.createCuboidShape(3, 0, 3, 13, 16, 13)); - BOUNDING_SHAPES.put(Direction.DOWN, Block.createCuboidShape(3, 0, 3, 13, 16, 13)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.UP, Block.box(3, 0, 3, 13, 16, 13)); + BOUNDING_SHAPES.put(Direction.DOWN, Block.box(3, 0, 3, 13, 16, 13)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { - return state.getValue(FACING) == Direction.UP && world.getBlockState(pos.below()).isIn(EndTags.END_GROUND); + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { + return state.getValue(FACING) == Direction.UP && world.getBlockState(pos.below()).is(EndTags.END_GROUND); } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return random.nextInt(16) == 0; } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { BlocksHelper.setWithUpdate(world, pos, Blocks.AIR); EndFeatures.JELLYSHROOM.getFeature().place(world, null, random, pos, null); } diff --git a/src/main/java/ru/betterend/blocks/SmaragdantCrystalBlock.java b/src/main/java/ru/betterend/blocks/SmaragdantCrystalBlock.java index cdd80120..6572cbf2 100644 --- a/src/main/java/ru/betterend/blocks/SmaragdantCrystalBlock.java +++ b/src/main/java/ru/betterend/blocks/SmaragdantCrystalBlock.java @@ -2,13 +2,18 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.material.Material; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.EndPillarBlock; public class SmaragdantCrystalBlock extends EndPillarBlock { public SmaragdantCrystalBlock() { - super(FabricBlockSettings.of(Material.GLASS).breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS) - .luminance(15).hardness(1F).resistance(1F).nonOpaque()); + super(FabricBlockSettings.of(Material.GLASS) + .breakByTool(FabricToolTags.PICKAXES) + .luminance(15) + .hardness(1F) + .resistance(1F) + .noOcclusion() + .sound(SoundType.GLASS)); } } diff --git a/src/main/java/ru/betterend/blocks/SmaragdantCrystalShardBlock.java b/src/main/java/ru/betterend/blocks/SmaragdantCrystalShardBlock.java index 3edebc7c..2e8626a8 100644 --- a/src/main/java/ru/betterend/blocks/SmaragdantCrystalShardBlock.java +++ b/src/main/java/ru/betterend/blocks/SmaragdantCrystalShardBlock.java @@ -6,99 +6,102 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; -public class SmaragdantCrystalShardBlock extends AttachedBlock - implements IRenderTypeable, Waterloggable, FluidFillable { +public class SmaragdantCrystalShardBlock extends AttachedBlock implements IRenderTypeable, SimpleWaterloggedBlock, LiquidBlockContainer { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public SmaragdantCrystalShardBlock() { - super(FabricBlockSettings.of(Material.STONE).materialColor(MaterialColor.COLOR_GREEN) - .breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS).luminance(15).requiresTool() - .noCollision()); + super(FabricBlockSettings.of(Material.STONE) + .materialColor(MaterialColor.COLOR_GREEN) + .breakByTool(FabricToolTags.PICKAXES) + .luminance(15) + .sound(SoundType.GLASS) + .requiresCorrectToolForDrops() + .noCollission()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { super.createBlockStateDefinition(stateManager); stateManager.add(WATERLOGGED); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return !state.getValue(WATERLOGGED); } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return !state.getValue(WATERLOGGED); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - BlockState state = super.getPlacementState(ctx); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + BlockState state = super.getStateForPlacement(ctx); if (state != null) { - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; - return state.with(WATERLOGGED, water); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER; + return state.setValue(WATERLOGGED, water); } return null; } - + @Override public FluidState getFluidState(BlockState state) { - return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState(); + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); - return world.getBlockState(blockPos).isSideSolidFullSquare(world, blockPos, direction); + return world.getBlockState(blockPos).isFaceSturdy(world, blockPos, direction); } - + static { - BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.125, 0.0, 0.125, 0.875F, 0.875F, 0.875F)); - BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 1.0, 0.875F)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 0.875F, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.125, 0.125, 0.0, 0.875F, 0.875F, 0.875F)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.125, 0.125, 0.125, 1.0, 0.875F, 0.875F)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.125, 0.125, 0.875F, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.UP, Shapes.box(0.125, 0.0, 0.125, 0.875F, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.DOWN, Shapes.box(0.125, 0.125, 0.125, 0.875F, 1.0, 0.875F)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.125, 0.125, 0.125, 0.875F, 0.875F, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.125, 0.125, 0.0, 0.875F, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.125, 0.125, 0.125, 1.0, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.125, 0.125, 0.875F, 0.875F, 0.875F)); } } diff --git a/src/main/java/ru/betterend/blocks/SulphurCrystalBlock.java b/src/main/java/ru/betterend/blocks/SulphurCrystalBlock.java index ea73eb86..d0becc90 100644 --- a/src/main/java/ru/betterend/blocks/SulphurCrystalBlock.java +++ b/src/main/java/ru/betterend/blocks/SulphurCrystalBlock.java @@ -9,31 +9,31 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -41,79 +41,81 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; import ru.betterend.util.MHelper; -public class SulphurCrystalBlock extends AttachedBlock implements IRenderTypeable, Waterloggable, FluidFillable { +public class SulphurCrystalBlock extends AttachedBlock implements IRenderTypeable, SimpleWaterloggedBlock, LiquidBlockContainer { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); - public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 2); - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - + public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 2); + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public SulphurCrystalBlock() { - super(FabricBlockSettings.of(Material.STONE).materialColor(MaterialColor.COLOR_YELLOW) - .breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS).requiresTool().noCollision()); + super(FabricBlockSettings.of(Material.STONE) + .materialColor(MaterialColor.COLOR_YELLOW) + .breakByTool(FabricToolTags.PICKAXES) + .sound(SoundType.GLASS) + .requiresCorrectToolForDrops() + .noCollission()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { super.createBlockStateDefinition(stateManager); stateManager.add(AGE, WATERLOGGED); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { - return state.getValue(AGE) < 2 ? Collections.emptyList() - : Lists.newArrayList( - new ItemStack(EndItems.CRYSTALLINE_SULPHUR, MHelper.randRange(1, 3, MHelper.RANDOM))); + return state.getValue(AGE) < 2 ? Collections.emptyList() : Lists.newArrayList(new ItemStack(EndItems.CRYSTALLINE_SULPHUR, MHelper.randRange(1, 3, MHelper.RANDOM))); } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return !state.getValue(WATERLOGGED); } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return !state.getValue(WATERLOGGED); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - BlockState state = super.getPlacementState(ctx); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + BlockState state = super.getStateForPlacement(ctx); if (state != null) { - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; - return state.with(WATERLOGGED, water); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER; + return state.setValue(WATERLOGGED, water); } return null; } - + @Override public FluidState getFluidState(BlockState state) { - return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState(); + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); return world.getBlockState(blockPos).is(EndBlocks.BRIMSTONE); } - + static { - BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.125, 0.0, 0.125, 0.875F, 0.5, 0.875F)); - BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.125, 0.5, 0.125, 0.875F, 1.0, 0.875F)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.125, 0.125, 0.5, 0.875F, 0.875F, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.125, 0.125, 0.0, 0.875F, 0.875F, 0.5)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.125, 0.125, 1.0, 0.875F, 0.875F)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.125, 0.125, 0.5, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.UP, Shapes.box(0.125, 0.0, 0.125, 0.875F, 0.5, 0.875F)); + BOUNDING_SHAPES.put(Direction.DOWN, Shapes.box(0.125, 0.5, 0.125, 0.875F, 1.0, 0.875F)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.125, 0.125, 0.5, 0.875F, 0.875F, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.125, 0.125, 0.0, 0.875F, 0.875F, 0.5)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.125, 0.125, 1.0, 0.875F, 0.875F)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.125, 0.125, 0.5, 0.875F, 0.875F)); } } diff --git a/src/main/java/ru/betterend/blocks/TenaneaFlowersBlock.java b/src/main/java/ru/betterend/blocks/TenaneaFlowersBlock.java index 4059ca38..82238857 100644 --- a/src/main/java/ru/betterend/blocks/TenaneaFlowersBlock.java +++ b/src/main/java/ru/betterend/blocks/TenaneaFlowersBlock.java @@ -4,14 +4,14 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; import net.minecraft.core.Vec3i; +import net.minecraft.util.Mth; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.VineBlock; import ru.betterend.interfaces.IColorProvider; import ru.betterend.registry.EndParticles; @@ -19,13 +19,13 @@ import ru.betterend.util.MHelper; public class TenaneaFlowersBlock extends VineBlock implements IColorProvider { public static final Vec3i[] COLORS; - + public TenaneaFlowersBlock() { super(15); } @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { long i = (MHelper.getRandom(pos.getX(), pos.getZ()) & 63) + pos.getY(); double delta = i * 0.1; @@ -33,15 +33,15 @@ public class TenaneaFlowersBlock extends VineBlock implements IColorProvider { int index2 = (index + 1) & 3; delta -= index; index &= 3; - + Vec3i color1 = COLORS[index]; Vec3i color2 = COLORS[index2]; - + int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); float[] hsb = MHelper.fromRGBtoHSB(r, g, b); - + return MHelper.fromHSBtoRGB(hsb[0], MHelper.max(0.5F, hsb[1]), hsb[2]); }; } @@ -52,12 +52,12 @@ public class TenaneaFlowersBlock extends VineBlock implements IColorProvider { return MHelper.color(255, 255, 255); }; } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } - + @Environment(EnvType.CLIENT) public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { super.animateTick(state, world, pos, random); @@ -68,9 +68,13 @@ public class TenaneaFlowersBlock extends VineBlock implements IColorProvider { world.addParticle(EndParticles.TENANEA_PETAL, x, y, z, 0, 0, 0); } } - + static { - COLORS = new Vec3i[] { new Vec3i(250, 111, 222), new Vec3i(167, 89, 255), new Vec3i(120, 207, 239), - new Vec3i(255, 87, 182) }; + COLORS = new Vec3i[] { + new Vec3i(250, 111, 222), + new Vec3i(167, 89, 255), + new Vec3i(120, 207, 239), + new Vec3i(255, 87, 182) + }; } } diff --git a/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java b/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java index 77b0de8a..c4e8393f 100644 --- a/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/TenaneaSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.registry.EndBlocks; @@ -17,9 +17,9 @@ public class TenaneaSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.LUCERNIA.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.RUTISCUS); } } diff --git a/src/main/java/ru/betterend/blocks/TerminiteBlock.java b/src/main/java/ru/betterend/blocks/TerminiteBlock.java index a7a1b6eb..19c031c3 100644 --- a/src/main/java/ru/betterend/blocks/TerminiteBlock.java +++ b/src/main/java/ru/betterend/blocks/TerminiteBlock.java @@ -1,14 +1,17 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SoundType; import ru.betterend.blocks.basis.BlockBase; public class TerminiteBlock extends BlockBase { public TerminiteBlock() { - super(FabricBlockSettings.of(Material.METAL, MaterialColor.field_25708).hardness(7F).resistance(9F) - .requiresTool().sounds(SoundType.METAL)); + super(FabricBlockSettings.of(Material.METAL, MaterialColor.WARPED_WART_BLOCK) + .hardness(7F) + .resistance(9F) + .requiresCorrectToolForDrops() + .sound(SoundType.METAL)); } } diff --git a/src/main/java/ru/betterend/blocks/TerrainPlantBlock.java b/src/main/java/ru/betterend/blocks/TerrainPlantBlock.java index 3f1ba358..090b3b15 100644 --- a/src/main/java/ru/betterend/blocks/TerrainPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/TerrainPlantBlock.java @@ -6,15 +6,15 @@ import ru.betterend.blocks.basis.EndPlantBlock; public class TerrainPlantBlock extends EndPlantBlock { private final Block[] ground; - + public TerrainPlantBlock(Block... ground) { super(true); this.ground = ground; } - + @Override protected boolean isTerrain(BlockState state) { - for (Block block : ground) { + for (Block block: ground) { if (state.is(block)) { return true; } diff --git a/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossBlock.java b/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossBlock.java index fe4d215e..08fe2dbf 100644 --- a/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossBlock.java +++ b/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossBlock.java @@ -4,11 +4,11 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; @@ -18,32 +18,32 @@ public class TwistedUmbrellaMossBlock extends EndPlantBlock { public TwistedUmbrellaMossBlock() { super(11); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); } - + @Environment(EnvType.CLIENT) - public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { - return true; - } + public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) { + return true; + } - @Environment(EnvType.CLIENT) - public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { - return 1F; + @Environment(EnvType.CLIENT) + public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) { + return 1F; + } + + @Override + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { + return world.isEmptyBlock(pos.above()); } - - @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { - return world.isAir(pos.up()); - } - - @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - int rot = world.random.nextInt(4); - BlockState bs = EndBlocks.TWISTED_UMBRELLA_MOSS_TALL.defaultBlockState().with(DoublePlantBlock.ROTATION, rot); + + @Override + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + int rot = world.random.nextInt(4); + BlockState bs = EndBlocks.TWISTED_UMBRELLA_MOSS_TALL.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot); BlocksHelper.setWithoutUpdate(world, pos, bs); - BlocksHelper.setWithoutUpdate(world, pos.up(), bs.with(DoublePlantBlock.TOP, true)); + BlocksHelper.setWithoutUpdate(world, pos.above(), bs.setValue(DoublePlantBlock.TOP, true)); } } diff --git a/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossTallBlock.java b/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossTallBlock.java index b344ba20..843aa4a3 100644 --- a/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossTallBlock.java +++ b/src/main/java/ru/betterend/blocks/TwistedUmbrellaMossTallBlock.java @@ -1,12 +1,11 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.registry.EndBlocks; @@ -14,14 +13,13 @@ public class TwistedUmbrellaMossTallBlock extends DoublePlantBlock { public TwistedUmbrellaMossTallBlock() { super(12); } - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(EndBlocks.TWISTED_UMBRELLA_MOSS)); - world.spawnEntity(item); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(EndBlocks.TWISTED_UMBRELLA_MOSS)); + world.addFreshEntity(item); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); diff --git a/src/main/java/ru/betterend/blocks/UmbrellaMossBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaMossBlock.java index bef8a773..e9fb7790 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaMossBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaMossBlock.java @@ -4,11 +4,11 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.registry.EndBlocks; @@ -18,32 +18,32 @@ public class UmbrellaMossBlock extends EndPlantBlock { public UmbrellaMossBlock() { super(11); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); } - + @Environment(EnvType.CLIENT) - public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { - return true; - } + public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) { + return true; + } - @Environment(EnvType.CLIENT) - public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { - return 1F; + @Environment(EnvType.CLIENT) + public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) { + return 1F; + } + + @Override + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { + return world.isEmptyBlock(pos.above()); } - - @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { - return world.isAir(pos.up()); - } - - @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - int rot = world.random.nextInt(4); - BlockState bs = EndBlocks.UMBRELLA_MOSS_TALL.defaultBlockState().with(DoublePlantBlock.ROTATION, rot); + + @Override + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + int rot = world.random.nextInt(4); + BlockState bs = EndBlocks.UMBRELLA_MOSS_TALL.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot); BlocksHelper.setWithoutUpdate(world, pos, bs); - BlocksHelper.setWithoutUpdate(world, pos.up(), bs.with(DoublePlantBlock.TOP, true)); + BlocksHelper.setWithoutUpdate(world, pos.above(), bs.setValue(DoublePlantBlock.TOP, true)); } } diff --git a/src/main/java/ru/betterend/blocks/UmbrellaMossTallBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaMossTallBlock.java index 0ab0434c..7e15e99a 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaMossTallBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaMossTallBlock.java @@ -1,12 +1,11 @@ package ru.betterend.blocks; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.registry.EndBlocks; @@ -14,14 +13,13 @@ public class UmbrellaMossTallBlock extends DoublePlantBlock { public UmbrellaMossTallBlock() { super(12); } - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(EndBlocks.UMBRELLA_MOSS)); - world.spawnEntity(item); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(EndBlocks.UMBRELLA_MOSS)); + world.addFreshEntity(item); } - + @Override protected boolean isTerrain(BlockState state) { return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); diff --git a/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterBlock.java index d9d48e22..2565ca21 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterBlock.java @@ -1,22 +1,22 @@ package ru.betterend.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.phys.BlockHitResult; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; @@ -24,34 +24,32 @@ import ru.betterend.util.BlocksHelper; public class UmbrellaTreeClusterBlock extends BlockBase { public static final BooleanProperty NATURAL = BlockProperties.NATURAL; - + public UmbrellaTreeClusterBlock() { - super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK).materialColor(MaterialColor.COLOR_PURPLE) + super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK) + .materialColor(MaterialColor.COLOR_PURPLE) .luminance(15)); - setDefaultState(stateManager.defaultBlockState().with(NATURAL, false)); + registerDefaultState(stateDefinition.any().setValue(NATURAL, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(NATURAL); } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - ItemStack stack = player.getMainHandStack(); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + ItemStack stack = player.getMainHandItem(); if (stack.getItem() == Items.GLASS_BOTTLE) { if (!player.isCreative()) { - stack.decrement(1); + stack.shrink(1); } stack = new ItemStack(EndItems.UMBRELLA_CLUSTER_JUICE); - player.giveItemStack(stack); - world.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.ITEM_BOTTLE_FILL, - SoundSource.BLOCKS, 1, 1, false); - BlocksHelper.setWithUpdate(world, pos, - EndBlocks.UMBRELLA_TREE_CLUSTER_EMPTY.defaultBlockState().with(NATURAL, state.getValue(NATURAL))); - return ActionResult.SUCCESS; + player.addItem(stack); + world.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, 1, 1, false); + BlocksHelper.setWithUpdate(world, pos, EndBlocks.UMBRELLA_TREE_CLUSTER_EMPTY.defaultBlockState().setValue(NATURAL, state.getValue(NATURAL))); + return InteractionResult.SUCCESS; } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } diff --git a/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterEmptyBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterEmptyBlock.java index b4f1941a..a8805689 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterEmptyBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaTreeClusterEmptyBlock.java @@ -3,37 +3,37 @@ package ru.betterend.blocks; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; public class UmbrellaTreeClusterEmptyBlock extends BlockBase { public static final BooleanProperty NATURAL = BlockProperties.NATURAL; - + public UmbrellaTreeClusterEmptyBlock() { - super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK).materialColor(MaterialColor.COLOR_PURPLE) - .ticksRandomly()); - setDefaultState(stateManager.defaultBlockState().with(NATURAL, false)); + super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK) + .materialColor(MaterialColor.COLOR_PURPLE) + .randomTicks()); + registerDefaultState(stateDefinition.any().setValue(NATURAL, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(NATURAL); } - + @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { if (state.getValue(NATURAL) && random.nextInt(16) == 0) { - BlocksHelper.setWithUpdate(world, pos, - EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState().with(UmbrellaTreeClusterBlock.NATURAL, true)); + BlocksHelper.setWithUpdate(world, pos, EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState().setValue(UmbrellaTreeClusterBlock.NATURAL, true)); } } } diff --git a/src/main/java/ru/betterend/blocks/UmbrellaTreeMembraneBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaTreeMembraneBlock.java index 31844133..215bb8a2 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaTreeMembraneBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaTreeMembraneBlock.java @@ -9,20 +9,20 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SlimeBlock; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SlimeBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.noise.OpenSimplexNoise; @@ -34,66 +34,67 @@ import ru.betterend.util.MHelper; public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderTypeable, BlockPatterned { public static final IntegerProperty COLOR = BlockProperties.COLOR; private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); - + public UmbrellaTreeMembraneBlock() { super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK)); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - double px = ctx.getBlockPos().getX() * 0.1; - double py = ctx.getBlockPos().getY() * 0.1; - double pz = ctx.getBlockPos().getZ() * 0.1; - return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + double px = ctx.getClickedPos().getX() * 0.1; + double py = ctx.getClickedPos().getY() * 0.1; + double pz = ctx.getClickedPos().getZ() * 0.1; + return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(COLOR); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(COLOR) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { - return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) - : Collections.emptyList(); + } + else { + return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) : Collections.emptyList(); } } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; } @Override - public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { + public boolean propagatesSkylightDown(BlockState state, BlockGetter world, BlockPos pos) { return state.getValue(COLOR) > 0; } - + @Environment(EnvType.CLIENT) - public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) { if (state.getValue(COLOR) > 0) { - return super.isSideInvisible(state, stateFrom, direction); - } else { + return super.skipRendering(state, stateFrom, direction); + } + else { return false; } } diff --git a/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java b/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java index 47608d81..cc01c356 100644 --- a/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/UmbrellaTreeSaplingBlock.java @@ -1,8 +1,8 @@ package ru.betterend.blocks; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.client.render.ERenderLayer; @@ -18,12 +18,12 @@ public class UmbrellaTreeSaplingBlock extends FeatureSaplingBlock { protected Feature getFeature() { return EndFeatures.UMBRELLA_TREE.getFeature(); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return world.getBlockState(pos.below()).is(EndBlocks.JUNGLE_MOSS); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.TRANSLUCENT; diff --git a/src/main/java/ru/betterend/blocks/VentBubbleColumnBlock.java b/src/main/java/ru/betterend/blocks/VentBubbleColumnBlock.java index 8664b136..e01729ef 100644 --- a/src/main/java/ru/betterend/blocks/VentBubbleColumnBlock.java +++ b/src/main/java/ru/betterend/blocks/VentBubbleColumnBlock.java @@ -5,70 +5,70 @@ import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockRenderType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FluidDrainable; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.entity.Entity; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; -public class VentBubbleColumnBlock extends Block implements FluidDrainable, FluidFillable { +public class VentBubbleColumnBlock extends Block implements BucketPickup, LiquidBlockContainer { public VentBubbleColumnBlock() { - super(FabricBlockSettings.of(Material.BUBBLE_COLUMN).nonOpaque().noCollision().dropsNothing()); + super(FabricBlockSettings.of(Material.BUBBLE_COLUMN).noOcclusion().noCollission().noDrops()); } @Override - public Fluid tryDrainFluid(LevelAccessor world, BlockPos pos, BlockState state) { - world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState(), 11); + public Fluid takeLiquid(LevelAccessor world, BlockPos pos, BlockState state) { + world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11); return Fluids.WATER; } - + @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.INVISIBLE; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.INVISIBLE; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState blockState = world.getBlockState(pos.below()); return blockState.is(this) || blockState.is(EndBlocks.HYDROTHERMAL_VENT); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { - return VoxelShapes.empty(); + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { + return Shapes.empty(); } @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { - if (!state.canPlaceAt(world, pos)) { + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { + if (!state.canSurvive(world, pos)) { return Blocks.WATER.defaultBlockState(); - } else { - BlockPos up = pos.up(); + } + else { + BlockPos up = pos.above(); if (world.getBlockState(up).is(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, up, this); - world.getBlockTickScheduler().schedule(up, this, 5); + world.getBlockTicks().scheduleTick(up, this, 5); } } return state; @@ -80,48 +80,44 @@ public class VentBubbleColumnBlock extends Block implements FluidDrainable, Flui double px = pos.getX() + random.nextDouble(); double py = pos.getY() + random.nextDouble(); double pz = pos.getZ() + random.nextDouble(); - world.addImportantParticle(ParticleTypes.BUBBLE_COLUMN_UP, px, py, pz, 0, 0.04, 0); + world.addAlwaysVisibleParticle(ParticleTypes.BUBBLE_COLUMN_UP, px, py, pz, 0, 0.04, 0); } if (random.nextInt(200) == 0) { - world.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, - SoundSource.BLOCKS, 0.2F + random.nextFloat() * 0.2F, 0.9F + random.nextFloat() * 0.15F, false); + world.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BUBBLE_COLUMN_UPWARDS_AMBIENT, SoundSource.BLOCKS, 0.2F + random.nextFloat() * 0.2F, 0.9F + random.nextFloat() * 0.15F, false); } } @Environment(EnvType.CLIENT) public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { - BlockState blockState = world.getBlockState(pos.up()); + BlockState blockState = world.getBlockState(pos.above()); if (blockState.isAir()) { - entity.onBubbleColumnSurfaceCollision(false); + entity.onAboveBubbleCol(false); if (!world.isClientSide) { ServerLevel serverWorld = (ServerLevel) world; for (int i = 0; i < 2; ++i) { - serverWorld.sendParticles(ParticleTypes.SPLASH, (double) pos.getX() + world.random.nextDouble(), - (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.0D, - 0.0D, 1.0D); - serverWorld.sendParticles(ParticleTypes.BUBBLE, (double) pos.getX() + world.random.nextDouble(), - (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.01D, - 0.0D, 0.2D); + serverWorld.sendParticles(ParticleTypes.SPLASH, (double) pos.getX() + world.random.nextDouble(), (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.0D, 0.0D, 1.0D); + serverWorld.sendParticles(ParticleTypes.BUBBLE, (double) pos.getX() + world.random.nextDouble(), (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.01D, 0.0D, 0.2D); } } - } else { - entity.onBubbleColumnCollision(false); + } + else { + entity.onInsideBubbleColumn(false); } } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override public FluidState getFluidState(BlockState state) { - return Fluids.WATER.getStill(false); + return Fluids.WATER.getSource(false); } } diff --git a/src/main/java/ru/betterend/blocks/basis/AttachedBlock.java b/src/main/java/ru/betterend/blocks/basis/AttachedBlock.java index 64f1f99a..474859ff 100644 --- a/src/main/java/ru/betterend/blocks/basis/AttachedBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/AttachedBlock.java @@ -1,45 +1,45 @@ package ru.betterend.blocks.basis; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.DirectionProperty; import ru.betterend.util.BlocksHelper; public abstract class AttachedBlock extends BlockBaseNotFull { - public static final DirectionProperty FACING = Properties.FACING; - - public AttachedBlock(net.minecraft.world.level.block.state.BlockBehaviour.Properties settings) { + public static final DirectionProperty FACING = BlockStateProperties.FACING; + + public AttachedBlock(Properties settings) { super(settings); - this.setDefaultState(this.defaultBlockState().with(FACING, Direction.UP)); + this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.UP)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(FACING); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { BlockState blockState = this.defaultBlockState(); - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - Direction[] directions = ctx.getPlacementDirections(); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + Direction[] directions = ctx.getNearestLookingDirections(); for (int i = 0; i < directions.length; ++i) { Direction direction = directions[i]; Direction direction2 = direction.getOpposite(); - blockState = (BlockState) blockState.with(FACING, direction2); - if (blockState.canPlaceAt(worldView, blockPos)) { + blockState = (BlockState) blockState.setValue(FACING, direction2); + if (blockState.canSurvive(worldView, blockPos)) { return blockState; } } @@ -47,30 +47,30 @@ public abstract class AttachedBlock extends BlockBaseNotFull { } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); - return sideCoversSmallSquare(world, blockPos, direction) - || world.getBlockState(blockPos).isIn(BlockTags.LEAVES); + return canSupportCenter(world, blockPos, direction) || world.getBlockState(blockPos).is(BlockTags.LEAVES); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } } diff --git a/src/main/java/ru/betterend/blocks/basis/BarkBlock.java b/src/main/java/ru/betterend/blocks/basis/BarkBlock.java index 36b39146..1b82913c 100644 --- a/src/main/java/ru/betterend/blocks/basis/BarkBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/BarkBlock.java @@ -1,28 +1,27 @@ package ru.betterend.blocks.basis; import java.io.Reader; - -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import ru.betterend.patterns.Patterns; public class BarkBlock extends EndPillarBlock { public BarkBlock(Properties settings) { super(settings); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BASE, getName(blockId), blockId.getPath()); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, getName(blockId), blockId.getPath()); } - + private String getName(ResourceLocation blockId) { String name = blockId.getPath(); return name.replace("_bark", "_log_side"); diff --git a/src/main/java/ru/betterend/blocks/basis/BaseBlockWithEntity.java b/src/main/java/ru/betterend/blocks/basis/BaseBlockWithEntity.java index 9f4ead5f..f8a8b656 100644 --- a/src/main/java/ru/betterend/blocks/basis/BaseBlockWithEntity.java +++ b/src/main/java/ru/betterend/blocks/basis/BaseBlockWithEntity.java @@ -2,24 +2,23 @@ package ru.betterend.blocks.basis; import java.util.Collections; import java.util.List; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.BlockWithEntity; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; -public class BaseBlockWithEntity extends BlockWithEntity { +public class BaseBlockWithEntity extends BaseEntityBlock { public BaseBlockWithEntity(Properties settings) { super(settings); } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return null; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); diff --git a/src/main/java/ru/betterend/blocks/basis/BlockBase.java b/src/main/java/ru/betterend/blocks/basis/BlockBase.java index 04dddbf3..05f59723 100644 --- a/src/main/java/ru/betterend/blocks/basis/BlockBase.java +++ b/src/main/java/ru/betterend/blocks/basis/BlockBase.java @@ -3,10 +3,9 @@ package ru.betterend.blocks.basis; import java.io.Reader; import java.util.Collections; import java.util.List; - import net.minecraft.core.Registry; -import net.minecraft.world.item.ItemStack; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; @@ -17,24 +16,24 @@ public class BlockBase extends Block implements BlockPatterned { public BlockBase(Properties settings) { super(settings); } - + @Override - public List getDrops(BlockState blockState, LootContext.Builder builder) { + public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/basis/BlockBaseNotFull.java b/src/main/java/ru/betterend/blocks/basis/BlockBaseNotFull.java index 34d51d6f..754b09b0 100644 --- a/src/main/java/ru/betterend/blocks/basis/BlockBaseNotFull.java +++ b/src/main/java/ru/betterend/blocks/basis/BlockBaseNotFull.java @@ -1,9 +1,9 @@ package ru.betterend.blocks.basis; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.state.BlockState; public class BlockBaseNotFull extends BlockBase { @@ -11,15 +11,15 @@ public class BlockBaseNotFull extends BlockBase { super(settings); } - public boolean canSuffocate(BlockState state, BlockView view, BlockPos pos) { + public boolean canSuffocate(BlockState state, BlockGetter view, BlockPos pos) { return false; } - public boolean isSimpleFullBlock(BlockState state, BlockView view, BlockPos pos) { + public boolean isSimpleFullBlock(BlockState state, BlockGetter view, BlockPos pos) { return false; } - public boolean allowsSpawning(BlockState state, BlockView view, BlockPos pos, EntityType type) { + public boolean allowsSpawning(BlockState state, BlockGetter view, BlockPos pos, EntityType type) { return false; } } diff --git a/src/main/java/ru/betterend/blocks/basis/DoublePlantBlock.java b/src/main/java/ru/betterend/blocks/basis/DoublePlantBlock.java index a997b782..a1c09b06 100644 --- a/src/main/java/ru/betterend/blocks/basis/DoublePlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/DoublePlantBlock.java @@ -7,143 +7,147 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; -public class DoublePlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 2, 4, 12, 16, 12); +public class DoublePlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock { + private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); public static final IntegerProperty ROTATION = BlockProperties.ROTATION; - public static final BooleanProperty TOP = BooleanProperty.of("top"); - + public static final BooleanProperty TOP = BooleanProperty.create("top"); + public DoublePlantBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS) - .breakByHand(true).noCollision()); - this.setDefaultState(this.stateManager.defaultBlockState().with(TOP, false)); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .noCollission()); + this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); } - + public DoublePlantBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS) - .luminance((state) -> { - return state.getValue(TOP) ? light : 0; - }).breakByHand(true).noCollision()); - this.setDefaultState(this.stateManager.defaultBlockState().with(TOP, false)); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .lightLevel((state) -> state.getValue(TOP) ? light : 0) + .noCollission()); + this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(TOP, ROTATION); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); - return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); + return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.XZ; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.XZ; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); - BlockState up = world.getBlockState(pos.up()); + BlockState up = world.getBlockState(pos.above()); return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getMaterial().isReplaceable()); } - - public boolean canStayAt(BlockState state, WorldView world, BlockPos pos) { + + public boolean canStayAt(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); - BlockState up = world.getBlockState(pos.up()); + BlockState up = world.getBlockState(pos.above()); return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getBlock() == this); } protected boolean isTerrain(BlockState state) { - return state.isIn(EndTags.END_GROUND); + return state.is(EndTags.END_GROUND); } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canStayAt(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(TOP)) { return Lists.newArrayList(); } - + ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(this)); - world.spawnEntity(item); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); + world.addFreshEntity(item); } - + @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { int rot = world.random.nextInt(4); - BlockState bs = this.defaultBlockState().with(ROTATION, rot); + BlockState bs = this.defaultBlockState().setValue(ROTATION, rot); BlocksHelper.setWithoutUpdate(world, pos, bs); - BlocksHelper.setWithoutUpdate(world, pos.up(), bs.with(TOP, true)); + BlocksHelper.setWithoutUpdate(world, pos.above(), bs.setValue(TOP, true)); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndAnvilBlock.java b/src/main/java/ru/betterend/blocks/basis/EndAnvilBlock.java index b45bca97..2cc44850 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndAnvilBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndAnvilBlock.java @@ -8,17 +8,17 @@ import java.util.Map; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.AnvilBlock; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.blocks.BlockProperties; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; @@ -26,37 +26,37 @@ import ru.betterend.patterns.Patterns; public class EndAnvilBlock extends AnvilBlock implements BlockPatterned { private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION; protected final int level; - + public EndAnvilBlock(MaterialColor color, int level) { super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color)); this.level = level; } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); builder.add(DESTRUCTION); } - public IntegerProperty getDESTRUCTION() { + public IntegerProperty getDestructionProperty() { return DESTRUCTION; } public int getCraftingLevel() { return level; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -73,7 +73,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned { char last = block.charAt(block.length() - 1); return blockId.getPath() + "_top_" + last; } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_ANVIL; diff --git a/src/main/java/ru/betterend/blocks/basis/EndBarrelBlock.java b/src/main/java/ru/betterend/blocks/basis/EndBarrelBlock.java index 6c00c5b5..96e02235 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndBarrelBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndBarrelBlock.java @@ -5,26 +5,26 @@ import java.util.List; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.BarrelBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockRenderType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.mob.PiglinBrain; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.stat.Stats; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.stats.Stats; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.piglin.PiglinAi; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BarrelBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.BlockHitResult; import ru.betterend.blocks.entities.EBarrelBlockEntity; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; @@ -32,12 +32,12 @@ import ru.betterend.registry.EndBlockEntities; public class EndBarrelBlock extends BarrelBlock implements BlockPatterned { public EndBarrelBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque()); + super(FabricBlockSettings.copyOf(source).noOcclusion()); } @Override - public BlockEntity createBlockEntity(BlockView world) { - return EndBlockEntities.BARREL.instantiate(); + public BlockEntity newBlockEntity(BlockGetter world) { + return EndBlockEntities.BARREL.create(); } @Override @@ -48,24 +48,24 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned { } @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (world.isClientSide) { - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } else { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EBarrelBlockEntity) { - player.openHandledScreen((EBarrelBlockEntity) blockEntity); - player.incrementStat(Stats.OPEN_BARREL); - PiglinBrain.onGuardedBlockInteracted(player, true); + player.openMenu((EBarrelBlockEntity) blockEntity); + player.awardStat(Stats.OPEN_BARREL); + PiglinAi.angerNearbyPiglins(player, true); } - return ActionResult.CONSUME; + return InteractionResult.CONSUME; } } @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EBarrelBlockEntity) { ((EBarrelBlockEntity) blockEntity).tick(); @@ -73,26 +73,27 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned { } @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.MODEL; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.MODEL; } @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { - if (itemStack.hasCustomName()) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, + ItemStack itemStack) { + if (itemStack.hasCustomHoverName()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EBarrelBlockEntity) { - ((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getName()); + ((EBarrelBlockEntity) blockEntity).setCustomName(itemStack.getHoverName()); } } } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { String texture = Registry.BLOCK.getKey(this).getPath(); @@ -101,7 +102,7 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_BARREL; diff --git a/src/main/java/ru/betterend/blocks/basis/EndBlockStripableLogLog.java b/src/main/java/ru/betterend/blocks/basis/EndBlockStripableLogLog.java index d7a62f60..99d73b01 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndBlockStripableLogLog.java +++ b/src/main/java/ru/betterend/blocks/basis/EndBlockStripableLogLog.java @@ -2,42 +2,40 @@ package ru.betterend.blocks.basis; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.RotatedPillarBlock; -import net.minecraft.world.entity.player.Player; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; public class EndBlockStripableLogLog extends EndPillarBlock { private final Block striped; - + public EndBlockStripableLogLog(MaterialColor color, Block striped) { super(FabricBlockSettings.copyOf(striped).materialColor(color)); this.striped = striped; } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (player.getMainHandStack().getItem().isIn(FabricToolTags.AXES)) { - world.playLocalSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) { + world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { - world.setBlockAndUpdate(pos, striped.defaultBlockState().with(RotatedPillarBlock.AXIS, - state.getValue(RotatedPillarBlock.AXIS)), 11); + world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11); if (player != null && !player.isCreative()) { - player.getMainHandStack().damage(1, world.random, (ServerPlayer) player); + player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player); } } - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndBookshelfBlock.java b/src/main/java/ru/betterend/blocks/basis/EndBookshelfBlock.java index 82688186..cbe352f3 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndBookshelfBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndBookshelfBlock.java @@ -5,23 +5,23 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.patterns.Patterns; public class EndBookshelfBlock extends BlockBase { public EndBookshelfBlock(Block source) { super(FabricBlockSettings.copyOf(source)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); @@ -33,24 +33,24 @@ public class EndBookshelfBlock extends BlockBase { } return Collections.singletonList(new ItemStack(Items.BOOK, 3)); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BOOKSHELF, getName(blockId), blockId.getPath()); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, getName(blockId), blockId.getPath()); } - + private String getName(ResourceLocation blockId) { String name = blockId.getPath(); return name.replace("_bookshelf", ""); diff --git a/src/main/java/ru/betterend/blocks/basis/EndChainBlock.java b/src/main/java/ru/betterend/blocks/basis/EndChainBlock.java index a28dac5e..1b03516c 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndChainBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndChainBlock.java @@ -5,14 +5,14 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.ChainBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; @@ -22,18 +22,18 @@ public class EndChainBlock extends ChainBlock implements BlockPatterned, IRender public EndChainBlock(MaterialColor color) { super(FabricBlockSettings.copyOf(Blocks.CHAIN).materialColor(color)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -42,12 +42,12 @@ public class EndChainBlock extends ChainBlock implements BlockPatterned, IRender } return Patterns.createJson(Patterns.BLOCK_CHAIN, blockId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_CHAIN; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; diff --git a/src/main/java/ru/betterend/blocks/basis/EndChestBlock.java b/src/main/java/ru/betterend/blocks/basis/EndChestBlock.java index d146316f..a7d6344a 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndChestBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndChestBlock.java @@ -4,48 +4,50 @@ import java.io.Reader; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.ChestBlock; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; -import net.minecraft.world.level.BlockGetter; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; import ru.betterend.registry.EndBlockEntities; public class EndChestBlock extends ChestBlock implements BlockPatterned { private final Block parent; - + public EndChestBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque(), () -> { + super(FabricBlockSettings.copyOf(source).noOcclusion(), () -> { return EndBlockEntities.CHEST; }); this.parent = source; } - + @Override - public BlockEntity createBlockEntity(BlockView world) { - return EndBlockEntities.CHEST.instantiate(); + public BlockEntity newBlockEntity(BlockGetter world) + { + return EndBlockEntities.CHEST.create(); } - + @Override - public List getDrops(BlockState state, LootContext.Builder builder) { + public List getDrops(BlockState state, LootContext.Builder builder) + { List drop = super.getDrops(state, builder); drop.add(new ItemStack(this.asItem())); return drop; } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String path) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -55,7 +57,7 @@ public class EndChestBlock extends ChestBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndComposterBlock.java b/src/main/java/ru/betterend/blocks/basis/EndComposterBlock.java index db82d4bd..fdf45dff 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndComposterBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndComposterBlock.java @@ -5,13 +5,13 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ComposterBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.ComposterBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; @@ -19,25 +19,25 @@ public class EndComposterBlock extends ComposterBlock implements BlockPatterned public EndComposterBlock(Block source) { super(FabricBlockSettings.copyOf(source)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this.asItem())); } - + @Override public String getStatesPattern(Reader data) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, blockId, blockId); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); String blockName = blockId.getPath(); return Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockName); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_COMPOSTER; diff --git a/src/main/java/ru/betterend/blocks/basis/EndCraftingTableBlock.java b/src/main/java/ru/betterend/blocks/basis/EndCraftingTableBlock.java index 2e8da6d9..0f930b7f 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndCraftingTableBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndCraftingTableBlock.java @@ -6,13 +6,13 @@ import java.util.HashMap; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.CraftingTableBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CraftingTableBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; @@ -25,13 +25,13 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this.asItem())); } - + @Override public String getStatesPattern(Reader data) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, blockId, blockId); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -49,7 +49,7 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa } }); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndCropBlock.java b/src/main/java/ru/betterend/blocks/basis/EndCropBlock.java index e8e75e3c..8413c649 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndCropBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndCropBlock.java @@ -8,59 +8,63 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Mth; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; public class EndCropBlock extends EndPlantBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(2, 0, 2, 14, 14, 14); - public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 3); - + private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); + public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); + private final Block[] terrain; private final Item drop; - + public EndCropBlock(Item drop, Block... terrain) { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).sounds(SoundType.GRASS) - .breakByHand(true).ticksRandomly().noCollision()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.HOES) + .breakByHand(true) + .sound(SoundType.GRASS) + .randomTicks() + .noCollission()); this.drop = drop; this.terrain = terrain; - this.setDefaultState(getDefaultState().with(AGE, 0)); + this.registerDefaultState(defaultBlockState().setValue(AGE, 0)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(AGE); } - + @Override protected boolean isTerrain(BlockState state) { - for (Block block : terrain) { + for (Block block: terrain) { if (state.is(block)) { return true; } } return false; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(AGE) < 3) { @@ -79,40 +83,40 @@ public class EndCropBlock extends EndPlantBlock { int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM); return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops)); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { int age = state.getValue(AGE); if (age < 3) { - BlocksHelper.setWithUpdate(world, pos, state.with(AGE, age + 1)); + BlocksHelper.setWithUpdate(world, pos, state.setValue(AGE, age + 1)); } } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return state.getValue(AGE) < 3; } - + @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return state.getValue(AGE) < 3; } - + @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - super.scheduledTick(state, world, pos, random); - if (canGrow(world, random, pos, state) && random.nextInt(8) == 0) { - grow(world, random, pos, state); + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + super.tick(state, world, pos, random); + if (isBonemealSuccess(world, random, pos, state) && random.nextInt(8) == 0) { + performBonemeal(world, random, pos, state); } } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndDoorBlock.java b/src/main/java/ru/betterend/blocks/basis/EndDoorBlock.java index 8d6d21f8..edd17f80 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndDoorBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndDoorBlock.java @@ -5,14 +5,14 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.DoorBlock; -import net.minecraft.world.level.block.enums.DoubleBlockHalf; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; @@ -20,7 +20,7 @@ import ru.betterend.patterns.Patterns; public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPatterned { public EndDoorBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(3F, 3F).nonOpaque()); + super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); } @Override @@ -35,13 +35,13 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPat public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public String getStatesPattern(Reader data) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, blockId, blockId); } - + @Override public String getModelPattern(String block) { String blockId = Registry.BLOCK.getKey(this).getPath(); @@ -59,7 +59,7 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPat } return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockId, blockId); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_DOOR; diff --git a/src/main/java/ru/betterend/blocks/basis/EndFenceBlock.java b/src/main/java/ru/betterend/blocks/basis/EndFenceBlock.java index 30c55f1c..513214fd 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndFenceBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndFenceBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FenceBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.FenceBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndFenceBlock extends FenceBlock implements BlockPatterned { private final Block parent; - + public EndFenceBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque()); + super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } @@ -27,14 +27,14 @@ public class EndFenceBlock extends FenceBlock implements BlockPatterned { public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -47,7 +47,7 @@ public class EndFenceBlock extends FenceBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_FENCE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndFurnaceBlock.java b/src/main/java/ru/betterend/blocks/basis/EndFurnaceBlock.java index a4666eb8..dee166a3 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndFurnaceBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndFurnaceBlock.java @@ -8,21 +8,21 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FurnaceBlock; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.stat.Stats; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.stats.Stats; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.FurnaceBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.betterend.blocks.entities.EFurnaceBlockEntity; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; @@ -31,31 +31,31 @@ import ru.betterend.patterns.Patterns; public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRenderTypeable { public EndFurnaceBlock(Block source) { - super(FabricBlockSettings.copyOf(source).luminance((state) -> { + super(FabricBlockSettings.copyOf(source).lightLevel((state) -> { return state.getValue(LIT) ? 13 : 0; })); } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new EFurnaceBlockEntity(); } - + @Override - protected void openScreen(Level world, BlockPos pos, Player player) { + protected void openContainer(Level world, BlockPos pos, Player player) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof EFurnaceBlockEntity) { - player.openHandledScreen((NamedScreenHandlerFactory) blockEntity); - player.incrementStat(Stats.INTERACT_WITH_FURNACE); + player.openMenu((MenuProvider) blockEntity); + player.awardStat(Stats.INTERACT_WITH_FURNACE); } } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -66,12 +66,13 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRe map.put("%front%", blockId.getPath() + "_front_on"); map.put("%glow%", blockId.getPath() + "_glow"); return Patterns.createJson(Patterns.BLOCK_FURNACE_GLOW, map); - } else { + } + else { map.put("%front%", blockId.getPath() + "_front"); return Patterns.createJson(Patterns.BLOCK_FURNACE, map); } } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_FURNACE; @@ -81,15 +82,15 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRe public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { List drop = Lists.newArrayList(new ItemStack(this)); - BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); + BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); if (blockEntity instanceof EFurnaceBlockEntity) { EFurnaceBlockEntity entity = (EFurnaceBlockEntity) blockEntity; - for (int i = 0; i < entity.size(); i++) { - drop.add(entity.getStack(i)); + for (int i = 0; i < entity.getContainerSize(); i++) { + drop.add(entity.getItem(i)); } } return drop; diff --git a/src/main/java/ru/betterend/blocks/basis/EndGateBlock.java b/src/main/java/ru/betterend/blocks/basis/EndGateBlock.java index ed2946e7..156407c2 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndGateBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndGateBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FenceGateBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.FenceGateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndGateBlock extends FenceGateBlock implements BlockPatterned { private final Block parent; - + public EndGateBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque()); + super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } @@ -27,14 +27,14 @@ public class EndGateBlock extends FenceGateBlock implements BlockPatterned { public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -51,7 +51,7 @@ public class EndGateBlock extends FenceGateBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_GATE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndLadderBlock.java b/src/main/java/ru/betterend/blocks/basis/EndLadderBlock.java index acc5ca29..505b3ae9 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndLadderBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndLadderBlock.java @@ -3,28 +3,28 @@ package ru.betterend.blocks.basis; import java.io.Reader; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.HorizontalFacingBlock; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; @@ -32,15 +32,15 @@ import ru.betterend.patterns.Patterns; import ru.betterend.util.BlocksHelper; public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, BlockPatterned { - public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - protected static final VoxelShape EAST_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D); - protected static final VoxelShape WEST_SHAPE = Block.createCuboidShape(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); - protected static final VoxelShape SOUTH_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D); - protected static final VoxelShape NORTH_SHAPE = Block.createCuboidShape(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D); + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D); + protected static final VoxelShape WEST_SHAPE = Block.box(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); + protected static final VoxelShape SOUTH_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D); + protected static final VoxelShape NORTH_SHAPE = Block.box(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D); public EndLadderBlock(Block block) { - super(FabricBlockSettings.copyOf(block).nonOpaque()); + super(FabricBlockSettings.copyOf(block).noOcclusion()); } @Override @@ -49,7 +49,7 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, stateManager.add(WATERLOGGED); } - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { switch (state.getValue(FACING)) { case SOUTH: return SOUTH_SHAPE; @@ -62,25 +62,25 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, } } - private boolean canPlaceOn(BlockView world, BlockPos pos, Direction side) { + private boolean canPlaceOn(BlockGetter world, BlockPos pos, Direction side) { BlockState blockState = world.getBlockState(pos); - return !blockState.emitsRedstonePower() && blockState.isSideSolidFullSquare(world, pos, side); + return !blockState.isSignalSource() && blockState.isFaceSturdy(world, pos, side); } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); return this.canPlaceOn(world, pos.relative(direction.getOpposite()), direction); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (facing.getOpposite() == state.getValue(FACING) && !state.canPlaceAt(world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, + LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(world, pos)) { return Blocks.AIR.defaultBlockState(); } else { if ((Boolean) state.getValue(WATERLOGGED)) { - world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return super.updateShape(state, facing, neighborState, world, pos, neighborPos); @@ -88,28 +88,28 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, } @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { BlockState blockState2; - if (!ctx.canReplaceExisting()) { - blockState2 = ctx.getLevel().getBlockState(ctx.getBlockPos().offset(ctx.getSide().getOpposite())); - if (blockState2.getBlock() == this && blockState2.get(FACING) == ctx.getSide()) { + if (!ctx.replacingClickedOnBlock()) { + blockState2 = ctx.getLevel().getBlockState(ctx.getClickedPos().relative(ctx.getClickedFace().getOpposite())); + if (blockState2.getBlock() == this && blockState2.getValue(FACING) == ctx.getClickedFace()) { return null; } } blockState2 = this.defaultBlockState(); - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos()); - Direction[] var6 = ctx.getPlacementDirections(); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); + Direction[] var6 = ctx.getNearestLookingDirections(); int var7 = var6.length; for (int var8 = 0; var8 < var7; ++var8) { Direction direction = var6[var8]; if (direction.getAxis().isHorizontal()) { - blockState2 = (BlockState) blockState2.with(FACING, direction.getOpposite()); - if (blockState2.canPlaceAt(worldView, blockPos)) { - return (BlockState) blockState2.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER); + blockState2 = (BlockState) blockState2.setValue(FACING, direction.getOpposite()); + if (blockState2.canSurvive(worldView, blockPos)) { + return (BlockState) blockState2.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); } } } @@ -123,26 +123,26 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } @Override public FluidState getFluidState(BlockState state) { - return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + return (Boolean) state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public String getStatesPattern(Reader data) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, blockId, blockId); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -151,7 +151,7 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, } return Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_LADDER; diff --git a/src/main/java/ru/betterend/blocks/basis/EndLanternBlock.java b/src/main/java/ru/betterend/blocks/basis/EndLanternBlock.java index 28505b8f..136a9e17 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndLanternBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndLanternBlock.java @@ -1,110 +1,119 @@ package ru.betterend.blocks.basis; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import ru.betterend.blocks.BlockProperties; -public class EndLanternBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable { +public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer { public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR; - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; - + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public EndLanternBlock(Block source) { - this(FabricBlockSettings.copyOf(source).luminance(15).nonOpaque()); + this(FabricBlockSettings.copyOf(source).luminance(15).noOcclusion()); } - - public EndLanternBlock(FabricBlockSettings settings) { - super(settings.nonOpaque()); + + public EndLanternBlock(Properties settings) { + super(settings.noOcclusion()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(IS_FLOOR, WATERLOGGED); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - Direction dir = ctx.getSide(); - boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + Direction dir = ctx.getClickedFace(); + boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER; if (dir != Direction.DOWN && dir != Direction.UP) { - if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) { - return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water); - } else if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) { - return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water); - } else { + if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) { + return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water); + } + else if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) { + return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water); + } + else { return null; } - } else if (dir == Direction.DOWN) { - if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) { - return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water); - } else if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) { - return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water); - } else { + } + else if (dir == Direction.DOWN) { + if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) { + return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water); + } + else if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) { + return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water); + } + else { return null; } - } else { - if (sideCoversSmallSquare(worldView, blockPos.below(), Direction.UP)) { - return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water); - } else if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) { - return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water); - } else { + } + else { + if (canSupportCenter(worldView, blockPos.below(), Direction.UP)) { + return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water); + } + else if (canSupportCenter(worldView, blockPos.above(), Direction.DOWN)) { + return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water); + } + else { return null; } } } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { if (state.getValue(IS_FLOOR)) { - return sideCoversSmallSquare(world, pos.below(), Direction.UP); - } else { - return sideCoversSmallSquare(world, pos.up(), Direction.DOWN); + return canSupportCenter(world, pos.below(), Direction.UP); + } + else { + return canSupportCenter(world, pos.above(), Direction.DOWN); } } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { Boolean water = state.getValue(WATERLOGGED); if (water) { - world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } - if (!canPlaceAt(state, world, pos)) { + if (!canSurvive(state, world, pos)) { return water ? Blocks.WATER.defaultBlockState() : Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override public FluidState getFluidState(BlockState state) { - return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState(); + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndLeavesBlock.java b/src/main/java/ru/betterend/blocks/basis/EndLeavesBlock.java index b5b45e92..4e9509ca 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndLeavesBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndLeavesBlock.java @@ -8,18 +8,18 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; @@ -28,57 +28,58 @@ import ru.betterend.util.MHelper; public class EndLeavesBlock extends LeavesBlock implements BlockPatterned, IRenderTypeable { private final Block sapling; - + public EndLeavesBlock(Block sapling, MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning((state, world, pos, type) -> { - return false; - }).suffocates((state, world, pos) -> { - return false; - }).blockVision((state, world, pos) -> { - return false; - }).materialColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true)); + super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) + .materialColor(color) + .breakByTool(FabricToolTags.HOES) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false)); this.sapling = sapling; } - + public EndLeavesBlock(Block sapling, MaterialColor color, int light) { - super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning((state, world, pos, type) -> { - return false; - }).suffocates((state, world, pos) -> { - return false; - }).blockVision((state, world, pos) -> { - return false; - }).materialColor(color).luminance(light).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS)); + super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) + .materialColor(color) + .luminance(light) + .breakByTool(FabricToolTags.HOES) + .breakByTool(FabricToolTags.SHEARS) + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false)); this.sapling = sapling; } - + @Override public String getStatesPattern(Reader data) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, blockId, blockId); } - + @Override public String getModelPattern(String block) { String blockId = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(Patterns.BLOCK_BASE, blockId, blockId); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); if (tool != null) { - if (tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Collections.singletonList(new ItemStack(this)); } int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); diff --git a/src/main/java/ru/betterend/blocks/basis/EndMetalPaneBlock.java b/src/main/java/ru/betterend/blocks/basis/EndMetalPaneBlock.java index a83998c1..a10f97ff 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndMetalPaneBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndMetalPaneBlock.java @@ -7,35 +7,35 @@ import java.util.List; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.PaneBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.IronBarsBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; -public class EndMetalPaneBlock extends PaneBlock implements BlockPatterned, IRenderTypeable { +public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned, IRenderTypeable { public EndMetalPaneBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).nonOpaque()); + super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); } @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -44,24 +44,25 @@ public class EndMetalPaneBlock extends PaneBlock implements BlockPatterned, IRen } if (block.contains("post")) { return Patterns.createJson(Patterns.BLOCK_BARS_POST, blockId.getPath(), blockId.getPath()); - } else { + } + else { return Patterns.createJson(Patterns.BLOCK_BARS_SIDE, blockId.getPath(), blockId.getPath()); } } - + @Environment(EnvType.CLIENT) - public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) { + public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) { if (direction.getAxis().isVertical() && stateFrom.getBlock().is(this) && !stateFrom.equals(state)) { return false; } - return super.isSideInvisible(state, stateFrom, direction); + return super.skipRendering(state, stateFrom, direction); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_BARS; } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; diff --git a/src/main/java/ru/betterend/blocks/basis/EndMetalPlateBlock.java b/src/main/java/ru/betterend/blocks/basis/EndMetalPlateBlock.java index 17a54773..307dda00 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndMetalPlateBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndMetalPlateBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.WeightedPressurePlateBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.WeightedPressurePlateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements BlockPatterned { private final Block parent; - + public EndMetalPlateBlock(Block source) { - super(15, FabricBlockSettings.copyOf(source).noCollision().nonOpaque().requiresTool().strength(0.5F)); + super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F)); this.parent = source; } @@ -27,14 +27,14 @@ public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements Bl public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -44,7 +44,7 @@ public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements Bl } return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_PLATE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndOreBlock.java b/src/main/java/ru/betterend/blocks/basis/EndOreBlock.java index 7e9750d0..74c0bbb7 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndOreBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndOreBlock.java @@ -6,20 +6,20 @@ import java.util.List; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.block.OreBlock; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.OreBlock; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.core.Registry; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; import ru.betterend.util.MHelper; @@ -29,18 +29,21 @@ public class EndOreBlock extends OreBlock implements BlockPatterned { private final int minCount; private final int maxCount; private final int expirience; - + public EndOreBlock(Item drop, int minCount, int maxCount, int expirience) { - super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresTool() - .sounds(SoundType.STONE)); + super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) + .hardness(3F) + .resistance(9F) + .requiresCorrectToolForDrops() + .sound(SoundType.STONE)); this.dropItem = drop; this.minCount = minCount; this.maxCount = maxCount; this.expirience = expirience; } - + @Override - protected int getExperienceWhenMined(Random random) { + protected int xpOnDrop(Random random) { return this.expirience > 0 ? random.nextInt(expirience) + 1 : 0; } @@ -67,19 +70,19 @@ public class EndOreBlock extends OreBlock implements BlockPatterned { } return Collections.emptyList(); } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/basis/EndPillarBlock.java b/src/main/java/ru/betterend/blocks/basis/EndPillarBlock.java index 492115fd..82e02e7a 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndPillarBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndPillarBlock.java @@ -5,13 +5,13 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.RotatedPillarBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RotatedPillarBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; @@ -19,28 +19,28 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockPatterned public EndPillarBlock(Properties settings) { super(settings); } - + public EndPillarBlock(Block block) { super(FabricBlockSettings.copyOf(block)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { String texture = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, texture, texture); } - + @Override public String getModelPattern(String block) { String texture = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(Patterns.BLOCK_PILLAR, texture, texture); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_PILLAR; diff --git a/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java index da0e6a7e..bf785d30 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndPlantBlock.java @@ -7,120 +7,125 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.registry.EndTags; -public class EndPlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12); - +public class EndPlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock { + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); + public EndPlantBlock() { this(false); } - + public EndPlantBlock(int light) { this(false, light); } - + public EndPlantBlock(boolean replaceable) { super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true).noCollision()); + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission()); } - + public EndPlantBlock(boolean replaceable, int light) { super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).luminance(light).breakByHand(true) - .noCollision()); + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(light) + .sound(SoundType.GRASS) + .noCollission()); } - + public EndPlantBlock(Properties settings) { super(settings); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); - return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); + return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.XZ; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.XZ; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); return isTerrain(down); } - + protected boolean isTerrain(BlockState state) { - return state.isIn(EndTags.END_GROUND); + return state.is(EndTags.END_GROUND); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(this)); - world.spawnEntity(item); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); + world.addFreshEntity(item); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndPlantWithAgeBlock.java b/src/main/java/ru/betterend/blocks/basis/EndPlantWithAgeBlock.java index f02774d4..ed6bc623 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndPlantWithAgeBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndPlantWithAgeBlock.java @@ -4,57 +4,62 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; +import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.Level; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.BlockProperties; public abstract class EndPlantWithAgeBlock extends EndPlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; - + public EndPlantWithAgeBlock() { - this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS) - .breakByHand(true).ticksRandomly().noCollision()); + this(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .randomTicks() + .noCollission()); } - - public EndPlantWithAgeBlock(FabricBlockSettings settings) { + + public EndPlantWithAgeBlock(Properties settings) { super(settings); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(AGE); } - + public abstract void growAdult(WorldGenLevel world, Random random, BlockPos pos); - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { int age = state.getValue(AGE); if (age < 3) { - world.setBlockAndUpdate(pos, state.with(AGE, age + 1)); - } else { + world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1)); + } + else { growAdult(world, random, pos); } } - + @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } - + @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - super.scheduledTick(state, world, pos, random); + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + super.tick(state, world, pos, random); if (random.nextInt(8) == 0) { - grow(world, random, pos, state); + performBonemeal(world, random, pos, state); } } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndPlateBlock.java b/src/main/java/ru/betterend/blocks/basis/EndPlateBlock.java index 9bf2a9b6..a178faad 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndPlateBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndPlateBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.PressurePlateBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.PressurePlateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned { private final Block parent; - - public EndPlateBlock(ActivationRule rule, Block source) { - super(rule, FabricBlockSettings.copyOf(source).noCollision().nonOpaque().strength(0.5F)); + + public EndPlateBlock(Sensitivity rule, Block source) { + super(rule, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().strength(0.5F)); this.parent = source; } @@ -27,14 +27,14 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -44,9 +44,9 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned } return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { - return this.stateManager.getProperty("facing") != null ? Patterns.STATE_PLATE_ROTATED : Patterns.STATE_PLATE; + return this.stateDefinition.getProperty("facing") != null ? Patterns.STATE_PLATE_ROTATED : Patterns.STATE_PLATE; } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndSignBlock.java b/src/main/java/ru/betterend/blocks/basis/EndSignBlock.java index 539ba8f9..eca5c594 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndSignBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndSignBlock.java @@ -5,39 +5,39 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.SignBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.SignType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.Mth; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SignBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.block.state.properties.WoodType; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.entities.ESignBlockEntity; import ru.betterend.interfaces.ISpetialItem; import ru.betterend.patterns.BlockPatterned; @@ -45,20 +45,20 @@ import ru.betterend.patterns.Patterns; import ru.betterend.util.BlocksHelper; public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialItem { - public static final IntegerProperty ROTATION = Properties.ROTATION; - public static final BooleanProperty FLOOR = BooleanProperty.of("floor"); + public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; + public static final BooleanProperty FLOOR = BooleanProperty.create("floor"); private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] { - Block.createCuboidShape(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D), - Block.createCuboidShape(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D), - Block.createCuboidShape(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D), - Block.createCuboidShape(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D) }; + Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D), + Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D), + Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D), + Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D) + }; private final Block parent; - + public EndSignBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollision().nonOpaque(), SignType.OAK); - this.setDefaultState( - this.stateManager.defaultBlockState().with(ROTATION, 0).with(FLOOR, false).with(WATERLOGGED, false)); + super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK); + this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false)); this.parent = source; } @@ -68,72 +68,74 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(FLOOR) ? SHAPE : WALL_SHAPES[state.getValue(ROTATION) >> 2]; } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new ESignBlockEntity(); } - + @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { if (placer != null && placer instanceof Player) { ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos); if (!world.isClientSide) { - sign.setEditor((Player) placer); - ((ServerPlayer) placer).networkHandler.sendPacket(new SignEditorOpenS2CPacket(pos)); - } else { + sign.setAllowedPlayerEditor((Player) placer); + ((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos)); + } + else { sign.setEditable(true); } } } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if ((Boolean) state.getValue(WATERLOGGED)) { - world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } - if (!canPlaceAt(state, world, pos)) { - return state.getValue(WATERLOGGED) ? state.getFluidState().getBlockState() : Blocks.AIR.defaultBlockState(); + if (!canSurvive(state, world, pos)) { + return state.getValue(WATERLOGGED) ? state.getFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState(); } return super.updateShape(state, facing, neighborState, world, pos, neighborPos); } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { if (!state.getValue(FLOOR)) { int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3; return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).getMaterial().isSolid(); - } else { + } + else { return world.getBlockState(pos.below()).getMaterial().isSolid(); } } @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - if (ctx.getSide() == Direction.UP) { - FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos()); - return this.defaultBlockState().with(FLOOR, true) - .with(ROTATION, Mth.floor((180.0 + ctx.getPlayerYaw() * 16.0 / 360.0) + 0.5 - 12) & 15) - .with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER); - } else if (ctx.getSide() != Direction.DOWN) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + if (ctx.getClickedFace() == Direction.UP) { + FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); + return this.defaultBlockState().setValue(FLOOR, true) + .setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15) + .setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); + } + else if (ctx.getClickedFace() != Direction.DOWN) { BlockState blockState = this.defaultBlockState(); - FluidState fluidState = ctx.getLevel().getFluidState(ctx.getBlockPos()); - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - Direction[] directions = ctx.getPlacementDirections(); + FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + Direction[] directions = ctx.getNearestLookingDirections(); for (int i = 0; i < directions.length; ++i) { Direction direction = directions[i]; if (direction.getAxis().isHorizontal()) { Direction dir = direction.getOpposite(); - int rot = Mth.floor((180.0 + dir.asRotation() * 16.0 / 360.0) + 0.5 + 4) & 15; - blockState = blockState.with(ROTATION, rot); - if (blockState.canPlaceAt(worldView, blockPos)) { - return blockState.with(FLOOR, false).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER); + int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15; + blockState = blockState.setValue(ROTATION, rot); + if (blockState.canSurvive(worldView, blockPos)) { + return blockState.setValue(FLOOR, false).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); } } } @@ -141,14 +143,14 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI return null; } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String path) { ResourceLocation parentId = Registry.BLOCK.getKey(parent); @@ -157,41 +159,41 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI } return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { - return (BlockState) state.with(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16)); + return (BlockState) state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16)); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { - return (BlockState) state.with(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16)); + public BlockState mirror(BlockState state, Mirror mirror) { + return (BlockState) state.setValue(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } @Override - public Fluid tryDrainFluid(LevelAccessor world, BlockPos pos, BlockState state) { + public Fluid takeLiquid(LevelAccessor world, BlockPos pos, BlockState state) { // TODO Auto-generated method stub return null; } @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { // TODO Auto-generated method stub return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { // TODO Auto-generated method stub return false; } diff --git a/src/main/java/ru/betterend/blocks/basis/EndSlabBlock.java b/src/main/java/ru/betterend/blocks/basis/EndSlabBlock.java index 59139636..ef75cac8 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndSlabBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndSlabBlock.java @@ -5,19 +5,19 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.SlabBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SlabBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndSlabBlock extends SlabBlock implements BlockPatterned { private final Block parent; - + public EndSlabBlock(Block source) { super(FabricBlockSettings.copyOf(source)); this.parent = source; @@ -27,21 +27,21 @@ public class EndSlabBlock extends SlabBlock implements BlockPatterned { public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SLAB; diff --git a/src/main/java/ru/betterend/blocks/basis/EndStairsBlock.java b/src/main/java/ru/betterend/blocks/basis/EndStairsBlock.java index def04b1c..98d020cd 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndStairsBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndStairsBlock.java @@ -5,38 +5,37 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.StairsBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.StairBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; -public class EndStairsBlock extends StairsBlock implements BlockPatterned { - +public class EndStairsBlock extends StairBlock implements BlockPatterned { + private final Block parent; - + public EndStairsBlock(Block source) { super(source.defaultBlockState(), FabricBlockSettings.copyOf(source)); this.parent = source; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -49,7 +48,7 @@ public class EndStairsBlock extends StairsBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_STAIRS; diff --git a/src/main/java/ru/betterend/blocks/basis/EndStoneButtonBlock.java b/src/main/java/ru/betterend/blocks/basis/EndStoneButtonBlock.java index e8e51ec5..538d06f8 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndStoneButtonBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndStoneButtonBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.StoneButtonBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.StoneButtonBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatterned { private final Block parent; - + public EndStoneButtonBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque()); + super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } @@ -27,14 +27,14 @@ public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatter public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -47,7 +47,7 @@ public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatter } return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_BUTTON; diff --git a/src/main/java/ru/betterend/blocks/basis/EndStonelateBlock.java b/src/main/java/ru/betterend/blocks/basis/EndStonelateBlock.java index 80a39785..16b16f0e 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndStonelateBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndStonelateBlock.java @@ -4,6 +4,6 @@ import net.minecraft.world.level.block.Block; public class EndStonelateBlock extends EndPlateBlock { public EndStonelateBlock(Block source) { - super(ActivationRule.MOBS, source); + super(Sensitivity.MOBS, source); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndTrapdoorBlock.java b/src/main/java/ru/betterend/blocks/basis/EndTrapdoorBlock.java index 25330f0a..626beccd 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndTrapdoorBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndTrapdoorBlock.java @@ -6,39 +6,39 @@ import java.util.HashMap; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.TrapdoorBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; -public class EndTrapdoorBlock extends TrapdoorBlock implements IRenderTypeable, BlockPatterned { +public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable, BlockPatterned { public EndTrapdoorBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).nonOpaque()); + super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); } @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, block, block); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -51,7 +51,7 @@ public class EndTrapdoorBlock extends TrapdoorBlock implements IRenderTypeable, } }); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_TRAPDOOR; diff --git a/src/main/java/ru/betterend/blocks/basis/EndUnderwaterWallPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/EndUnderwaterWallPlantBlock.java index e838ac46..656e7898 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndUnderwaterWallPlantBlock.java @@ -2,51 +2,58 @@ package ru.betterend.blocks.basis; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; - -public class EndUnderwaterWallPlantBlock extends EndWallPlantBlock implements FluidFillable { +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +public class EndUnderwaterWallPlantBlock extends EndWallPlantBlock implements LiquidBlockContainer { + public EndUnderwaterWallPlantBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .noCollission()); } - + public EndUnderwaterWallPlantBlock(int light) { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).luminance(light).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(light) + .sound(SoundType.WET_GRASS) + .noCollission()); } - + public EndUnderwaterWallPlantBlock(Properties settings) { super(settings); } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override public FluidState getFluidState(BlockState state) { - return Fluids.WATER.getStill(false); + return Fluids.WATER.getSource(false); } - + @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return world.getFluidState(pos).getFluid() == Fluids.WATER && super.canPlaceAt(state, world, pos); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return world.getFluidState(pos).getType() == Fluids.WATER && super.canSurvive(state, world, pos); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndWallBlock.java b/src/main/java/ru/betterend/blocks/basis/EndWallBlock.java index b95c3c18..c8e51c77 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndWallBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndWallBlock.java @@ -5,22 +5,22 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.WallBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.WallBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; public class EndWallBlock extends WallBlock implements BlockPatterned { - + private final Block parent; - + public EndWallBlock(Block source) { - super(FabricBlockSettings.copyOf(source).nonOpaque()); + super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } @@ -28,14 +28,14 @@ public class EndWallBlock extends WallBlock implements BlockPatterned { public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -51,7 +51,7 @@ public class EndWallBlock extends WallBlock implements BlockPatterned { } return Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_WALL; diff --git a/src/main/java/ru/betterend/blocks/basis/EndWallPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/EndWallPlantBlock.java index 25848862..69357296 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndWallPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndWallPlantBlock.java @@ -7,87 +7,95 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.HorizontalFacingBlock; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.util.BlocksHelper; public class EndWallPlantBlock extends EndPlantBlock { - private static final EnumMap SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, - Block.createCuboidShape(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.createCuboidShape(1, 1, 0, 15, 15, 8), - Direction.WEST, Block.createCuboidShape(8, 1, 1, 16, 15, 15), Direction.EAST, - Block.createCuboidShape(0, 1, 1, 8, 15, 15))); - public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; - + private static final EnumMap SHAPES = Maps.newEnumMap(ImmutableMap.of( + Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16), + Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8), + Direction.WEST, Block.box(8, 1, 1, 16, 15, 15), + Direction.EAST, Block.box(0, 1, 1, 8, 15, 15))); + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; + public EndWallPlantBlock() { - this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS) - .breakByHand(true).noCollision()); + this(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission()); } - + public EndWallPlantBlock(int light) { - this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS) - .luminance(light).breakByHand(true).noCollision()); + this(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(light) + .sound(SoundType.GRASS) + .noCollission()); } - + public EndWallPlantBlock(Properties settings) { super(settings); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(FACING); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPES.get(state.getValue(FACING)); } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = (Direction) state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); BlockState blockState = world.getBlockState(blockPos); return isSupport(world, blockPos, blockState, direction); } - - public boolean isSupport(WorldView world, BlockPos pos, BlockState blockState, Direction direction) { - return blockState.getMaterial().isSolid() && blockState.isSideSolidFullSquare(world, pos, direction); + + public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) { + return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { + public BlockState getStateForPlacement(BlockPlaceContext ctx) { BlockState blockState = this.defaultBlockState(); - WorldView worldView = ctx.getLevel(); - BlockPos blockPos = ctx.getBlockPos(); - Direction[] directions = ctx.getPlacementDirections(); + LevelReader worldView = ctx.getLevel(); + BlockPos blockPos = ctx.getClickedPos(); + Direction[] directions = ctx.getNearestLookingDirections(); for (int i = 0; i < directions.length; ++i) { Direction direction = directions[i]; if (direction.getAxis().isHorizontal()) { Direction direction2 = direction.getOpposite(); - blockState = blockState.with(FACING, direction2); - if (blockState.canPlaceAt(worldView, blockPos)) { + blockState = blockState.setValue(FACING, direction2); + if (blockState.canSurvive(worldView, blockPos)) { return blockState; } } @@ -96,22 +104,22 @@ public class EndWallPlantBlock extends EndPlantBlock { } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } @Override - public BlockState mirror(BlockState state, BlockMirror mirror) { + public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } } diff --git a/src/main/java/ru/betterend/blocks/basis/EndWoodenButtonBlock.java b/src/main/java/ru/betterend/blocks/basis/EndWoodenButtonBlock.java index 67493ed2..a2455f6d 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndWoodenButtonBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndWoodenButtonBlock.java @@ -5,21 +5,21 @@ import java.util.Collections; import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.WoodenButtonBlock; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.WoodButtonBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.Patterns; -public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatterned { +public class EndWoodenButtonBlock extends WoodButtonBlock implements BlockPatterned { private final Block parent; - + public EndWoodenButtonBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).nonOpaque()); + super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion()); this.parent = source; } @@ -27,14 +27,14 @@ public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatt public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation parentId = Registry.BLOCK.getKey(parent); return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -47,7 +47,7 @@ public class EndWoodenButtonBlock extends WoodenButtonBlock implements BlockPatt } return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath()); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_BUTTON; diff --git a/src/main/java/ru/betterend/blocks/basis/EndWoodenPlateBlock.java b/src/main/java/ru/betterend/blocks/basis/EndWoodenPlateBlock.java index 005eba94..90454903 100644 --- a/src/main/java/ru/betterend/blocks/basis/EndWoodenPlateBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/EndWoodenPlateBlock.java @@ -4,6 +4,6 @@ import net.minecraft.world.level.block.Block; public class EndWoodenPlateBlock extends EndPlateBlock { public EndWoodenPlateBlock(Block source) { - super(ActivationRule.EVERYTHING, source); + super(Sensitivity.EVERYTHING, source); } } diff --git a/src/main/java/ru/betterend/blocks/basis/FeatureSaplingBlock.java b/src/main/java/ru/betterend/blocks/basis/FeatureSaplingBlock.java index d0527ed8..b5b4b11c 100644 --- a/src/main/java/ru/betterend/blocks/basis/FeatureSaplingBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/FeatureSaplingBlock.java @@ -4,97 +4,105 @@ import java.io.Reader; import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.Patterns; import ru.betterend.registry.EndTags; -public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements Fertilizable, IRenderTypeable { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12); - +public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements BonemealableBlock, IRenderTypeable { + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); + public FeatureSaplingBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).breakInstantly() - .sounds(SoundType.GRASS).ticksRandomly()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .collidable(false) + .instabreak() + .sound(SoundType.GRASS) + .randomTicks()); } - + public FeatureSaplingBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).breakInstantly() - .sounds(SoundType.GRASS).luminance(light).ticksRandomly()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .collidable(false) + .luminance(light) + .instabreak() + .sound(SoundType.GRASS) + .randomTicks()); } - + protected abstract Feature getFeature(); @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { - return world.getBlockState(pos.below()).isIn(EndTags.END_GROUND); + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { + return world.getBlockState(pos.below()).is(EndTags.END_GROUND); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) return Blocks.AIR.defaultBlockState(); else return state; } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return random.nextInt(16) == 0; } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - getFeature().place(world, world.getChunkManager().getChunkGenerator(), random, pos, null); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + getFeature().place(world, world.getChunkSource().getGenerator(), random, pos, null); } @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - super.scheduledTick(state, world, pos, random); - if (canGrow(world, random, pos, state)) { - grow(world, random, pos, state); + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + super.tick(state, world, pos, random); + if (isBonemealSuccess(world, random, pos, state)) { + performBonemeal(world, random, pos, state); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override public String getStatesPattern(Reader data) { ResourceLocation blockId = Registry.BLOCK.getKey(this); return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); } - + @Override public String getModelPattern(String block) { if (block.contains("item")) { @@ -103,7 +111,7 @@ public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements Fe } return Patterns.createJson(Patterns.BLOCK_CROSS, block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SAPLING; diff --git a/src/main/java/ru/betterend/blocks/basis/FurBlock.java b/src/main/java/ru/betterend/blocks/basis/FurBlock.java index bc516a93..01e4ef2c 100644 --- a/src/main/java/ru/betterend/blocks/basis/FurBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/FurBlock.java @@ -8,21 +8,21 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.level.ItemLike; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.util.MHelper; @@ -31,50 +31,58 @@ public class FurBlock extends AttachedBlock implements IRenderTypeable { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private final ItemLike drop; private final int dropChance; - + public FurBlock(ItemLike drop, int light, int dropChance, boolean wet) { - super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(wet ? SoundType.WET_GRASS : SoundType.GRASS).luminance(light).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(light) + .sound(wet ? SoundType.WET_GRASS : SoundType.GRASS) + .noCollission()); this.drop = drop; this.dropChance = dropChance; } - + public FurBlock(ItemLike drop, int dropChance) { - super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.GRASS).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission()); this.drop = drop; this.dropChance = dropChance; } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else if (dropChance < 1 || MHelper.RANDOM.nextInt(dropChance) == 0) { + } + else if (dropChance < 1 || MHelper.RANDOM.nextInt(dropChance) == 0) { return Lists.newArrayList(new ItemStack(drop)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + static { - BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)); - BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.UP, Shapes.box(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)); + BOUNDING_SHAPES.put(Direction.DOWN, Shapes.box(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); } } diff --git a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java index f884d6ef..cf0dbfd8 100644 --- a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java @@ -11,33 +11,33 @@ import org.jetbrains.annotations.Nullable; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BlockEntityProvider; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.PedestalState; import ru.betterend.blocks.InfusionPedestal; @@ -46,18 +46,18 @@ import ru.betterend.patterns.Patterns; import ru.betterend.registry.EndBlocks; import ru.betterend.rituals.InfusionRitual; -public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvider { +public class PedestalBlock extends BlockBaseNotFull implements EntityBlock { public final static EnumProperty STATE = BlockProperties.PEDESTAL_STATE; public static final BooleanProperty HAS_ITEM = BlockProperties.HAS_ITEM; public static final BooleanProperty HAS_LIGHT = BlockProperties.HAS_LIGHT; - + private static final VoxelShape SHAPE_DEFAULT; private static final VoxelShape SHAPE_COLUMN; private static final VoxelShape SHAPE_PILLAR; private static final VoxelShape SHAPE_PEDESTAL_TOP; private static final VoxelShape SHAPE_COLUMN_TOP; private static final VoxelShape SHAPE_BOTTOM; - + /** * * Register new Pedestal block with Better End mod id. @@ -69,7 +69,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid public static Block registerPedestal(String name, Block source) { return EndBlocks.registerBlock(name, new PedestalBlock(source)); } - + /** * * Register new Pedestal block with specified mod id. @@ -81,58 +81,54 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid public static Block registerPedestal(ResourceLocation id, Block source) { return EndBlocks.registerBlock(id, new PedestalBlock(source)); } - + protected final Block parent; protected float height = 1.0F; - + public PedestalBlock(Block parent) { - super(FabricBlockSettings.copyOf(parent).luminance(state -> state.getValue(HAS_LIGHT) ? 12 : 0)); - this.setDefaultState(stateManager.defaultBlockState().with(STATE, PedestalState.DEFAULT).with(HAS_ITEM, false) - .with(HAS_LIGHT, false)); + super(FabricBlockSettings.copyOf(parent).lightLevel(state -> state.getValue(HAS_LIGHT) ? 12 : 0)); + this.registerDefaultState(stateDefinition.any().setValue(STATE, PedestalState.DEFAULT).setValue(HAS_ITEM, false).setValue(HAS_LIGHT, false)); this.parent = parent; } - + public float getHeight(BlockState state) { if (state.getBlock() instanceof PedestalBlock && state.getValue(STATE) == PedestalState.PEDESTAL_TOP) { return this.height - 0.2F; } return this.height; } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (world.isClientSide || !state.is(this)) - return ActionResult.CONSUME; + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (world.isClientSide || !state.is(this)) return InteractionResult.CONSUME; if (!isPlaceable(state)) { - return ActionResult.PASS; + return InteractionResult.PASS; } BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof PedestalBlockEntity) { PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; if (pedestal.isEmpty()) { - ItemStack itemStack = player.getStackInHand(hand); - if (itemStack.isEmpty()) - return ActionResult.CONSUME; - pedestal.setStack(0, itemStack.split(1)); + ItemStack itemStack = player.getItemInHand(hand); + if (itemStack.isEmpty()) return InteractionResult.CONSUME; + pedestal.setItem(0, itemStack.split(1)); checkRitual(world, pos); - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } else { - ItemStack itemStack = pedestal.getStack(0); - if (player.giveItemStack(itemStack)) { - pedestal.removeStack(0); + ItemStack itemStack = pedestal.getItem(0); + if (player.addItem(itemStack)) { + pedestal.removeItemNoUpdate(0); checkRitual(world, pos); - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } - return ActionResult.PASS; + return InteractionResult.PASS; } - + public void checkRitual(Level world, BlockPos pos) { MutableBlockPos posMutable = new MutableBlockPos(); - for (Point point : InfusionRitual.getMap()) { + for (Point point: InfusionRitual.getMap()) { posMutable.set(pos).move(point.x, 0, point.y); BlockState state = world.getBlockState(posMutable); if (state.getBlock() instanceof InfusionPedestal) { @@ -141,93 +137,85 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid } } } - + @Override @Nullable - public BlockState getPlacementState(ItemPlacementContext context) { + public BlockState getStateForPlacement(BlockPlaceContext context) { Level world = context.getLevel(); - BlockPos pos = context.getBlockPos(); - BlockState upState = world.getBlockState(pos.up()); + BlockPos pos = context.getClickedPos(); + BlockState upState = world.getBlockState(pos.above()); BlockState downState = world.getBlockState(pos.below()); - boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN) - || upState.isIn(BlockTags.WALLS); + boolean upSideSolid = upState.isFaceSturdy(world, pos.above(), Direction.DOWN) || upState.is(BlockTags.WALLS); boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock; boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock; if (!hasPedestalOver && hasPedestalUnder && upSideSolid) { - return getDefaultState().with(STATE, PedestalState.COLUMN_TOP); + return defaultBlockState().setValue(STATE, PedestalState.COLUMN_TOP); } else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) { - return getDefaultState().with(STATE, PedestalState.COLUMN); + return defaultBlockState().setValue(STATE, PedestalState.COLUMN); } else if (hasPedestalUnder && hasPedestalOver) { - return getDefaultState().with(STATE, PedestalState.PILLAR); + return defaultBlockState().setValue(STATE, PedestalState.PILLAR); } else if (hasPedestalUnder) { - return getDefaultState().with(STATE, PedestalState.PEDESTAL_TOP); + return defaultBlockState().setValue(STATE, PedestalState.PEDESTAL_TOP); } else if (hasPedestalOver) { - return getDefaultState().with(STATE, PedestalState.BOTTOM); + return defaultBlockState().setValue(STATE, PedestalState.BOTTOM); } - return getDefaultState(); + return defaultBlockState(); } - + @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { + public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { BlockState updated = getUpdatedState(state, direction, newState, world, pos, posFrom); - if (!updated.is(this)) - return updated; + if (!updated.is(this)) return updated; if (!isPlaceable(updated)) { moveStoredStack(world, updated, pos); } return updated; } - - private BlockState getUpdatedState(BlockState state, Direction direction, BlockState newState, LevelAccessor world, - BlockPos pos, BlockPos posFrom) { - if (!state.is(this)) - return state.updateShape(direction, newState, world, pos, posFrom); - if (direction != Direction.UP && direction != Direction.DOWN) - return state; - BlockState upState = world.getBlockState(pos.up()); + + private BlockState getUpdatedState(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) { + if (!state.is(this)) return state.updateShape(direction, newState, world, pos, posFrom); + if (direction != Direction.UP && direction != Direction.DOWN) return state; + BlockState upState = world.getBlockState(pos.above()); BlockState downState = world.getBlockState(pos.below()); - boolean upSideSolid = upState.isSideSolidFullSquare(world, pos.up(), Direction.DOWN) - || upState.isIn(BlockTags.WALLS); + boolean upSideSolid = upState.isFaceSturdy(world, pos.above(), Direction.DOWN) || upState.is(BlockTags.WALLS); boolean hasPedestalOver = upState.getBlock() instanceof PedestalBlock; boolean hasPedestalUnder = downState.getBlock() instanceof PedestalBlock; if (direction == Direction.UP) { - upSideSolid = newState.isSideSolidFullSquare(world, posFrom, Direction.DOWN) - || newState.isIn(BlockTags.WALLS); + upSideSolid = newState.isFaceSturdy(world, posFrom, Direction.DOWN) || newState.is(BlockTags.WALLS); hasPedestalOver = newState.getBlock() instanceof PedestalBlock; } else { hasPedestalUnder = newState.getBlock() instanceof PedestalBlock; } BlockState updatedState; if (!hasPedestalOver && hasPedestalUnder && upSideSolid) { - updatedState = state.with(STATE, PedestalState.COLUMN_TOP); + updatedState = state.setValue(STATE, PedestalState.COLUMN_TOP); } else if (!hasPedestalOver && !hasPedestalUnder && upSideSolid) { - updatedState = state.with(STATE, PedestalState.COLUMN); + updatedState = state.setValue(STATE, PedestalState.COLUMN); } else if (hasPedestalUnder && hasPedestalOver) { - updatedState = state.with(STATE, PedestalState.PILLAR); + updatedState = state.setValue(STATE, PedestalState.PILLAR); } else if (hasPedestalUnder) { - updatedState = state.with(STATE, PedestalState.PEDESTAL_TOP); + updatedState = state.setValue(STATE, PedestalState.PEDESTAL_TOP); } else if (hasPedestalOver) { - updatedState = state.with(STATE, PedestalState.BOTTOM); + updatedState = state.setValue(STATE, PedestalState.BOTTOM); } else { - updatedState = state.with(STATE, PedestalState.DEFAULT); + updatedState = state.setValue(STATE, PedestalState.DEFAULT); } if (!isPlaceable(updatedState)) { - updatedState = updatedState.with(HAS_ITEM, false).with(HAS_LIGHT, false); + updatedState = updatedState.setValue(HAS_ITEM, false).setValue(HAS_LIGHT, false); } return updatedState; } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { List drop = Lists.newArrayList(super.getDrops(state, builder)); if (state.is(this)) { if (isPlaceable(state)) { - BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); + BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); if (blockEntity instanceof PedestalBlockEntity) { PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; if (!pedestal.isEmpty()) { - drop.add(pedestal.getStack(0)); + drop.add(pedestal.getItem(0)); } } } else { @@ -236,30 +224,30 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid } return drop; } - + private void moveStoredStack(LevelAccessor world, BlockState state, BlockPos pos) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof PedestalBlockEntity && state.is(this)) { PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; - ItemStack stack = pedestal.removeStack(0); + ItemStack stack = pedestal.removeItemNoUpdate(0); if (!stack.isEmpty()) { - moveStoredStack(blockEntity, world, stack, pos.up()); + moveStoredStack(blockEntity, world, stack, pos.above()); } } } - + private void moveStoredStack(BlockEntity blockEntity, LevelAccessor world, ItemStack stack, BlockPos pos) { BlockState state = world.getBlockState(pos); if (!state.is(this)) { dropStoredStack(blockEntity, stack, pos); } else if (state.getValue(STATE).equals(PedestalState.PILLAR)) { - moveStoredStack(blockEntity, world, stack, pos.up()); + moveStoredStack(blockEntity, world, stack, pos.above()); } else if (!isPlaceable(state)) { dropStoredStack(blockEntity, stack, pos); } else if (blockEntity instanceof PedestalBlockEntity) { PedestalBlockEntity pedestal = (PedestalBlockEntity) blockEntity; if (pedestal.isEmpty()) { - pedestal.setStack(0, stack); + pedestal.setItem(0, stack); } else { dropStoredStack(blockEntity, stack, pos); } @@ -267,91 +255,91 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid dropStoredStack(blockEntity, stack, pos); } } - + private void dropStoredStack(BlockEntity blockEntity, ItemStack stack, BlockPos pos) { if (blockEntity != null && blockEntity.getLevel() != null) { Level world = blockEntity.getLevel(); - Block.dropStack(world, getDropPos(world, pos), stack); + Block.popResource(world, getDropPos(world, pos), stack); } } - + private BlockPos getDropPos(LevelAccessor world, BlockPos pos) { BlockPos dropPos; if (world.getBlockState(pos).isAir()) { return pos; } - if (world.getBlockState(pos.up()).isAir()) { - return pos.up(); + if (world.getBlockState(pos.above()).isAir()) { + return pos.above(); } - for (int i = 2; i < Direction.values().length; i++) { - dropPos = pos.relative(Direction.byId(i)); + for(int i = 2; i < Direction.values().length; i++) { + dropPos = pos.relative(Direction.from3DDataValue(i)); if (world.getBlockState(dropPos).isAir()) { return dropPos.immutable(); } } - return getDropPos(world, pos.up()); + return getDropPos(world, pos.above()); } - + public boolean isPlaceable(BlockState state) { - if (!state.is(this)) - return false; + if (!state.is(this)) return false; PedestalState currentState = state.getValue(STATE); - return currentState == PedestalState.DEFAULT || currentState == PedestalState.PEDESTAL_TOP; + return currentState == PedestalState.DEFAULT || + currentState == PedestalState.PEDESTAL_TOP; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { if (state.is(this)) { - switch (state.getValue(STATE)) { - case BOTTOM: { - return SHAPE_BOTTOM; - } - case PEDESTAL_TOP: { - return SHAPE_PEDESTAL_TOP; - } - case COLUMN_TOP: { - return SHAPE_COLUMN_TOP; - } - case PILLAR: { - return SHAPE_PILLAR; - } - case COLUMN: { - return SHAPE_COLUMN; - } - default: { - return SHAPE_DEFAULT; - } + switch(state.getValue(STATE)) { + case BOTTOM: { + return SHAPE_BOTTOM; + } + case PEDESTAL_TOP: { + return SHAPE_PEDESTAL_TOP; + } + case COLUMN_TOP: { + return SHAPE_COLUMN_TOP; + } + case PILLAR: { + return SHAPE_PILLAR; + } + case COLUMN: { + return SHAPE_COLUMN; + } + default: { + return SHAPE_DEFAULT; + } } } - return super.getOutlineShape(state, world, pos, context); + return super.getShape(state, world, pos, context); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(STATE, HAS_ITEM, HAS_LIGHT); } @Override - public BlockEntity createBlockEntity(BlockView world) { + public BlockEntity newBlockEntity(BlockGetter world) { return new PedestalBlockEntity(); } - + @Override - public boolean hasComparatorOutput(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return state.getBlock() instanceof PedestalBlock; } - + @Override - public int getComparatorOutput(BlockState state, Level world, BlockPos pos) { + public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { return state.getValue(HAS_ITEM) ? 15 : 0; } - + @Override public String getStatesPattern(Reader data) { String texture = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, texture, texture); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(parent); @@ -359,7 +347,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid Map textures = new HashMap() { private static final long serialVersionUID = 1L; { - put("%mod%", blockId.getNamespace()); + put("%mod%", blockId.getNamespace() ); put("%top%", name + "_top"); put("%base%", name + "_base"); put("%pillar%", name + "_pillar"); @@ -379,28 +367,28 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid } return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_PEDESTAL; } - + static { - VoxelShape basinUp = Block.createCuboidShape(2, 3, 2, 14, 4, 14); - VoxelShape basinDown = Block.createCuboidShape(0, 0, 0, 16, 3, 16); - VoxelShape columnTopUp = Block.createCuboidShape(1, 14, 1, 15, 16, 15); - VoxelShape columnTopDown = Block.createCuboidShape(2, 13, 2, 14, 14, 14); - VoxelShape pedestalTop = Block.createCuboidShape(1, 8, 1, 15, 10, 15); - VoxelShape pedestalDefault = Block.createCuboidShape(1, 12, 1, 15, 14, 15); - VoxelShape pillar = Block.createCuboidShape(3, 0, 3, 13, 8, 13); - VoxelShape pillarDefault = Block.createCuboidShape(3, 0, 3, 13, 12, 13); - VoxelShape columnTop = VoxelShapes.union(columnTopDown, columnTopUp); - VoxelShape basin = VoxelShapes.union(basinDown, basinUp); - SHAPE_PILLAR = Block.createCuboidShape(3, 0, 3, 13, 16, 13); - SHAPE_DEFAULT = VoxelShapes.union(basin, pillarDefault, pedestalDefault); - SHAPE_PEDESTAL_TOP = VoxelShapes.union(pillar, pedestalTop); - SHAPE_COLUMN_TOP = VoxelShapes.union(SHAPE_PILLAR, columnTop); - SHAPE_COLUMN = VoxelShapes.union(basin, SHAPE_PILLAR, columnTop); - SHAPE_BOTTOM = VoxelShapes.union(basin, SHAPE_PILLAR); + VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14); + VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16); + VoxelShape columnTopUp = Block.box(1, 14, 1, 15, 16, 15); + VoxelShape columnTopDown = Block.box(2, 13, 2, 14, 14, 14); + VoxelShape pedestalTop = Block.box(1, 8, 1, 15, 10, 15); + VoxelShape pedestalDefault = Block.box(1, 12, 1, 15, 14, 15); + VoxelShape pillar = Block.box(3, 0, 3, 13, 8, 13); + VoxelShape pillarDefault = Block.box(3, 0, 3, 13, 12, 13); + VoxelShape columnTop = Shapes.or(columnTopDown, columnTopUp); + VoxelShape basin = Shapes.or(basinDown, basinUp); + SHAPE_PILLAR = Block.box(3, 0, 3, 13, 16, 13); + SHAPE_DEFAULT = Shapes.or(basin, pillarDefault, pedestalDefault); + SHAPE_PEDESTAL_TOP = Shapes.or(pillar, pedestalTop); + SHAPE_COLUMN_TOP = Shapes.or(SHAPE_PILLAR, columnTop); + SHAPE_COLUMN = Shapes.or(basin, SHAPE_PILLAR, columnTop); + SHAPE_BOTTOM = Shapes.or(basin, SHAPE_PILLAR); } } diff --git a/src/main/java/ru/betterend/blocks/basis/SimpleLeavesBlock.java b/src/main/java/ru/betterend/blocks/basis/SimpleLeavesBlock.java index 145242a3..8fc9a20b 100644 --- a/src/main/java/ru/betterend/blocks/basis/SimpleLeavesBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/SimpleLeavesBlock.java @@ -3,50 +3,51 @@ package ru.betterend.blocks.basis; import java.io.Reader; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.Patterns; public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeable { public SimpleLeavesBlock(MaterialColor color) { - super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).sounds(SoundType.GRASS).nonOpaque() - .allowsSpawning((state, world, pos, type) -> { - return false; - }).suffocates((state, world, pos) -> { - return false; - }).blockVision((state, world, pos) -> { - return false; - }).materialColor(color)); + super(FabricBlockSettings.of(Material.LEAVES) + .strength(0.2F) + .materialColor(color) + .sound(SoundType.GRASS) + .noOcclusion() + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false)); } - + public SimpleLeavesBlock(MaterialColor color, int light) { - super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).sounds(SoundType.GRASS).nonOpaque() - .luminance(light).allowsSpawning((state, world, pos, type) -> { - return false; - }).suffocates((state, world, pos) -> { - return false; - }).blockVision((state, world, pos) -> { - return false; - }).materialColor(color)); + super(FabricBlockSettings.of(Material.LEAVES) + .luminance(light) + .materialColor(color) + .strength(0.2F) + .sound(SoundType.GRASS) + .noOcclusion() + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false)); } - + @Override public String getStatesPattern(Reader data) { String texture = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(data, texture, texture); } - + @Override public String getModelPattern(String block) { String texture = Registry.BLOCK.getKey(this).getPath(); return Patterns.createJson(Patterns.BLOCK_BASE, texture, texture); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_SIMPLE; diff --git a/src/main/java/ru/betterend/blocks/basis/StalactiteBlock.java b/src/main/java/ru/betterend/blocks/basis/StalactiteBlock.java index 0de3cf81..4bcf8179 100644 --- a/src/main/java/ru/betterend/blocks/basis/StalactiteBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/StalactiteBlock.java @@ -1,48 +1,47 @@ package ru.betterend.blocks.basis; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.Waterloggable; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.state.property.Properties; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.Mth; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.patterns.Patterns; -public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable, IRenderTypeable { - public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; +public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTypeable { + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR; public static final IntegerProperty SIZE = BlockProperties.SIZE; private static final VoxelShape[] SHAPES; public StalactiteBlock(Block source) { - super(FabricBlockSettings.copy(source).nonOpaque()); - this.setDefaultState( - getStateManager().defaultBlockState().with(SIZE, 0).with(IS_FLOOR, true).with(WATERLOGGED, false)); + super(FabricBlockSettings.copy(source).noOcclusion()); + this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false)); } @Override @@ -51,137 +50,147 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPES[state.getValue(SIZE)]; } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - WorldView world = ctx.getLevel(); - BlockPos pos = ctx.getBlockPos(); - Direction dir = ctx.getSide(); - boolean water = world.getFluidState(pos).getFluid() == Fluids.WATER; - + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + LevelReader world = ctx.getLevel(); + BlockPos pos = ctx.getClickedPos(); + Direction dir = ctx.getClickedFace(); + boolean water = world.getFluidState(pos).getType() == Fluids.WATER; + if (dir == Direction.DOWN) { - if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) { - return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water); - } else if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) { - return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water); - } else { + if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) { + return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water); + } + else if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) { + return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water); + } + else { return null; } - } else { - if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) { - return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water); - } else if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) { - return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water); - } else { + } + else { + if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) { + return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water); + } + else if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) { + return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water); + } + else { return null; } } } @Override - public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { - boolean hasUp = isThis(world, pos.up()); + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { + boolean hasUp = isThis(world, pos.above()); boolean hasDown = isThis(world, pos.below()); MutableBlockPos mut = new MutableBlockPos(); if (hasUp && hasDown) { boolean floor = state.getValue(IS_FLOOR); - BlockPos second = floor ? pos.up() : pos.below(); + BlockPos second = floor ? pos.above() : pos.below(); BlockState bState = world.getBlockState(second); - world.setBlockAndUpdate(pos, state.with(SIZE, 1).with(IS_FLOOR, floor)); - world.setBlockAndUpdate(second, bState.with(SIZE, 1).with(IS_FLOOR, !floor)); - + world.setBlockAndUpdate(pos, state.setValue(SIZE, 1).setValue(IS_FLOOR, floor)); + world.setBlockAndUpdate(second, bState.setValue(SIZE, 1).setValue(IS_FLOOR, !floor)); + bState = state; int startSize = floor ? 1 : 2; mut.set(pos.getX(), pos.getY() + 1, pos.getZ()); for (int i = 0; i < 8 && isThis(bState); i++) { - world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, false)); + world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, false)); mut.setY(mut.getY() + 1); bState = world.getBlockState(mut); } - + bState = state; startSize = floor ? 2 : 1; mut.set(pos.getX(), pos.getY() - 1, pos.getZ()); for (int i = 0; i < 8 && isThis(bState); i++) { - world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, true)); + world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, true)); mut.setY(mut.getY() - 1); bState = world.getBlockState(mut); } - } else if (hasDown) { + } + else if (hasDown) { mut.setX(pos.getX()); mut.setZ(pos.getZ()); for (int i = 1; i < 8; i++) { mut.setY(pos.getY() - i); if (isThis(world, mut)) { BlockState state2 = world.getBlockState(mut); - int size = state2.get(SIZE); + int size = state2.getValue(SIZE); if (size < i) { - world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, true)); - } else { + world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, true)); + } + else { break; } - } else { + } + else { break; } } - } else if (hasUp) { + } + else if (hasUp) { mut.setX(pos.getX()); mut.setZ(pos.getZ()); for (int i = 1; i < 8; i++) { mut.setY(pos.getY() + i); if (isThis(world, mut)) { BlockState state2 = world.getBlockState(mut); - int size = state2.get(SIZE); + int size = state2.getValue(SIZE); if (size < i) { - world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, false)); - } else { + world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, false)); + } + else { break; } - } else { + } + else { break; } } } } - - private boolean isThis(WorldView world, BlockPos pos) { + + private boolean isThis(LevelReader world, BlockPos pos) { return isThis(world.getBlockState(pos)); } - + private boolean isThis(BlockState state) { return state.getBlock() instanceof StalactiteBlock; } - + @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); } return state; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { int size = state.getValue(SIZE); return checkUp(world, pos, size) || checkDown(world, pos, size); } - - private boolean checkUp(BlockView world, BlockPos pos, int size) { - BlockPos p = pos.up(); + + private boolean checkUp(BlockGetter world, BlockPos pos, int size) { + BlockPos p = pos.above(); BlockState state = world.getBlockState(p); - return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p); + return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p); } - - private boolean checkDown(BlockView world, BlockPos pos, int size) { + + private boolean checkDown(BlockGetter world, BlockPos pos, int size) { BlockPos p = pos.below(); BlockState state = world.getBlockState(p); - return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p); + return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p); } - + @Override public String getModelPattern(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); @@ -190,25 +199,25 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, } return Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, block); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_STALACTITE; } - + @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override public FluidState getFluidState(BlockState state) { - return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState(); + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); } @Override @@ -222,7 +231,7 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, SHAPES = new VoxelShape[8]; for (int i = 0; i < 8; i++) { int side = Mth.floor(Mth.lerp(i / 7F, start, end) * 8F + 0.5F); - SHAPES[i] = Block.createCuboidShape(side, 0, side, 16 - side, 16, 16 - side); + SHAPES[i] = Block.box(side, 0, side, 16 - side, 16, 16 - side); } } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/basis/StoneLanternBlock.java b/src/main/java/ru/betterend/blocks/basis/StoneLanternBlock.java index 01afe546..8488dca9 100644 --- a/src/main/java/ru/betterend/blocks/basis/StoneLanternBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/StoneLanternBlock.java @@ -3,34 +3,34 @@ package ru.betterend.blocks.basis; import java.io.Reader; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.ShapeContext; import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; -import net.minecraft.core.Vec3i; import net.minecraft.core.Registry; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.core.Vec3i; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.AuroraCrystalBlock; import ru.betterend.interfaces.IColorProvider; import ru.betterend.patterns.Patterns; import ru.betterend.util.MHelper; public class StoneLanternBlock extends EndLanternBlock implements IColorProvider { - private static final VoxelShape SHAPE_CEIL = Block.createCuboidShape(3, 1, 3, 13, 16, 13); - private static final VoxelShape SHAPE_FLOOR = Block.createCuboidShape(3, 0, 3, 13, 15, 13); + private static final VoxelShape SHAPE_CEIL = Block.box(3, 1, 3, 13, 16, 13); + private static final VoxelShape SHAPE_FLOOR = Block.box(3, 0, 3, 13, 15, 13); private static final Vec3i[] COLORS = AuroraCrystalBlock.COLORS; - + public StoneLanternBlock(Block source) { super(FabricBlockSettings.copyOf(source).luminance(15)); } - + @Override - public BlockColor getBlockProvider() { + public BlockColor getProvider() { return (state, world, pos, tintIndex) -> { long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ(); double delta = i * 0.1; @@ -38,14 +38,14 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider int index2 = (index + 1) & 3; delta -= index; index &= 3; - + Vec3i color1 = COLORS[index]; Vec3i color2 = COLORS[index2]; - + int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); - + return MHelper.color(r, g, b); }; } @@ -56,17 +56,17 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider return MHelper.color(COLORS[3].getX(), COLORS[3].getY(), COLORS[3].getZ()); }; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL; } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_STONE_LANTERN; } - + @Override public String getModelPattern(String block) { String texture = Registry.BLOCK.getKey(this).getPath(); @@ -75,7 +75,7 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider } return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, texture, texture); } - + @Override public String getStatesPattern(Reader data) { String block = Registry.BLOCK.getKey(this).getPath(); diff --git a/src/main/java/ru/betterend/blocks/basis/StrippableBarkBlock.java b/src/main/java/ru/betterend/blocks/basis/StrippableBarkBlock.java index f913b3d4..d70f0d5f 100644 --- a/src/main/java/ru/betterend/blocks/basis/StrippableBarkBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/StrippableBarkBlock.java @@ -2,42 +2,40 @@ package ru.betterend.blocks.basis; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.level.block.RotatedPillarBlock; -import net.minecraft.world.entity.player.Player; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; public class StrippableBarkBlock extends BarkBlock { private final Block striped; - + public StrippableBarkBlock(MaterialColor color, Block striped) { super(FabricBlockSettings.copyOf(striped).materialColor(color)); this.striped = striped; } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { - if (player.getMainHandStack().getItem().isIn(FabricToolTags.AXES)) { - world.playLocalSound(player, pos, SoundEvents.ITEM_AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) { + world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); if (!world.isClientSide) { - world.setBlockAndUpdate(pos, striped.defaultBlockState().with(RotatedPillarBlock.AXIS, - state.getValue(RotatedPillarBlock.AXIS)), 11); + world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11); if (player != null && !player.isCreative()) { - player.getMainHandStack().damage(1, world.random, (ServerPlayer) player); + player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player); } } - return ActionResult.SUCCESS; + return InteractionResult.SUCCESS; } - return ActionResult.FAIL; + return InteractionResult.FAIL; } } diff --git a/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java b/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java index 2ecdbee6..3144d336 100644 --- a/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/TripleTerrainBlock.java @@ -2,27 +2,25 @@ package ru.betterend.blocks.basis; import java.util.Map; import java.util.Random; - -import com.google.common.collect.Maps; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.hit.BlockHitResult; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.world.phys.BlockHitResult; +import com.google.common.collect.Maps; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.EndTerrainBlock; @@ -30,25 +28,24 @@ import ru.betterend.patterns.Patterns; public class TripleTerrainBlock extends EndTerrainBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - + public TripleTerrainBlock(MaterialColor color) { super(color); - this.setDefaultState(this.defaultBlockState().with(SHAPE, TripleShape.BOTTOM)); + this.registerDefaultState(this.defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override - public BlockState getPlacementState(ItemPlacementContext ctx) { - Direction dir = ctx.getSide(); - TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM - : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE; - return this.defaultBlockState().with(SHAPE, shape); + public BlockState getStateForPlacement(BlockPlaceContext ctx) { + Direction dir = ctx.getClickedFace(); + TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE; + return this.defaultBlockState().setValue(SHAPE, shape); } - + @Override public String getModelPattern(String block) { String name = Registry.BLOCK.getKey(this).getPath(); @@ -61,59 +58,64 @@ public class TripleTerrainBlock extends EndTerrainBlock { map.put("%bottom%", "minecraft:block/end_stone"); return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map); } - + @Override public ResourceLocation statePatternId() { return Patterns.STATE_TRIPLE_ROTATED_TOP; } - + @Override - public ActionResult onUse(BlockState state, Level world, BlockPos pos, Player player, Hand hand, - BlockHitResult hit) { + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.BOTTOM) { - return super.onUse(state, world, pos, player, hand, hit); + return super.use(state, world, pos, player, hand, hit); } - return ActionResult.FAIL; + return InteractionResult.FAIL; } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.BOTTOM) { super.randomTick(state, world, pos, random); return; - } else if (random.nextInt(16) == 0) { + } + else if (random.nextInt(16) == 0) { boolean bottom = canSurviveBottom(world, pos); if (shape == TripleShape.TOP) { if (!bottom) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); } - } else { - boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.up())); + } + else { + boolean top = canSurvive(state, world, pos) || isMiddle(world.getBlockState(pos.above())); if (!top && !bottom) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); - } else if (top && !bottom) { - world.setBlockAndUpdate(pos, state.with(SHAPE, TripleShape.BOTTOM)); - } else if (!top && bottom) { - world.setBlockAndUpdate(pos, state.with(SHAPE, TripleShape.TOP)); + } + else if (top && !bottom) { + world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM)); + } + else if (!top && bottom) { + world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP)); } } } } - - protected boolean canSurviveBottom(WorldView world, BlockPos pos) { + + protected boolean canSurviveBottom(LevelReader world, BlockPos pos) { BlockPos blockPos = pos.below(); BlockState blockState = world.getBlockState(blockPos); if (isMiddle(blockState)) { return true; - } else if (blockState.getFluidState().getLevel() == 8) { + } + else if (blockState.getFluidState().getAmount() == 8) { return false; - } else { - return !blockState.isSideSolidFullSquare(world, blockPos, Direction.UP); + } + else { + return !blockState.isFaceSturdy(world, blockPos, Direction.UP); } } - + protected boolean isMiddle(BlockState state) { return state.is(this) && state.getValue(SHAPE) == TripleShape.MIDDLE; } diff --git a/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantBlock.java index 51eb7fd6..39e94ec2 100644 --- a/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantBlock.java @@ -7,133 +7,139 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.block.FluidFillable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.world.level.material.Fluids; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.LiquidBlockContainer; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; -public class UnderwaterPlantBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable, FluidFillable { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 14, 12); - +public class UnderwaterPlantBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock, LiquidBlockContainer { + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); + public UnderwaterPlantBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .noCollission()); } - + public UnderwaterPlantBlock(int light) { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).luminance(light).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(light) + .sound(SoundType.WET_GRASS) + .noCollission()); } - + public UnderwaterPlantBlock(Properties settings) { super(settings); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); - return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); + return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.XZ; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.XZ; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); state = world.getBlockState(pos); - return isTerrain(down) && state.getFluidState().getFluid().equals(Fluids.WATER.getStill()); + return isTerrain(down) && state.getFluidState().getType().equals(Fluids.WATER.getSource()); } - + protected boolean isTerrain(BlockState state) { - return state.isIn(EndTags.END_GROUND) || state.getBlock() == EndBlocks.ENDSTONE_DUST; + return state.is(EndTags.END_GROUND) || state.getBlock() == EndBlocks.ENDSTONE_DUST; } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { - world.breakBlock(pos, true); + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { + world.destroyBlock(pos, true); return Blocks.WATER.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { - ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, - new ItemStack(this)); - world.spawnEntity(item); + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { + ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); + world.addFreshEntity(item); } @Override - public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override - public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { + public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } - + @Override public FluidState getFluidState(BlockState state) { - return Fluids.WATER.getStill(false); + return Fluids.WATER.getSource(false); } } diff --git a/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantWithAgeBlock.java index 405daee8..4ba46a39 100644 --- a/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/UnderwaterPlantWithAgeBlock.java @@ -4,49 +4,54 @@ import java.util.Random; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; +import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.BlockProperties; public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; - + public UnderwaterPlantWithAgeBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.WET_GRASS).breakByHand(true).ticksRandomly().noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .randomTicks() + .noCollission()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(AGE); } - + public abstract void grow(WorldGenLevel world, Random random, BlockPos pos); - + @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { if (random.nextInt(4) == 0) { int age = state.getValue(AGE); if (age < 3) { - world.setBlockAndUpdate(pos, state.with(AGE, age + 1)); - } else { + world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1)); + } + else { grow(world, random, pos); } } } - + @Override - public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - super.scheduledTick(state, world, pos, random); - if (canGrow(world, random, pos, state)) { - grow(world, random, pos, state); + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + super.tick(state, world, pos, random); + if (isBonemealSuccess(world, random, pos, state)) { + performBonemeal(world, random, pos, state); } } } diff --git a/src/main/java/ru/betterend/blocks/basis/UpDownPlantBlock.java b/src/main/java/ru/betterend/blocks/basis/UpDownPlantBlock.java index b8ab9330..d53fbb34 100644 --- a/src/main/java/ru/betterend/blocks/basis/UpDownPlantBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/UpDownPlantBlock.java @@ -6,88 +6,90 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.registry.EndTags; public class UpDownPlantBlock extends BlockBaseNotFull implements IRenderTypeable { - private static final VoxelShape SHAPE = Block.createCuboidShape(4, 0, 4, 12, 16, 12); - + private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); + public UpDownPlantBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS) - .breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission()); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); - BlockState up = world.getBlockState(pos.up()); + BlockState up = world.getBlockState(pos.above()); return (isTerrain(down) || down.getBlock() == this) && (isSupport(up, world, pos) || up.getBlock() == this); } - + protected boolean isTerrain(BlockState state) { - return state.isIn(EndTags.END_GROUND); + return state.is(EndTags.END_GROUND); } - - protected boolean isSupport(BlockState state, WorldView world, BlockPos pos) { - return sideCoversSmallSquare(world, pos.up(), Direction.UP); + + protected boolean isSupport(BlockState state, LevelReader world, BlockPos pos) { + return canSupportCenter(world, pos.above(), Direction.UP); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { return state; } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public void afterBreak(Level world, Player player, BlockPos pos, BlockState state, BlockEntity blockEntity, - ItemStack stack) { - super.afterBreak(world, player, pos, state, blockEntity, stack); - world.updateNeighbor(pos, Blocks.AIR, pos.below()); + public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, BlockEntity blockEntity, ItemStack stack) { + super.playerDestroy(world, player, pos, state, blockEntity, stack); + world.neighborChanged(pos, Blocks.AIR, pos.below()); } } diff --git a/src/main/java/ru/betterend/blocks/basis/VineBlock.java b/src/main/java/ru/betterend/blocks/basis/VineBlock.java index 2de33f06..45875dff 100644 --- a/src/main/java/ru/betterend/blocks/basis/VineBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/VineBlock.java @@ -7,119 +7,121 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fertilizable; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.tags.BlockTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.util.BlocksHelper; -public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, Fertilizable { +public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, BonemealableBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; - private static final VoxelShape VOXEL_SHAPE = Block.createCuboidShape(2, 0, 2, 14, 16, 14); - + private static final VoxelShape VOXEL_SHAPE = Block.box(2, 0, 2, 14, 16, 14); + public VineBlock() { this(0, false); } - + public VineBlock(int light) { this(light, false); } - + public VineBlock(int light, boolean bottomOnly) { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS) - .luminance((state) -> { - return bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light; - }).breakByHand(true).noCollision()); - this.setDefaultState(this.stateManager.defaultBlockState().with(SHAPE, TripleShape.BOTTOM)); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .sound(SoundType.GRASS) + .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) + .noCollission()); + this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { - Vec3d vec3d = state.getModelOffset(view, pos); - return VOXEL_SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { + Vec3 vec3d = state.getOffset(view, pos); + return VOXEL_SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.XZ; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.XZ; } - - public boolean canGenerate(BlockState state, WorldView world, BlockPos pos) { + + public boolean canGenerate(BlockState state, LevelReader world, BlockPos pos) { return isSupport(state, world, pos); } @Override - public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { + public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return isSupport(state, world, pos); } - - protected boolean isSupport(BlockState state, WorldView world, BlockPos pos) { - BlockState up = world.getBlockState(pos.up()); - return up.is(this) || up.isIn(BlockTags.LEAVES) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN); + + protected boolean isSupport(BlockState state, LevelReader world, BlockPos pos) { + BlockState up = world.getBlockState(pos.above()); + return up.is(this) || up.is(BlockTags.LEAVES) || canSupportCenter(world, pos.above(), Direction.DOWN); } @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, - BlockPos pos, BlockPos neighborPos) { - if (!canPlaceAt(state, world, pos)) { + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { if (world.getBlockState(pos.below()).getBlock() != this) - return state.with(SHAPE, TripleShape.BOTTOM); - else if (world.getBlockState(pos.up()).getBlock() != this) - return state.with(SHAPE, TripleShape.TOP); - return state.with(SHAPE, TripleShape.MIDDLE); + return state.setValue(SHAPE, TripleShape.BOTTOM); + else if (world.getBlockState(pos.above()).getBlock() != this) + return state.setValue(SHAPE, TripleShape.TOP); + return state.setValue(SHAPE, TripleShape.MIDDLE); } } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) - || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { + if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return Lists.newArrayList(new ItemStack(this)); - } else { + } + else { return Lists.newArrayList(); } } - + @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { while (world.getBlockState(pos).getBlock() == this) { pos = pos.below(); } @@ -127,19 +129,19 @@ public class VineBlock extends BlockBaseNotFull implements IRenderTypeable, Fert } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { while (world.getBlockState(pos).getBlock() == this) { pos = pos.below(); } - return world.isAir(pos); + return world.isEmptyBlock(pos); } @Override - public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { + public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { while (world.getBlockState(pos).getBlock() == this) { pos = pos.below(); } - world.setBlockAndUpdate(pos, getDefaultState()); - BlocksHelper.setWithoutUpdate(world, pos, getDefaultState()); + world.setBlockAndUpdate(pos, defaultBlockState()); + BlocksHelper.setWithoutUpdate(world, pos, defaultBlockState()); } } diff --git a/src/main/java/ru/betterend/blocks/basis/WallMushroomBlock.java b/src/main/java/ru/betterend/blocks/basis/WallMushroomBlock.java index 55600834..7e6a2ac4 100644 --- a/src/main/java/ru/betterend/blocks/basis/WallMushroomBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/WallMushroomBlock.java @@ -6,28 +6,34 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.WorldView; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; public class WallMushroomBlock extends EndWallPlantBlock { public WallMushroomBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).sounds(SoundType.GRASS) - .luminance(light).sounds(SoundType.WOOD).hardness(0.2F).breakByHand(true).noCollision()); + super(FabricBlockSettings.of(Material.PLANT) + .breakByTool(FabricToolTags.AXES) + .breakByHand(true) + .luminance(light) + .hardness(0.2F) + .sound(SoundType.GRASS) + .sound(SoundType.WOOD) + .noCollission()); } - + @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Lists.newArrayList(new ItemStack(this)); } - + @Override - public boolean isSupport(WorldView world, BlockPos pos, BlockState blockState, Direction direction) { - return blockState.getMaterial().isSolid() && blockState.isSideSolidFullSquare(world, pos, direction); + public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) { + return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction); } } diff --git a/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java b/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java index 57f496dc..22274872 100644 --- a/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/ColoredMaterial.java @@ -6,12 +6,12 @@ import java.util.function.Function; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.material.MaterialColor; +import net.minecraft.core.Registry; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeItem; import net.minecraft.world.level.ItemLike; -import net.minecraft.util.DyeColor; -import net.minecraft.core.Registry; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.recipe.builders.GridRecipe; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; @@ -20,42 +20,39 @@ public class ColoredMaterial { private static final Map DYES = Maps.newHashMap(); private static final Map COLORS = Maps.newHashMap(); private final Map colors = Maps.newHashMap(); - + public ColoredMaterial(Function constructor, Block source, boolean craftEight) { this(constructor, source, COLORS, DYES, craftEight); } - - public ColoredMaterial(Function constructor, Block source, Map colors, - Map dyes, boolean craftEight) { + + public ColoredMaterial(Function constructor, Block source, Map colors, Map dyes, boolean craftEight) { String id = Registry.BLOCK.getKey(source).getPath(); colors.forEach((color, name) -> { String blockName = id + "_" + name; - Block block = constructor - .apply(FabricBlockSettings.copyOf(source).materialColor(MaterialColor.COLOR_BLACK)); + Block block = constructor.apply(FabricBlockSettings.copyOf(source).materialColor(MaterialColor.COLOR_BLACK)); EndBlocks.registerBlock(blockName, block); if (craftEight) { - GridRecipe.make(blockName, block).setOutputCount(8).setShape("###", "#D#", "###") - .addMaterial('#', source).addMaterial('D', dyes.get(color)).build(); - } else { - GridRecipe.make(blockName, block).setList("#D").addMaterial('#', source) - .addMaterial('D', dyes.get(color)).build(); + GridRecipe.make(blockName, block).setOutputCount(8).setShape("###", "#D#", "###").addMaterial('#', source).addMaterial('D', dyes.get(color)).build(); + } + else { + GridRecipe.make(blockName, block).setList("#D").addMaterial('#', source).addMaterial('D', dyes.get(color)).build(); } this.colors.put(color, block); BlocksHelper.addBlockColor(block, color); }); } - + public Block getByColor(DyeColor color) { - return colors.get(color.getMaterialColor().color); + return colors.get(color.getMaterialColor().col); } - + public Block getByColor(int color) { return colors.get(color); } - + static { - for (DyeColor color : DyeColor.values()) { - int colorRGB = color.getMaterialColor().color; + for (DyeColor color: DyeColor.values()) { + int colorRGB = color.getMaterialColor().col; COLORS.put(colorRGB, color.getName()); DYES.put(colorRGB, DyeItem.byColor(color)); } diff --git a/src/main/java/ru/betterend/blocks/complex/CrystalSubblocksMaterial.java b/src/main/java/ru/betterend/blocks/complex/CrystalSubblocksMaterial.java index 15bf2a3f..352909ea 100644 --- a/src/main/java/ru/betterend/blocks/complex/CrystalSubblocksMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/CrystalSubblocksMaterial.java @@ -1,9 +1,9 @@ package ru.betterend.blocks.complex; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; +import net.minecraft.world.level.block.Block; import ru.betterend.blocks.EndPedestal; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.EndPillarBlock; @@ -27,7 +27,7 @@ public class CrystalSubblocksMaterial { public final Block brick_stairs; public final Block brick_slab; public final Block brick_wall; - + public CrystalSubblocksMaterial(String name, Block source) { FabricBlockSettings material = FabricBlockSettings.copyOf(source); polished = EndBlocks.registerBlock(name + "_polished", new BlockBase(material)); @@ -41,39 +41,29 @@ public class CrystalSubblocksMaterial { brick_stairs = EndBlocks.registerBlock(name + "_bricks_stairs", new EndStairsBlock(bricks)); brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new EndSlabBlock(bricks)); brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new EndWallBlock(bricks)); - + // Recipes // - GridRecipe.make(name + "_bricks", bricks).setOutputCount(4).setShape("##", "##").addMaterial('#', source) - .setGroup("end_bricks").build(); - GridRecipe.make(name + "_polished", polished).setOutputCount(4).setShape("##", "##").addMaterial('#', bricks) - .setGroup("end_tile").build(); - GridRecipe.make(name + "_tiles", tiles).setOutputCount(4).setShape("##", "##").addMaterial('#', polished) - .setGroup("end_small_tile").build(); - GridRecipe.make(name + "_pillar", pillar).setShape("#", "#").addMaterial('#', slab).setGroup("end_pillar") - .build(); - - GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', source).setGroup("end_stone_stairs").build(); - GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', source) - .setGroup("end_stone_slabs").build(); - GridRecipe.make(name + "_bricks_stairs", brick_stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', bricks).setGroup("end_stone_stairs").build(); - GridRecipe.make(name + "_bricks_slab", brick_slab).setOutputCount(6).setShape("###").addMaterial('#', bricks) - .setGroup("end_stone_slabs").build(); - - GridRecipe.make(name + "_wall", wall).setOutputCount(6).setShape("###", "###").addMaterial('#', source) - .setGroup("end_wall").build(); - GridRecipe.make(name + "_bricks_wall", brick_wall).setOutputCount(6).setShape("###", "###") - .addMaterial('#', bricks).setGroup("end_wall").build(); - + GridRecipe.make(name + "_bricks", bricks).setOutputCount(4).setShape("##", "##").addMaterial('#', source).setGroup("end_bricks").build(); + GridRecipe.make(name + "_polished", polished).setOutputCount(4).setShape("##", "##").addMaterial('#', bricks).setGroup("end_tile").build(); + GridRecipe.make(name + "_tiles", tiles).setOutputCount(4).setShape("##", "##").addMaterial('#', polished).setGroup("end_small_tile").build(); + GridRecipe.make(name + "_pillar", pillar).setShape("#", "#").addMaterial('#', slab).setGroup("end_pillar").build(); + + GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', source).setGroup("end_stone_stairs").build(); + GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', source).setGroup("end_stone_slabs").build(); + GridRecipe.make(name + "_bricks_stairs", brick_stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', bricks).setGroup("end_stone_stairs").build(); + GridRecipe.make(name + "_bricks_slab", brick_slab).setOutputCount(6).setShape("###").addMaterial('#', bricks).setGroup("end_stone_slabs").build(); + + GridRecipe.make(name + "_wall", wall).setOutputCount(6).setShape("###", "###").addMaterial('#', source).setGroup("end_wall").build(); + GridRecipe.make(name + "_bricks_wall", brick_wall).setOutputCount(6).setShape("###", "###").addMaterial('#', bricks).setGroup("end_wall").build(); + CraftingRecipes.registerPedestal(name + "_pedestal", pedestal, slab, pillar); - + // Item Tags // TagHelper.addTag(ItemTags.SLABS, slab, brick_slab); TagHelper.addTag(ItemTags.STONE_BRICKS, bricks); TagHelper.addTag(ItemTags.STONE_CRAFTING_MATERIALS, source); TagHelper.addTag(ItemTags.STONE_TOOL_MATERIALS, source); - + // Block Tags // TagHelper.addTag(BlockTags.STONE_BRICKS, bricks); TagHelper.addTag(BlockTags.WALLS, wall, brick_wall); diff --git a/src/main/java/ru/betterend/blocks/complex/MetalMaterial.java b/src/main/java/ru/betterend/blocks/complex/MetalMaterial.java index e2ef98dd..a0f73d54 100644 --- a/src/main/java/ru/betterend/blocks/complex/MetalMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/MetalMaterial.java @@ -1,17 +1,19 @@ package ru.betterend.blocks.complex; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.Tier; -import net.minecraft.world.level.block.SoundType; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.Tier; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.BulbVineLanternBlock; import ru.betterend.blocks.BulbVineLanternColoredBlock; import ru.betterend.blocks.ChandelierBlock; @@ -54,64 +56,54 @@ public class MetalMaterial { public final Block chain; public final Block stairs; public final Block slab; - + public final Block chandelier; public final Block bulb_lantern; public final ColoredMaterial bulb_lantern_colored; - + public final Item nugget; public final Item ingot; - + public final Item shovelHead; public final Item pickaxeHead; public final Item axeHead; public final Item hoeHead; public final Item swordBlade; public final Item swordHandle; - + public final Item shovel; public final Item sword; public final Item pickaxe; public final Item axe; public final Item hoe; public final Item hammer; - + public final Item helmet; public final Item chestplate; public final Item leggings; public final Item boots; - + public static MetalMaterial makeNormal(String name, MaterialColor color, Tier material, ArmorMaterial armor) { - return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), - EndItems.makeItemSettings(), material, armor); + return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeItemSettings(), material, armor); } - - public static MetalMaterial makeNormal(String name, MaterialColor color, float hardness, float resistance, - Tier material, ArmorMaterial armor) { - return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color) - .hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor); + + public static MetalMaterial makeNormal(String name, MaterialColor color, float hardness, float resistance, Tier material, ArmorMaterial armor) { + return new MetalMaterial(name, true, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor); } - + public static MetalMaterial makeOreless(String name, MaterialColor color, Tier material, ArmorMaterial armor) { - return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), - EndItems.makeItemSettings(), material, armor); + return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color), EndItems.makeItemSettings(), material, armor); } - - public static MetalMaterial makeOreless(String name, MaterialColor color, float hardness, float resistance, - Tier material, ArmorMaterial armor) { - return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color) - .hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor); + + public static MetalMaterial makeOreless(String name, MaterialColor color, float hardness, float resistance, Tier material, ArmorMaterial armor) { + return new MetalMaterial(name, false, FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).materialColor(color).hardness(hardness).resistance(resistance), EndItems.makeItemSettings(), material, armor); } - - private MetalMaterial(String name, boolean hasOre, FabricBlockSettings settings, Item.Properties itemSettings, - Tier material, ArmorMaterial armor) { - FabricBlockSettings lantern = FabricBlockSettings.copyOf(settings).sounds(SoundType.LANTERN).hardness(1) - .resistance(1).luminance(15); + + private MetalMaterial(String name, boolean hasOre, FabricBlockSettings settings, Properties itemSettings, Tier material, ArmorMaterial armor) { + BlockBehaviour.Properties lanternProperties = FabricBlockSettings.copyOf(settings).hardness(1).resistance(1).luminance(15).sound(SoundType.LANTERN); final int level = material.getLevel(); - - ore = hasOre - ? EndBlocks.registerBlock(name + "_ore", new BlockBase(FabricBlockSettings.copyOf(Blocks.END_STONE))) - : null; + + ore = hasOre ? EndBlocks.registerBlock(name + "_ore", new BlockBase(FabricBlockSettings.copyOf(Blocks.END_STONE))) : null; block = EndBlocks.registerBlock(name + "_block", new BlockBase(settings)); tile = EndBlocks.registerBlock(name + "_tile", new BlockBase(settings)); stairs = EndBlocks.registerBlock(name + "_stairs", new EndStairsBlock(tile)); @@ -122,75 +114,58 @@ public class MetalMaterial { bars = EndBlocks.registerBlock(name + "_bars", new EndMetalPaneBlock(block)); chain = EndBlocks.registerBlock(name + "_chain", new EndChainBlock(block.defaultMaterialColor())); plate = EndBlocks.registerBlock(name + "_plate", new EndWoodenPlateBlock(block)); - + chandelier = EndBlocks.registerBlock(name + "_chandelier", new ChandelierBlock(block)); - bulb_lantern = EndBlocks.registerBlock(name + "_bulb_lantern", new BulbVineLanternBlock(lantern)); + bulb_lantern = EndBlocks.registerBlock(name + "_bulb_lantern", new BulbVineLanternBlock(lanternProperties)); bulb_lantern_colored = new ColoredMaterial(BulbVineLanternColoredBlock::new, bulb_lantern, false); - + nugget = EndItems.registerItem(name + "_nugget", new PatternedItem(itemSettings)); ingot = EndItems.registerItem(name + "_ingot", new PatternedItem(itemSettings)); - + shovelHead = EndItems.registerItem(name + "_shovel_head"); pickaxeHead = EndItems.registerItem(name + "_pickaxe_head"); axeHead = EndItems.registerItem(name + "_axe_head"); hoeHead = EndItems.registerItem(name + "_hoe_head"); swordBlade = EndItems.registerItem(name + "_sword_blade"); swordHandle = EndItems.registerItem(name + "_sword_handle"); - + shovel = EndItems.registerTool(name + "_shovel", new EndShovelItem(material, 1.5F, -3.0F, itemSettings)); sword = EndItems.registerTool(name + "_sword", new EndSwordItem(material, 3, -2.4F, itemSettings)); pickaxe = EndItems.registerTool(name + "_pickaxe", new EndPickaxeItem(material, 1, -2.8F, itemSettings)); axe = EndItems.registerTool(name + "_axe", new EndAxeItem(material, 6.0F, -3.0F, itemSettings)); hoe = EndItems.registerTool(name + "_hoe", new EndHoeItem(material, -3, 0.0F, itemSettings)); hammer = EndItems.registerTool(name + "_hammer", new EndHammerItem(material, 5.0F, -3.2F, 0.3D, itemSettings)); - + helmet = EndItems.registerItem(name + "_helmet", new EndArmorItem(armor, EquipmentSlot.HEAD, itemSettings)); - chestplate = EndItems.registerItem(name + "_chestplate", - new EndArmorItem(armor, EquipmentSlot.CHEST, itemSettings)); + chestplate = EndItems.registerItem(name + "_chestplate", new EndArmorItem(armor, EquipmentSlot.CHEST, itemSettings)); leggings = EndItems.registerItem(name + "_leggings", new EndArmorItem(armor, EquipmentSlot.LEGS, itemSettings)); boots = EndItems.registerItem(name + "_boots", new EndArmorItem(armor, EquipmentSlot.FEET, itemSettings)); - + if (hasOre) { FurnaceRecipe.make(name + "_ingot_furnace", ore, ingot).setGroup("end_ingot").buildWithBlasting(); - AlloyingRecipe.Builder.create(name + "_ingot_alloy").setInput(ore, ore).setOutput(ingot, 3) - .setExpiriense(2.1F).build(); + AlloyingRecipe.Builder.create(name + "_ingot_alloy").setInput(ore, ore).setOutput(ingot, 3).setExpiriense(2.1F).build(); } - + // Basic recipes - GridRecipe.make(name + "_ingot_from_nuggets", ingot).setShape("###", "###", "###").addMaterial('#', nugget) - .setGroup("end_metal_ingots_nug").build(); - GridRecipe.make(name + "_block", block).setShape("###", "###", "###").addMaterial('#', ingot) - .setGroup("end_metal_blocks").build(); - GridRecipe.make(name + "_ingot_from_block", ingot).setOutputCount(9).setList("#").addMaterial('#', block) - .setGroup("end_metal_ingots").build(); - + GridRecipe.make(name + "_ingot_from_nuggets", ingot).setShape("###", "###", "###").addMaterial('#', nugget).setGroup("end_metal_ingots_nug").build(); + GridRecipe.make(name + "_block", block).setShape("###", "###", "###").addMaterial('#', ingot).setGroup("end_metal_blocks").build(); + GridRecipe.make(name + "_ingot_from_block", ingot).setOutputCount(9).setList("#").addMaterial('#', block).setGroup("end_metal_ingots").build(); + // Block recipes - GridRecipe.make(name + "_tile", tile).setOutputCount(4).setShape("##", "##").addMaterial('#', block) - .setGroup("end_metal_tiles").build(); - GridRecipe.make(name + "_bars", bars).setOutputCount(16).setShape("###", "###").addMaterial('#', ingot) - .setGroup("end_metal_bars").build(); - GridRecipe.make(name + "_plate", plate).setShape("##").addMaterial('#', ingot).setGroup("end_metal_plates") - .build(); - GridRecipe.make(name + "_door", door).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', ingot) - .setGroup("end_metal_doors").build(); - GridRecipe.make(name + "_trapdoor", trapdoor).setShape("##", "##").addMaterial('#', ingot) - .setGroup("end_metal_trapdoors").build(); - GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', block, tile).setGroup("end_metal_stairs").build(); - GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', block, tile) - .setGroup("end_metal_slabs").build(); - GridRecipe.make(name + "_chain", chain).setShape("N", "#", "N").addMaterial('#', ingot).addMaterial('N', nugget) - .setGroup("end_metal_chain").build(); - GridRecipe.make(name + "_anvil", anvil).setShape("###", " I ", "III").addMaterial('#', block, tile) - .addMaterial('I', ingot).setGroup("end_metal_anvil").build(); - GridRecipe.make(name + "bulb_lantern", bulb_lantern).setShape("C", "I", "#").addMaterial('C', chain) - .addMaterial('I', ingot).addMaterial('#', EndItems.GLOWING_BULB).build(); - - GridRecipe.make(name + "_smith_table", Blocks.SMITHING_TABLE).setShape("II", "##", "##") - .addMaterial('#', ItemTags.PLANKS).addMaterial('I', ingot).setGroup("smith_table").build(); - GridRecipe.make(name + "_chandelier", chandelier).setShape("I#I", " # ").addMaterial('#', ingot) - .addMaterial('I', EndItems.LUMECORN_ROD).setGroup("end_metal_chandelier").build(); - + GridRecipe.make(name + "_tile", tile).setOutputCount(4).setShape("##", "##").addMaterial('#', block).setGroup("end_metal_tiles").build(); + GridRecipe.make(name + "_bars", bars).setOutputCount(16).setShape("###", "###").addMaterial('#', ingot).setGroup("end_metal_bars").build(); + GridRecipe.make(name + "_plate", plate).setShape("##").addMaterial('#', ingot).setGroup("end_metal_plates").build(); + GridRecipe.make(name + "_door", door).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', ingot).setGroup("end_metal_doors").build(); + GridRecipe.make(name + "_trapdoor", trapdoor).setShape("##", "##").addMaterial('#', ingot).setGroup("end_metal_trapdoors").build(); + GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', block, tile).setGroup("end_metal_stairs").build(); + GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', block, tile).setGroup("end_metal_slabs").build(); + GridRecipe.make(name + "_chain", chain).setShape("N", "#", "N").addMaterial('#', ingot).addMaterial('N', nugget).setGroup("end_metal_chain").build(); + GridRecipe.make(name + "_anvil", anvil).setShape("###", " I ", "III").addMaterial('#', block, tile).addMaterial('I', ingot).setGroup("end_metal_anvil").build(); + GridRecipe.make(name + "bulb_lantern", bulb_lantern).setShape("C", "I", "#").addMaterial('C', chain).addMaterial('I', ingot).addMaterial('#', EndItems.GLOWING_BULB).build(); + + GridRecipe.make(name + "_smith_table", Blocks.SMITHING_TABLE).setShape("II", "##", "##").addMaterial('#', ItemTags.PLANKS).addMaterial('I', ingot).setGroup("smith_table").build(); + GridRecipe.make(name + "_chandelier", chandelier).setShape("I#I", " # ").addMaterial('#', ingot).addMaterial('I', EndItems.LUMECORN_ROD).setGroup("end_metal_chandelier").build(); + // Tools & armor into nuggets FurnaceRecipe.make(name + "_axe_nugget", axe, nugget).setGroup("end_nugget").buildWithBlasting(); FurnaceRecipe.make(name + "_hoe_nugget", hoe, nugget).setGroup("end_nugget").buildWithBlasting(); @@ -201,47 +176,34 @@ public class MetalMaterial { FurnaceRecipe.make(name + "_chestplate_nugget", chestplate, nugget).setGroup("end_nugget").buildWithBlasting(); FurnaceRecipe.make(name + "_leggings_nugget", leggings, nugget).setGroup("end_nugget").buildWithBlasting(); FurnaceRecipe.make(name + "_boots_nugget", boots, nugget).setGroup("end_nugget").buildWithBlasting(); - + // Tool parts from ingots - AnvilRecipe.Builder.create(name + "_shovel_head").setInput(ingot).setOutput(shovelHead).setAnvilLevel(level) - .setToolLevel(level).setDamage(level).build(); - AnvilRecipe.Builder.create(name + "_pickaxe_head").setInput(ingot).setInputCount(3).setOutput(pickaxeHead) - .setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); - AnvilRecipe.Builder.create(name + "_axe_head").setInput(ingot).setInputCount(3).setOutput(axeHead) - .setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); - AnvilRecipe.Builder.create(name + "_hoe_head").setInput(ingot).setInputCount(2).setOutput(hoeHead) - .setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); - AnvilRecipe.Builder.create(name + "_sword_blade").setInput(ingot).setOutput(swordBlade).setAnvilLevel(level) - .setToolLevel(level).setDamage(level).build(); - + AnvilRecipe.Builder.create(name + "_shovel_head").setInput(ingot).setOutput(shovelHead).setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); + AnvilRecipe.Builder.create(name + "_pickaxe_head").setInput(ingot).setInputCount(3).setOutput(pickaxeHead).setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); + AnvilRecipe.Builder.create(name + "_axe_head").setInput(ingot).setInputCount(3).setOutput(axeHead).setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); + AnvilRecipe.Builder.create(name + "_hoe_head").setInput(ingot).setInputCount(2).setOutput(hoeHead).setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); + AnvilRecipe.Builder.create(name + "_sword_blade").setInput(ingot).setOutput(swordBlade).setAnvilLevel(level).setToolLevel(level).setDamage(level).build(); + // Tools from parts SmithingTableRecipe.create(name + "_hammer").setResult(hammer).setBase(block).setAddition(Items.STICK).build(); SmithingTableRecipe.create(name + "_axe").setResult(axe).setBase(axeHead).setAddition(Items.STICK).build(); - SmithingTableRecipe.create(name + "_pickaxe").setResult(pickaxe).setBase(pickaxeHead).setAddition(Items.STICK) - .build(); + SmithingTableRecipe.create(name + "_pickaxe").setResult(pickaxe).setBase(pickaxeHead).setAddition(Items.STICK).build(); SmithingTableRecipe.create(name + "_hoe").setResult(hoe).setBase(hoeHead).setAddition(Items.STICK).build(); - SmithingTableRecipe.create(name + "_sword_handle").setResult(swordHandle).setBase(ingot) - .setAddition(Items.STICK).build(); - SmithingTableRecipe.create(name + "_sword").setResult(sword).setBase(swordBlade).setAddition(swordHandle) - .build(); - SmithingTableRecipe.create(name + "_shovel").setResult(shovel).setBase(shovelHead).setAddition(Items.STICK) - .build(); - + SmithingTableRecipe.create(name + "_sword_handle").setResult(swordHandle).setBase(ingot).setAddition(Items.STICK).build(); + SmithingTableRecipe.create(name + "_sword").setResult(sword).setBase(swordBlade).setAddition(swordHandle).build(); + SmithingTableRecipe.create(name + "_shovel").setResult(shovel).setBase(shovelHead).setAddition(Items.STICK).build(); + // Armor crafting - GridRecipe.make(name + "_helmet", helmet).setShape("###", "# #").addMaterial('#', ingot) - .setGroup("end_metal_helmets").build(); - GridRecipe.make(name + "_chestplate", chestplate).setShape("# #", "###", "###").addMaterial('#', ingot) - .setGroup("end_metal_chestplates").build(); - GridRecipe.make(name + "_leggings", leggings).setShape("###", "# #", "# #").addMaterial('#', ingot) - .setGroup("end_metal_leggings").build(); - GridRecipe.make(name + "_boots", boots).setShape("# #", "# #").addMaterial('#', ingot) - .setGroup("end_metal_boots").build(); - + GridRecipe.make(name + "_helmet", helmet).setShape("###", "# #").addMaterial('#', ingot).setGroup("end_metal_helmets").build(); + GridRecipe.make(name + "_chestplate", chestplate).setShape("# #", "###", "###").addMaterial('#', ingot).setGroup("end_metal_chestplates").build(); + GridRecipe.make(name + "_leggings", leggings).setShape("###", "# #", "# #").addMaterial('#', ingot).setGroup("end_metal_leggings").build(); + GridRecipe.make(name + "_boots", boots).setShape("# #", "# #").addMaterial('#', ingot).setGroup("end_metal_boots").build(); + TagHelper.addTag(BlockTags.ANVIL, anvil); TagHelper.addTag(BlockTags.BEACON_BASE_BLOCKS, block); TagHelper.addTag(EndTags.IRON_INGOTS, ingot); TagHelper.addTag(ItemTags.BEACON_PAYMENT_ITEMS, ingot); - + TagHelper.addTag(EndTags.DRAGON_IMMUNE, ore, bars); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java b/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java index bae66336..8a06d206 100644 --- a/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/StoneMaterial.java @@ -1,11 +1,11 @@ package ru.betterend.blocks.complex; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.ItemTags; import ru.betterend.blocks.EndPedestal; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.EndFurnaceBlock; @@ -25,7 +25,7 @@ import ru.betterend.util.TagHelper; public class StoneMaterial { public final Block stone; - + public final Block polished; public final Block tiles; public final Block pillar; @@ -36,16 +36,16 @@ public class StoneMaterial { public final Block pressure_plate; public final Block pedestal; public final Block lantern; - + public final Block bricks; public final Block brick_stairs; public final Block brick_slab; public final Block brick_wall; public final Block furnace; - + public StoneMaterial(String name, MaterialColor color) { FabricBlockSettings material = FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color); - + stone = EndBlocks.registerBlock(name, new BlockBase(material)); polished = EndBlocks.registerBlock(name + "_polished", new BlockBase(material)); tiles = EndBlocks.registerBlock(name + "_tiles", new BlockBase(material)); @@ -57,62 +57,48 @@ public class StoneMaterial { pressure_plate = EndBlocks.registerBlock(name + "_plate", new EndStonelateBlock(stone)); pedestal = EndBlocks.registerBlock(name + "_pedestal", new EndPedestal(stone)); lantern = EndBlocks.registerBlock(name + "_lantern", new StoneLanternBlock(stone)); - + bricks = EndBlocks.registerBlock(name + "_bricks", new BlockBase(material)); brick_stairs = EndBlocks.registerBlock(name + "_bricks_stairs", new EndStairsBlock(bricks)); brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new EndSlabBlock(bricks)); brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new EndWallBlock(bricks)); furnace = EndBlocks.registerBlock(name + "_furnace", new EndFurnaceBlock(bricks)); - + // Recipes // - GridRecipe.make(name + "_bricks", bricks).setOutputCount(4).setShape("##", "##").addMaterial('#', stone) - .setGroup("end_bricks").build(); - GridRecipe.make(name + "_polished", polished).setOutputCount(4).setShape("##", "##").addMaterial('#', bricks) - .setGroup("end_tile").build(); - GridRecipe.make(name + "_tiles", tiles).setOutputCount(4).setShape("##", "##").addMaterial('#', polished) - .setGroup("end_small_tile").build(); - GridRecipe.make(name + "_pillar", pillar).setShape("#", "#").addMaterial('#', slab).setGroup("end_pillar") - .build(); - - GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', stone).setGroup("end_stone_stairs").build(); - GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', stone) - .setGroup("end_stone_slabs").build(); - GridRecipe.make(name + "_bricks_stairs", brick_stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', bricks).setGroup("end_stone_stairs").build(); - GridRecipe.make(name + "_bricks_slab", brick_slab).setOutputCount(6).setShape("###").addMaterial('#', bricks) - .setGroup("end_stone_slabs").build(); - - GridRecipe.make(name + "_wall", wall).setOutputCount(6).setShape("###", "###").addMaterial('#', stone) - .setGroup("end_wall").build(); - GridRecipe.make(name + "_bricks_wall", brick_wall).setOutputCount(6).setShape("###", "###") - .addMaterial('#', bricks).setGroup("end_wall").build(); - - GridRecipe.make(name + "_button", button).setList("#").addMaterial('#', stone).setGroup("end_stone_buttons") - .build(); - GridRecipe.make(name + "_pressure_plate", pressure_plate).setShape("##").addMaterial('#', stone) - .setGroup("end_stone_plates").build(); - GridRecipe.make(name + "_lantern", lantern).setShape("S", "#", "S").addMaterial('#', EndItems.CRYSTAL_SHARDS) - .addMaterial('S', slab, brick_slab).setGroup("end_stone_lanterns").build(); - GridRecipe.make(name + "_furnace", furnace).setShape("###", "# #", "###").addMaterial('#', stone) - .setGroup("end_stone_furnaces").build(); - + GridRecipe.make(name + "_bricks", bricks).setOutputCount(4).setShape("##", "##").addMaterial('#', stone).setGroup("end_bricks").build(); + GridRecipe.make(name + "_polished", polished).setOutputCount(4).setShape("##", "##").addMaterial('#', bricks).setGroup("end_tile").build(); + GridRecipe.make(name + "_tiles", tiles).setOutputCount(4).setShape("##", "##").addMaterial('#', polished).setGroup("end_small_tile").build(); + GridRecipe.make(name + "_pillar", pillar).setShape("#", "#").addMaterial('#', slab).setGroup("end_pillar").build(); + + GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', stone).setGroup("end_stone_stairs").build(); + GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', stone).setGroup("end_stone_slabs").build(); + GridRecipe.make(name + "_bricks_stairs", brick_stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', bricks).setGroup("end_stone_stairs").build(); + GridRecipe.make(name + "_bricks_slab", brick_slab).setOutputCount(6).setShape("###").addMaterial('#', bricks).setGroup("end_stone_slabs").build(); + + GridRecipe.make(name + "_wall", wall).setOutputCount(6).setShape("###", "###").addMaterial('#', stone).setGroup("end_wall").build(); + GridRecipe.make(name + "_bricks_wall", brick_wall).setOutputCount(6).setShape("###", "###").addMaterial('#', bricks).setGroup("end_wall").build(); + + GridRecipe.make(name + "_button", button).setList("#").addMaterial('#', stone).setGroup("end_stone_buttons").build(); + GridRecipe.make(name + "_pressure_plate", pressure_plate).setShape("##").addMaterial('#', stone).setGroup("end_stone_plates").build(); + GridRecipe.make(name + "_lantern", lantern).setShape("S", "#", "S").addMaterial('#', EndItems.CRYSTAL_SHARDS).addMaterial('S', slab, brick_slab).setGroup("end_stone_lanterns").build(); + GridRecipe.make(name + "_furnace", furnace).setShape("###", "# #", "###").addMaterial('#', stone).setGroup("end_stone_furnaces").build(); + CraftingRecipes.registerPedestal(name + "_pedestal", pedestal, slab, pillar); - + // Item Tags // TagHelper.addTag(ItemTags.SLABS, slab, brick_slab); TagHelper.addTag(ItemTags.STONE_BRICKS, bricks); TagHelper.addTag(ItemTags.STONE_CRAFTING_MATERIALS, stone); TagHelper.addTag(ItemTags.STONE_TOOL_MATERIALS, stone); TagHelper.addTag(EndTags.FURNACES, furnace); - + // Block Tags // TagHelper.addTag(BlockTags.STONE_BRICKS, bricks); TagHelper.addTag(BlockTags.WALLS, wall, brick_wall); TagHelper.addTag(BlockTags.SLABS, slab, brick_slab); TagHelper.addTags(pressure_plate, BlockTags.PRESSURE_PLATES, BlockTags.STONE_PRESSURE_PLATES); TagHelper.addTag(EndTags.END_STONES, stone); - + TagHelper.addTag(EndTags.DRAGON_IMMUNE, stone, stairs, slab, wall); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/complex/WoodenMaterial.java b/src/main/java/ru/betterend/blocks/complex/WoodenMaterial.java index fc426b78..f545c6b0 100644 --- a/src/main/java/ru/betterend/blocks/complex/WoodenMaterial.java +++ b/src/main/java/ru/betterend/blocks/complex/WoodenMaterial.java @@ -1,15 +1,15 @@ package ru.betterend.blocks.complex; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.MaterialColor; import ru.betterend.blocks.basis.BarkBlock; import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.EndBarrelBlock; @@ -52,28 +52,28 @@ public class WoodenMaterial { public final Block pressurePlate; public final Block trapdoor; public final Block door; - + public final Block craftingTable; public final Block ladder; public final Block sign; - + public final Block chest; public final Block barrel; public final Block shelf; public final Block composter; - + public final Tag.Named logBlockTag; public final Tag.Named logItemTag; - + public WoodenMaterial(String name, MaterialColor woodColor, MaterialColor planksColor) { FabricBlockSettings materialPlanks = FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).materialColor(planksColor); - + log_stripped = EndBlocks.registerBlock(name + "_stripped_log", new EndPillarBlock(materialPlanks)); bark_stripped = EndBlocks.registerBlock(name + "_stripped_bark", new BarkBlock(materialPlanks)); - + log = EndBlocks.registerBlock(name + "_log", new EndBlockStripableLogLog(woodColor, log_stripped)); bark = EndBlocks.registerBlock(name + "_bark", new StrippableBarkBlock(woodColor, bark_stripped)); - + planks = EndBlocks.registerBlock(name + "_planks", new BlockBase(materialPlanks)); stairs = EndBlocks.registerBlock(name + "_stairs", new EndStairsBlock(planks)); slab = EndBlocks.registerBlock(name + "_slab", new EndSlabBlock(planks)); @@ -83,59 +83,43 @@ public class WoodenMaterial { pressurePlate = EndBlocks.registerBlock(name + "_plate", new EndWoodenPlateBlock(planks)); trapdoor = EndBlocks.registerBlock(name + "_trapdoor", new EndTrapdoorBlock(planks)); door = EndBlocks.registerBlock(name + "_door", new EndDoorBlock(planks)); - + craftingTable = EndBlocks.registerBlock(name + "_crafting_table", new EndCraftingTableBlock(planks)); ladder = EndBlocks.registerBlock(name + "_ladder", new EndLadderBlock(planks)); sign = EndBlocks.registerBlock(name + "_sign", new EndSignBlock(planks)); - + chest = EndBlocks.registerBlock(name + "_chest", new EndChestBlock(planks)); barrel = EndBlocks.registerBlock(name + "_barrel", new EndBarrelBlock(planks)); shelf = EndBlocks.registerBlock(name + "_bookshelf", new EndBookshelfBlock(planks)); composter = EndBlocks.registerBlock(name + "_composter", new EndComposterBlock(planks)); - + // Recipes // - GridRecipe.make(name + "_planks", planks).setOutputCount(4).setList("#") - .addMaterial('#', log, bark, log_stripped, bark_stripped).setGroup("end_planks").build(); - GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###") - .addMaterial('#', planks).setGroup("end_planks_stairs").build(); - GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', planks) - .setGroup("end_planks_slabs").build(); - GridRecipe.make(name + "_fence", fence).setOutputCount(3).setShape("#I#", "#I#").addMaterial('#', planks) - .addMaterial('I', Items.STICK).setGroup("end_planks_fences").build(); - GridRecipe.make(name + "_gate", gate).setShape("I#I", "I#I").addMaterial('#', planks) - .addMaterial('I', Items.STICK).setGroup("end_planks_gates").build(); - GridRecipe.make(name + "_button", button).setList("#").addMaterial('#', planks).setGroup("end_planks_buttons") - .build(); - GridRecipe.make(name + "_pressure_plate", pressurePlate).setShape("##").addMaterial('#', planks) - .setGroup("end_planks_plates").build(); - GridRecipe.make(name + "_trapdoor", trapdoor).setOutputCount(2).setShape("###", "###").addMaterial('#', planks) - .setGroup("end_trapdoors").build(); - GridRecipe.make(name + "_door", door).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', planks) - .setGroup("end_doors").build(); - GridRecipe.make(name + "_crafting_table", craftingTable).setShape("##", "##").addMaterial('#', planks) - .setGroup("end_tables").build(); - GridRecipe.make(name + "_ladder", ladder).setOutputCount(3).setShape("I I", "I#I", "I I") - .addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_ladders").build(); - GridRecipe.make(name + "_sign", sign).setOutputCount(3).setShape("###", "###", " I ").addMaterial('#', planks) - .addMaterial('I', Items.STICK).setGroup("end_signs").build(); - GridRecipe.make(name + "_chest", chest).setShape("###", "# #", "###").addMaterial('#', planks) - .setGroup("end_chests").build(); - GridRecipe.make(name + "_barrel", barrel).setShape("#S#", "# #", "#S#").addMaterial('#', planks) - .addMaterial('S', slab).setGroup("end_barrels").build(); - GridRecipe.make(name + "_bookshelf", shelf).setShape("###", "PPP", "###").addMaterial('#', planks) - .addMaterial('P', Items.BOOK).setGroup("end_bookshelves").build(); + GridRecipe.make(name + "_planks", planks).setOutputCount(4).setList("#").addMaterial('#', log, bark, log_stripped, bark_stripped).setGroup("end_planks").build(); + GridRecipe.make(name + "_stairs", stairs).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', planks).setGroup("end_planks_stairs").build(); + GridRecipe.make(name + "_slab", slab).setOutputCount(6).setShape("###").addMaterial('#', planks).setGroup("end_planks_slabs").build(); + GridRecipe.make(name + "_fence", fence).setOutputCount(3).setShape("#I#", "#I#").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_planks_fences").build(); + GridRecipe.make(name + "_gate", gate).setShape("I#I", "I#I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_planks_gates").build(); + GridRecipe.make(name + "_button", button).setList("#").addMaterial('#', planks).setGroup("end_planks_buttons").build(); + GridRecipe.make(name + "_pressure_plate", pressurePlate).setShape("##").addMaterial('#', planks).setGroup("end_planks_plates").build(); + GridRecipe.make(name + "_trapdoor", trapdoor).setOutputCount(2).setShape("###", "###").addMaterial('#', planks).setGroup("end_trapdoors").build(); + GridRecipe.make(name + "_door", door).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', planks).setGroup("end_doors").build(); + GridRecipe.make(name + "_crafting_table", craftingTable).setShape("##", "##").addMaterial('#', planks).setGroup("end_tables").build(); + GridRecipe.make(name + "_ladder", ladder).setOutputCount(3).setShape("I I", "I#I", "I I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_ladders").build(); + GridRecipe.make(name + "_sign", sign).setOutputCount(3).setShape("###", "###", " I ").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup("end_signs").build(); + GridRecipe.make(name + "_chest", chest).setShape("###", "# #", "###").addMaterial('#', planks).setGroup("end_chests").build(); + GridRecipe.make(name + "_barrel", barrel).setShape("#S#", "# #", "#S#").addMaterial('#', planks).addMaterial('S', slab).setGroup("end_barrels").build(); + GridRecipe.make(name + "_bookshelf", shelf).setShape("###", "PPP", "###").addMaterial('#', planks).addMaterial('P', Items.BOOK).setGroup("end_bookshelves").build(); GridRecipe.make(name + "_bark", bark).setShape("##", "##").addMaterial('#', log).setOutputCount(3).build(); GridRecipe.make(name + "_log", log).setShape("##", "##").addMaterial('#', bark).setOutputCount(3).build(); GridRecipe.make(name + "_composter", composter).setShape("# #", "# #", "###").addMaterial('#', slab).build(); - GridRecipe.make(name + "_shulker", Items.SHULKER_BOX).setShape("S", "#", "S") - .addMaterial('S', Items.SHULKER_SHELL).addMaterial('#', chest).build(); - + GridRecipe.make(name + "_shulker", Items.SHULKER_BOX).setShape("S", "#", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('#', chest).build(); + // Item Tags // TagHelper.addTag(ItemTags.PLANKS, planks); TagHelper.addTag(ItemTags.WOODEN_PRESSURE_PLATES, pressurePlate); TagHelper.addTag(ItemTags.LOGS, log, bark, log_stripped, bark_stripped); TagHelper.addTag(ItemTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped); - + TagHelper.addTags(button, ItemTags.WOODEN_BUTTONS, ItemTags.BUTTONS); TagHelper.addTags(door, ItemTags.WOODEN_DOORS, ItemTags.DOORS); TagHelper.addTags(fence, ItemTags.WOODEN_FENCES, ItemTags.FENCES); @@ -143,13 +127,13 @@ public class WoodenMaterial { TagHelper.addTags(stairs, ItemTags.WOODEN_STAIRS, ItemTags.STAIRS); TagHelper.addTags(trapdoor, ItemTags.WOODEN_TRAPDOORS, ItemTags.TRAPDOORS); TagHelper.addTag(EndTags.ITEM_CHEST, chest); - + // Block Tags // TagHelper.addTag(BlockTags.PLANKS, planks); TagHelper.addTag(BlockTags.CLIMBABLE, ladder); TagHelper.addTag(BlockTags.LOGS, log, bark, log_stripped, bark_stripped); TagHelper.addTag(BlockTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped); - + TagHelper.addTags(button, BlockTags.WOODEN_BUTTONS, BlockTags.BUTTONS); TagHelper.addTags(door, BlockTags.WOODEN_DOORS, BlockTags.DOORS); TagHelper.addTags(fence, BlockTags.WOODEN_FENCES, BlockTags.FENCES); @@ -158,17 +142,17 @@ public class WoodenMaterial { TagHelper.addTags(trapdoor, BlockTags.WOODEN_TRAPDOORS, BlockTags.TRAPDOORS); TagHelper.addTag(EndTags.BOOKSHELVES, shelf); TagHelper.addTag(EndTags.BLOCK_CHEST, chest); - + logBlockTag = EndTags.makeBlockTag(name + "_logs"); logItemTag = EndTags.makeItemTag(name + "_logs"); TagHelper.addTag(logBlockTag, log_stripped, bark_stripped, log, bark); TagHelper.addTag(logItemTag, log_stripped, bark_stripped, log, bark); } - + public boolean isTreeLog(Block block) { return block == log || block == bark; } - + public boolean isTreeLog(BlockState state) { return isTreeLog(state.getBlock()); } diff --git a/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java index 19306898..79f78183 100644 --- a/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java +++ b/src/main/java/ru/betterend/blocks/entities/BlockEntityHydrothermalVent.java @@ -1,31 +1,32 @@ package ru.betterend.blocks.entities; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.util.Tickable; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.TickableBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.HydrothermalVentBlock; import ru.betterend.registry.EndBlockEntities; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndParticles; -public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable { +public class BlockEntityHydrothermalVent extends BlockEntity implements TickableBlockEntity { public BlockEntityHydrothermalVent() { super(EndBlockEntities.HYDROTHERMAL_VENT); } @Override public void tick() { - if (world.random.nextInt(20) == 0) { - double x = pos.getX() + world.random.nextDouble(); - double y = pos.getY() + 0.9 + world.random.nextDouble() * 0.3; - double z = pos.getZ() + world.random.nextDouble(); - BlockState state = getCachedState(); + if (level.random.nextInt(20) == 0) { + double x = worldPosition.getX() + level.random.nextDouble(); + double y = worldPosition.getY() + 0.9 + level.random.nextDouble() * 0.3; + double z = worldPosition.getZ() + level.random.nextDouble(); + BlockState state = getBlockState(); if (state.is(EndBlocks.HYDROTHERMAL_VENT) && state.getValue(HydrothermalVentBlock.ACTIVATED)) { if (state.getValue(HydrothermalVentBlock.WATERLOGGED)) { - world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); - } else { - world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); + level.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); + } + else { + level.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); } } } diff --git a/src/main/java/ru/betterend/blocks/entities/EBarrelBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/EBarrelBlockEntity.java index 1857c409..1f349112 100644 --- a/src/main/java/ru/betterend/blocks/entities/EBarrelBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/EBarrelBlockEntity.java @@ -1,89 +1,89 @@ package ru.betterend.blocks.entities; -import net.minecraft.world.level.block.BarrelBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.entity.ChestBlockEntity; -import net.minecraft.world.level.block.entity.LootableContainerBlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.world.item.ItemStack; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.core.Vec3i; import net.minecraft.nbt.CompoundTag; -import net.minecraft.screen.GenericContainerScreenHandler; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.sounds.SoundSource; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.BarrelBlock; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.EndBarrelBlock; import ru.betterend.registry.EndBlockEntities; -public class EBarrelBlockEntity extends LootableContainerBlockEntity { - private DefaultedList inventory; +public class EBarrelBlockEntity extends RandomizableContainerBlockEntity { + private NonNullList inventory; private int viewerCount; private EBarrelBlockEntity(BlockEntityType type) { super(type); - this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY); + this.inventory = NonNullList.withSize(27, ItemStack.EMPTY); } public EBarrelBlockEntity() { this(EndBlockEntities.BARREL); } - public CompoundTag toTag(CompoundTag tag) { - super.toTag(tag); - if (!this.serializeLootTable(tag)) { - Inventories.toTag(tag, this.inventory); + public CompoundTag save(CompoundTag tag) { + super.save(tag); + if (!this.trySaveLootTable(tag)) { + ContainerHelper.saveAllItems(tag, this.inventory); } return tag; } - public void fromTag(BlockState state, CompoundTag tag) { - super.fromTag(state, tag); - this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY); - if (!this.deserializeLootTable(tag)) { - Inventories.fromTag(tag, this.inventory); + public void load(BlockState state, CompoundTag tag) { + super.load(state, tag); + this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); + if (!this.tryLoadLootTable(tag)) { + ContainerHelper.loadAllItems(tag, this.inventory); } } - public int size() { + public int getContainerSize() { return 27; } - protected DefaultedList getInvStackList() { + protected NonNullList getItems() { return this.inventory; } - protected void setInvStackList(DefaultedList list) { + protected void setItems(NonNullList list) { this.inventory = list; } - protected Text getContainerName() { - return new TranslatableText("container.barrel"); + protected Component getDefaultName() { + return new TranslatableComponent("container.barrel"); } - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { - return GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, this); + protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) { + return ChestMenu.threeRows(syncId, playerInventory, this); } - public void onOpen(Player player) { + public void startOpen(Player player) { if (!player.isSpectator()) { if (this.viewerCount < 0) { this.viewerCount = 0; } ++this.viewerCount; - BlockState blockState = this.getCachedState(); - boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN); + BlockState blockState = this.getBlockState(); + boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN); if (!bl) { - this.playSound(blockState, SoundEvents.BLOCK_BARREL_OPEN); + this.playSound(blockState, SoundEvents.BARREL_OPEN); this.setOpen(blockState, true); } @@ -92,47 +92,47 @@ public class EBarrelBlockEntity extends LootableContainerBlockEntity { } private void scheduleUpdate() { - this.world.getBlockTickScheduler().schedule(this.getPos(), this.getCachedState().getBlock(), 5); + this.level.getBlockTicks().scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), 5); } public void tick() { - int i = this.pos.getX(); - int j = this.pos.getY(); - int k = this.pos.getZ(); - this.viewerCount = ChestBlockEntity.countViewers(this.world, this, i, j, k); + int i = this.worldPosition.getX(); + int j = this.worldPosition.getY(); + int k = this.worldPosition.getZ(); + this.viewerCount = ChestBlockEntity.getOpenCount(this.level, this, i, j, k); if (this.viewerCount > 0) { this.scheduleUpdate(); } else { - BlockState blockState = this.getCachedState(); + BlockState blockState = this.getBlockState(); if (!(blockState.getBlock() instanceof EndBarrelBlock)) { - this.markRemoved(); + this.setRemoved(); return; } - boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN); + boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN); if (bl) { - this.playSound(blockState, SoundEvents.BLOCK_BARREL_CLOSE); + this.playSound(blockState, SoundEvents.BARREL_CLOSE); this.setOpen(blockState, false); } } } - public void onClose(Player player) { + public void stopOpen(Player player) { if (!player.isSpectator()) { --this.viewerCount; } } private void setOpen(BlockState state, boolean open) { - this.world.setBlockAndUpdate(this.getPos(), (BlockState) state.with(BarrelBlock.OPEN, open), 3); + this.level.setBlock(this.getBlockPos(), (BlockState) state.setValue(BarrelBlock.OPEN, open), 3); } private void playSound(BlockState blockState, SoundEvent soundEvent) { - Vec3i vec3i = ((Direction) blockState.get(BarrelBlock.FACING)).getVector(); - double d = (double) this.pos.getX() + 0.5D + (double) vec3i.getX() / 2.0D; - double e = (double) this.pos.getY() + 0.5D + (double) vec3i.getY() / 2.0D; - double f = (double) this.pos.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D; - this.world.playLocalSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, - this.world.random.nextFloat() * 0.1F + 0.9F); + Vec3i vec3i = ((Direction) blockState.getValue(BarrelBlock.FACING)).getNormal(); + double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D; + double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D; + double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D; + this.level.playSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, + this.level.random.nextFloat() * 0.1F + 0.9F); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/blocks/entities/EFurnaceBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/EFurnaceBlockEntity.java index 067113b4..de59525e 100644 --- a/src/main/java/ru/betterend/blocks/entities/EFurnaceBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/EFurnaceBlockEntity.java @@ -1,12 +1,12 @@ package ru.betterend.blocks.entities; -import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; -import net.minecraft.world.entity.player.PlayerInventory; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.FurnaceMenu; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.screen.FurnaceScreenHandler; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; import ru.betterend.registry.EndBlockEntities; public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity { @@ -14,11 +14,11 @@ public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity { super(EndBlockEntities.FURNACE, RecipeType.SMELTING); } - protected Text getContainerName() { - return new TranslatableText("container.furnace"); + protected Component getDefaultName() { + return new TranslatableComponent("container.furnace"); } - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { - return new FurnaceScreenHandler(syncId, playerInventory, this, this.propertyDelegate); + protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) { + return new FurnaceMenu(syncId, playerInventory, this, this.dataAccess); } } diff --git a/src/main/java/ru/betterend/blocks/entities/EndStoneSmelterBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/EndStoneSmelterBlockEntity.java index 9661b381..7f3672d2 100644 --- a/src/main/java/ru/betterend/blocks/entities/EndStoneSmelterBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/EndStoneSmelterBlockEntity.java @@ -10,99 +10,98 @@ import com.google.common.collect.Maps; import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.fabricmc.fabric.api.registry.FuelRegistry; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; -import net.minecraft.world.level.block.entity.LockableContainerBlockEntity; -import net.minecraft.world.entity.ExperienceOrbEntity; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.player.PlayerInventory; -import net.minecraft.inventory.Inventories; -import net.minecraft.inventory.SidedInventory; +import net.minecraft.world.entity.player.StackedContents; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.RecipeHolder; +import net.minecraft.world.inventory.StackedContentsCompatible; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.crafting.BlastingRecipe; import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.world.item.crafting.RecipeFinder; -import net.minecraft.world.item.crafting.RecipeInputProvider; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.crafting.RecipeUnlocker; -import net.minecraft.screen.PropertyDelegate; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Tickable; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.core.Direction; -import net.minecraft.util.Mth; -import net.minecraft.util.math.Vec3d; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.entity.TickableBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; import ru.betterend.BetterEnd; import ru.betterend.blocks.EndStoneSmelter; import ru.betterend.client.gui.EndStoneSmelterScreenHandler; import ru.betterend.recipe.builders.AlloyingRecipe; import ru.betterend.registry.EndBlockEntities; -public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity - implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable { +public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, TickableBlockEntity { private static final int[] TOP_SLOTS = new int[] { 0, 1 }; private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 }; private static final int[] SIDE_SLOTS = new int[] { 1, 2 }; private static final Map AVAILABLE_FUELS = Maps.newHashMap(); - + private final Object2IntOpenHashMap recipesUsed; - protected DefaultedList inventory; - protected final PropertyDelegate propertyDelegate; + protected NonNullList inventory; + protected final ContainerData propertyDelegate; private Recipe lastRecipe; private int smeltTimeTotal; private int smeltTime; private int burnTime; private int fuelTime; - + public EndStoneSmelterBlockEntity() { super(EndBlockEntities.END_STONE_SMELTER); - this.inventory = DefaultedList.ofSize(4, ItemStack.EMPTY); + this.inventory = NonNullList.withSize(4, ItemStack.EMPTY); this.recipesUsed = new Object2IntOpenHashMap<>(); - this.propertyDelegate = new PropertyDelegate() { - public int get(int index) { - switch (index) { - case 0: - return EndStoneSmelterBlockEntity.this.burnTime; - case 1: - return EndStoneSmelterBlockEntity.this.fuelTime; - case 2: - return EndStoneSmelterBlockEntity.this.smeltTime; - case 3: - return EndStoneSmelterBlockEntity.this.smeltTimeTotal; - default: - return 0; - } - } + this.propertyDelegate = new ContainerData() { + public int get(int index) { + switch(index) { + case 0: + return EndStoneSmelterBlockEntity.this.burnTime; + case 1: + return EndStoneSmelterBlockEntity.this.fuelTime; + case 2: + return EndStoneSmelterBlockEntity.this.smeltTime; + case 3: + return EndStoneSmelterBlockEntity.this.smeltTimeTotal; + default: + return 0; + } + } - public void set(int index, int value) { - switch (index) { - case 0: - EndStoneSmelterBlockEntity.this.burnTime = value; - break; - case 1: - EndStoneSmelterBlockEntity.this.fuelTime = value; - break; - case 2: - EndStoneSmelterBlockEntity.this.smeltTime = value; - break; - case 3: - EndStoneSmelterBlockEntity.this.smeltTimeTotal = value; - } - } + public void set(int index, int value) { + switch(index) { + case 0: + EndStoneSmelterBlockEntity.this.burnTime = value; + break; + case 1: + EndStoneSmelterBlockEntity.this.fuelTime = value; + break; + case 2: + EndStoneSmelterBlockEntity.this.smeltTime = value; + break; + case 3: + EndStoneSmelterBlockEntity.this.smeltTimeTotal = value; + } + } - public int size() { - return 4; - } - }; + public int getCount() { + return 4; + } + }; } private boolean isBurning() { @@ -110,7 +109,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } @Override - public int size() { + public int getContainerSize() { return this.inventory.size(); } @@ -129,103 +128,101 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } @Override - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return this.inventory.get(slot); } @Override - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(this.inventory, slot, amount); + public ItemStack removeItem(int slot, int amount) { + return ContainerHelper.removeItem(this.inventory, slot, amount); } @Override - public ItemStack removeStack(int slot) { - return Inventories.removeStack(this.inventory, slot); + public ItemStack removeItemNoUpdate(int slot) { + return ContainerHelper.takeItem(this.inventory, slot); } @Override - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { ItemStack itemStack = this.inventory.get(slot); - boolean stackValid = !stack.isEmpty() && stack.isItemEqualIgnoreDamage(itemStack) - && ItemStack.areTagsEqual(stack, itemStack); + boolean stackValid = !stack.isEmpty() && stack.sameItem(itemStack) && ItemStack.tagMatches(stack, itemStack); this.inventory.set(slot, stack); - if (stack.getCount() > getMaxCountPerStack()) { - stack.setCount(getMaxCountPerStack()); + if (stack.getCount() > getMaxStackSize()) { + stack.setCount(getMaxStackSize()); } if ((slot == 0 || slot == 1) && !stackValid) { this.smeltTimeTotal = this.getSmeltTime(); this.smeltTime = 0; - this.markDirty(); + this.setChanged(); } } - + protected int getSmeltTime() { - assert this.world != null; - int smeltTime = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world) + assert this.level != null; + int smeltTime = this.level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level) .map(AlloyingRecipe::getSmeltTime).orElse(0); if (smeltTime == 0) { - smeltTime = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world) - .map(BlastingRecipe::getCookTime).orElse(200); + smeltTime = this.level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level) + .map(BlastingRecipe::getCookingTime).orElse(200); smeltTime /= 1.5; } return smeltTime; } - + public void dropExperience(Player player) { - assert world != null; + assert level != null; List> list = Lists.newArrayList(); for (Entry entry : this.recipesUsed.object2IntEntrySet()) { - world.getRecipeManager().get(entry.getKey()).ifPresent((recipe) -> { + level.getRecipeManager().byKey(entry.getKey()).ifPresent((recipe) -> { list.add(recipe); if (recipe instanceof AlloyingRecipe) { AlloyingRecipe alloying = (AlloyingRecipe) recipe; - this.dropExperience(player.world, player.getPos(), entry.getIntValue(), alloying.getExperience()); + this.dropExperience(player.level, player.position(), entry.getIntValue(), alloying.getExperience()); } else { BlastingRecipe blasting = (BlastingRecipe) recipe; - this.dropExperience(player.world, player.getPos(), entry.getIntValue(), blasting.getExperience()); + this.dropExperience(player.level, player.position(), entry.getIntValue(), blasting.getExperience()); } }); } - player.unlockRecipes(list); + player.awardRecipes(list); this.recipesUsed.clear(); } - - private void dropExperience(Level world, Vec3d vec3d, int i, float f) { + + private void dropExperience(Level world, Vec3 vec3d, int i, float f) { int j = Mth.floor(i * f); - float g = Mth.fractionalPart(i * f); + float g = Mth.frac(i * f); if (g != 0.0F && Math.random() < g) { j++; } - while (j > 0) { - int k = ExperienceOrbEntity.roundToOrbSize(j); + while(j > 0) { + int k = ExperienceOrb.getExperienceValue(j); j -= k; - world.spawnEntity(new ExperienceOrbEntity(world, vec3d.x, vec3d.y, vec3d.z, k)); + world.addFreshEntity(new ExperienceOrb(world, vec3d.x, vec3d.y, vec3d.z, k)); } } @Override - public boolean canPlayerUse(Player player) { - assert this.world != null; - if (this.world.getBlockEntity(this.pos) != this) { + public boolean stillValid(Player player) { + assert this.level != null; + if (this.level.getBlockEntity(this.worldPosition) != this) { return false; } - return player.squaredDistanceTo(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, - this.pos.getZ() + 0.5D) <= 64.0D; + return player.distanceToSqr(this.worldPosition.getX() + 0.5D, this.worldPosition.getY() + 0.5D, this.worldPosition.getZ() + 0.5D) <= 64.0D; } @Override - public void clear() { + public void clearContent() { this.inventory.clear(); } @Override - protected Text getContainerName() { - return new TranslatableText(String.format("block.%s.%s", BetterEnd.MOD_ID, EndStoneSmelter.ID)); + protected Component getDefaultName() { + return new TranslatableComponent(String.format("block.%s.%s", BetterEnd.MOD_ID, EndStoneSmelter.ID)); } @Override - protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) { return new EndStoneSmelterScreenHandler(syncId, playerInventory, this, propertyDelegate); } @@ -237,18 +234,17 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } boolean burning = this.isBurning(); - assert this.world != null; - if (!this.world.isClientSide) { + assert this.level != null; + if (!this.level.isClientSide) { ItemStack fuel = this.inventory.get(2); if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) { if (smeltTime > 0) { this.smeltTime = Mth.clamp(smeltTime - 2, 0, smeltTimeTotal); } } else { - Recipe recipe = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world) - .orElse(null); + Recipe recipe = this.level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level).orElse(null); if (recipe == null) { - recipe = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world).orElse(null); + recipe = this.level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level).orElse(null); } boolean accepted = this.canAcceptRecipeOutput(recipe); if (!burning && accepted) { @@ -258,13 +254,13 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity if (burning) { if (!fuel.isEmpty()) { Item item = fuel.getItem(); - fuel.decrement(1); + fuel.shrink(1); if (fuel.isEmpty()) { - Item remainFuel = item.getRecipeRemainder(); + Item remainFuel = item.getCraftingRemainingItem(); this.inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel)); } } - this.markDirty(); + this.setChanged(); } } @@ -274,7 +270,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity this.smeltTime = 0; this.smeltTimeTotal = this.getSmeltTime(); this.craftRecipe(recipe); - this.markDirty(); + this.setChanged(); } } else { this.smeltTime = 0; @@ -282,23 +278,24 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } if (initialBurning != burning) { - this.world.setBlockAndUpdate(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3); - this.markDirty(); + this.level.setBlock(worldPosition, level.getBlockState(worldPosition).setValue(EndStoneSmelter.LIT, burning), 3); + this.setChanged(); } } } - + protected boolean canAcceptRecipeOutput(Recipe recipe) { - if (recipe == null) - return false; + if (recipe == null) return false; boolean validInput; if (recipe instanceof AlloyingRecipe) { - validInput = !inventory.get(0).isEmpty() && !inventory.get(1).isEmpty(); + validInput = !inventory.get(0).isEmpty() && + !inventory.get(1).isEmpty(); } else { - validInput = !inventory.get(0).isEmpty() || !inventory.get(1).isEmpty(); + validInput = !inventory.get(0).isEmpty() || + !inventory.get(1).isEmpty(); } if (validInput) { - ItemStack result = recipe.getOutput(); + ItemStack result = recipe.getResultItem(); if (result.isEmpty()) { return false; } @@ -308,55 +305,54 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity if (output.isEmpty()) { return true; } - if (!output.isItemEqualIgnoreDamage(result)) { + if (!output.sameItem(result)) { return false; } - if (outCount < this.getMaxCountPerStack() && outCount < output.getMaxCount()) { - return this.getMaxCountPerStack() >= total; + if (outCount < this.getMaxStackSize() && outCount < output.getMaxStackSize()) { + return this.getMaxStackSize() >= total; } - return output.getCount() < result.getMaxCount(); + return output.getCount() < result.getMaxStackSize(); } return false; } private void craftRecipe(Recipe recipe) { - if (recipe == null || !canAcceptRecipeOutput(recipe)) - return; - - ItemStack result = recipe.getOutput(); + if (recipe == null || !canAcceptRecipeOutput(recipe)) return; + + ItemStack result = recipe.getResultItem(); ItemStack output = this.inventory.get(3); if (output.isEmpty()) { this.inventory.set(3, result.copy()); } else if (output.getItem() == result.getItem()) { - output.increment(result.getCount()); + output.grow(result.getCount()); } - assert this.world != null; - if (!this.world.isClientSide) { - this.setLastRecipe(recipe); + assert this.level != null; + if (!this.level.isClientSide) { + this.setRecipeUsed(recipe); } - + if (recipe instanceof AlloyingRecipe) { - this.inventory.get(0).decrement(1); - this.inventory.get(1).decrement(1); + this.inventory.get(0).shrink(1); + this.inventory.get(1).shrink(1); } else { if (!this.inventory.get(0).isEmpty()) { - this.inventory.get(0).decrement(1); + this.inventory.get(0).shrink(1); } else { - this.inventory.get(1).decrement(1); + this.inventory.get(1).shrink(1); } } } @Override - public void provideRecipeInputs(RecipeFinder finder) { + public void fillStackedContents(StackedContents finder) { for (ItemStack itemStack : this.inventory) { - finder.addItem(itemStack); + finder.accountStack(itemStack); } } @Override - public void setLastRecipe(Recipe recipe) { + public void setRecipeUsed(Recipe recipe) { if (recipe != null) { ResourceLocation recipeId = recipe.getId(); this.recipesUsed.addTo(recipeId, 1); @@ -365,12 +361,12 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } @Override - public Recipe getLastRecipe() { + public Recipe getRecipeUsed() { return this.lastRecipe; } @Override - public int[] getAvailableSlots(Direction side) { + public int[] getSlotsForFace(Direction side) { if (side == Direction.DOWN) { return BOTTOM_SLOTS; } @@ -378,12 +374,12 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity } @Override - public boolean canInsert(int slot, ItemStack stack, Direction dir) { - return this.isValid(slot, stack); + public boolean canPlaceItemThroughFace(int slot, ItemStack stack, Direction dir) { + return this.canPlaceItem(slot, stack); } @Override - public boolean canExtract(int slot, ItemStack stack, Direction dir) { + public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) { if (dir == Direction.DOWN && slot == 2) { return stack.getItem() == Items.BUCKET; } @@ -397,38 +393,38 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity Item item = fuel.getItem(); return AVAILABLE_FUELS.getOrDefault(item, getFabricFuel(fuel)); } - + @Override - public void fromTag(BlockState state, CompoundTag tag) { - super.fromTag(state, tag); - this.inventory = DefaultedList.ofSize(size(), ItemStack.EMPTY); - Inventories.fromTag(tag, inventory); + public void load(BlockState state, CompoundTag tag) { + super.load(state, tag); + this.inventory = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY); + ContainerHelper.loadAllItems(tag, inventory); this.burnTime = tag.getShort("BurnTime"); this.fuelTime = tag.getShort("FuelTime"); this.smeltTime = tag.getShort("SmeltTime"); this.smeltTimeTotal = tag.getShort("SmeltTimeTotal"); CompoundTag compoundTag = tag.getCompound("RecipesUsed"); - for (String id : compoundTag.getKeys()) { + for (String id : compoundTag.getAllKeys()) { this.recipesUsed.put(new ResourceLocation(id), compoundTag.getInt(id)); } } - + @Override - public CompoundTag toTag(CompoundTag tag) { - super.toTag(tag); + public CompoundTag save(CompoundTag tag) { + super.save(tag); tag.putShort("BurnTime", (short) burnTime); tag.putShort("FuelTime", (short) fuelTime); tag.putShort("SmeltTime", (short) smeltTime); tag.putShort("SmeltTimeTotal", (short) smeltTimeTotal); - Inventories.toTag(tag, inventory); + ContainerHelper.saveAllItems(tag, inventory); CompoundTag usedRecipes = new CompoundTag(); this.recipesUsed.forEach((identifier, integer) -> usedRecipes.putInt(identifier.toString(), integer)); tag.put("RecipesUsed", usedRecipes); - + return tag; } - - public boolean isValid(int slot, ItemStack stack) { + + public boolean canPlaceItem(int slot, ItemStack stack) { if (slot == 3) { return false; } else if (slot != 2) { @@ -449,14 +445,14 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity public static Map availableFuels() { return AVAILABLE_FUELS; } - + private static int getFabricFuel(ItemStack stack) { Integer ticks = FuelRegistry.INSTANCE.get(stack.getItem()); return ticks == null ? 0 : ticks; } static { - AbstractFurnaceBlockEntity.createFuelTimeMap().forEach((item, time) -> { + AbstractFurnaceBlockEntity.getFuel().forEach((item, time) -> { if (time >= 2000) { registerFuel(item, time); } diff --git a/src/main/java/ru/betterend/blocks/entities/EternalPedestalEntity.java b/src/main/java/ru/betterend/blocks/entities/EternalPedestalEntity.java index f6ab8e2b..d4da8a18 100644 --- a/src/main/java/ru/betterend/blocks/entities/EternalPedestalEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/EternalPedestalEntity.java @@ -1,51 +1,51 @@ package ru.betterend.blocks.entities; -import net.minecraft.nbt.CompoundTag; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import ru.betterend.registry.EndBlockEntities; import ru.betterend.rituals.EternalRitual; public class EternalPedestalEntity extends PedestalBlockEntity { private EternalRitual linkedRitual; - + public EternalPedestalEntity() { super(EndBlockEntities.ETERNAL_PEDESTAL); } - + public boolean hasRitual() { return linkedRitual != null; } - + public void linkRitual(EternalRitual ritual) { this.linkedRitual = ritual; } - + public EternalRitual getRitual() { return linkedRitual; } - + @Override - public void setLocation(Level world, BlockPos pos) { - super.setLocation(world, pos); + public void setLevelAndPosition(Level world, BlockPos pos) { + super.setLevelAndPosition(world, pos); if (hasRitual()) { linkedRitual.setWorld(world); } } @Override - public CompoundTag toTag(CompoundTag tag) { + public CompoundTag save(CompoundTag tag) { if (hasRitual()) { tag.put("ritual", linkedRitual.toTag(new CompoundTag())); } - return super.toTag(tag); + return super.save(tag); } @Override protected void fromTag(CompoundTag tag) { super.fromTag(tag); if (tag.contains("ritual")) { - linkedRitual = new EternalRitual(world); + linkedRitual = new EternalRitual(level); linkedRitual.fromTag(tag.getCompound("ritual")); } } diff --git a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java index f0151b12..51e1aac7 100644 --- a/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/InfusionPedestalEntity.java @@ -1,7 +1,7 @@ package ru.betterend.blocks.entities; -import net.minecraft.nbt.CompoundTag; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import ru.betterend.registry.EndBlockEntities; import ru.betterend.rituals.InfusionRitual; @@ -9,31 +9,31 @@ import ru.betterend.rituals.InfusionRitual; public class InfusionPedestalEntity extends PedestalBlockEntity { private InfusionRitual linkedRitual; - + public InfusionPedestalEntity() { super(EndBlockEntities.INFUSION_PEDESTAL); } - + @Override - public void setLocation(Level world, BlockPos pos) { - super.setLocation(world, pos); + public void setLevelAndPosition(Level world, BlockPos pos) { + super.setLevelAndPosition(world, pos); if (hasRitual()) { linkedRitual.setLocation(world, pos); } } - + public void linkRitual(InfusionRitual ritual) { linkedRitual = ritual; } - + public InfusionRitual getRitual() { return linkedRitual; } - + public boolean hasRitual() { return linkedRitual != null; } - + @Override public void tick() { if (hasRitual()) { @@ -43,18 +43,18 @@ public class InfusionPedestalEntity extends PedestalBlockEntity { } @Override - public CompoundTag toTag(CompoundTag tag) { + public CompoundTag save(CompoundTag tag) { if (hasRitual()) { tag.put("ritual", linkedRitual.toTag(new CompoundTag())); } - return super.toTag(tag); + return super.save(tag); } @Override protected void fromTag(CompoundTag tag) { super.fromTag(tag); if (tag.contains("ritual")) { - linkedRitual = new InfusionRitual(world, pos); + linkedRitual = new InfusionRitual(level, worldPosition); linkedRitual.fromTag(tag.getCompound("ritual")); } } diff --git a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java index a8e6a7e9..f9e475be 100644 --- a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java @@ -1,42 +1,42 @@ package ru.betterend.blocks.entities; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.entity.player.Player; -import net.minecraft.inventory.Inventory; -import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.util.Tickable; +import net.minecraft.world.level.block.entity.TickableBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.registry.EndBlockEntities; import ru.betterend.registry.EndItems; -public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable, BlockEntityClientSerializable { +public class PedestalBlockEntity extends BlockEntity implements Container, TickableBlockEntity, BlockEntityClientSerializable { private ItemStack activeItem = ItemStack.EMPTY; - + private final int maxAge = 314; private int age; - + public PedestalBlockEntity() { super(EndBlockEntities.PEDESTAL); } - + public PedestalBlockEntity(BlockEntityType type) { super(type); } - + public int getAge() { return age; } - + public int getMaxAge() { return maxAge; } @Override - public int size() { + public int getContainerSize() { return 1; } @@ -46,71 +46,72 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka } @Override - public ItemStack getStack(int slot) { + public ItemStack getItem(int slot) { return activeItem; } @Override - public ItemStack removeStack(int slot, int amount) { - return removeStack(slot); + public ItemStack removeItem(int slot, int amount) { + return removeItemNoUpdate(slot); } - + @Override - public boolean isValid(int slot, ItemStack stack) { + public boolean canPlaceItem(int slot, ItemStack stack) { return isEmpty(); } @Override - public void clear() { + public void clearContent() { activeItem = ItemStack.EMPTY; - markDirty(); + setChanged(); } @Override - public ItemStack removeStack(int slot) { + public ItemStack removeItemNoUpdate(int slot) { ItemStack stored = activeItem; - clear(); + clearContent(); return stored; } @Override - public void setStack(int slot, ItemStack stack) { + public void setItem(int slot, ItemStack stack) { activeItem = stack; - markDirty(); + setChanged(); } - + @Override - public void markDirty() { - if (world != null && !world.isClientSide) { - BlockState state = world.getBlockState(pos); + public void setChanged() { + if (level != null && !level.isClientSide) { + BlockState state = level.getBlockState(worldPosition); if (state.getBlock() instanceof PedestalBlock) { - BlockState trueState = state.with(PedestalBlock.HAS_ITEM, !isEmpty()); + BlockState trueState = state.setValue(PedestalBlock.HAS_ITEM, !isEmpty()); if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) { - trueState = trueState.with(PedestalBlock.HAS_LIGHT, true); + trueState = trueState.setValue(PedestalBlock.HAS_LIGHT, true); } else { - trueState = trueState.with(PedestalBlock.HAS_LIGHT, false); + trueState = trueState.setValue(PedestalBlock.HAS_LIGHT, false); } - world.setBlockAndUpdate(pos, trueState); + level.setBlockAndUpdate(worldPosition, trueState); } } - super.markDirty(); + super.setChanged(); } + @Override - public boolean canPlayerUse(Player player) { + public boolean stillValid(Player player) { return true; } - + @Override - public void fromTag(BlockState state, CompoundTag tag) { - super.fromTag(state, tag); + public void load(BlockState state, CompoundTag tag) { + super.load(state, tag); fromTag(tag); } @Override - public CompoundTag toTag(CompoundTag tag) { - tag.put("active_item", activeItem.toTag(new CompoundTag())); - return super.toTag(tag); + public CompoundTag save(CompoundTag tag) { + tag.put("active_item", activeItem.save(new CompoundTag())); + return super.save(tag); } @Override @@ -120,13 +121,13 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka @Override public CompoundTag toClientTag(CompoundTag tag) { - return toTag(tag); + return save(tag); } protected void fromTag(CompoundTag tag) { if (tag.contains("active_item")) { CompoundTag itemTag = tag.getCompound("active_item"); - activeItem = ItemStack.fromTag(itemTag); + activeItem = ItemStack.of(itemTag); } } diff --git a/src/main/java/ru/betterend/blocks/entities/render/EndChestBlockEntityRenderer.java b/src/main/java/ru/betterend/blocks/entities/render/EndChestBlockEntityRenderer.java index 24bc27b9..2b6b7838 100644 --- a/src/main/java/ru/betterend/blocks/entities/render/EndChestBlockEntityRenderer.java +++ b/src/main/java/ru/betterend/blocks/entities/render/EndChestBlockEntityRenderer.java @@ -1,43 +1,41 @@ package ru.betterend.blocks.entities.render; import java.util.HashMap; - -import com.google.common.collect.Maps; - -import it.unimi.dsi.fastutil.floats.Float2FloatFunction; -import it.unimi.dsi.fastutil.ints.Int2IntFunction; -import net.minecraft.world.level.block.AbstractChestBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ChestBlock; -import net.minecraft.world.level.block.DoubleBlockProperties; -import net.minecraft.world.level.block.DoubleBlockProperties.PropertySource; -import net.minecraft.world.level.block.entity.ChestBlockEntity; -import net.minecraft.world.level.block.enums.ChestType; -import net.minecraft.client.block.ChestAnimationProgress; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; -import net.minecraft.client.render.block.entity.BlockEntityRenderer; -import net.minecraft.client.render.block.entity.LightmapCoordinatesRetriever; -import net.minecraft.client.util.math.MatrixStack; -import com.mojang.math.Vector3f; -import net.minecraft.world.item.BlockItem; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BrightnessCombiner; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.AbstractChestBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChestBlock; +import net.minecraft.world.level.block.DoubleBlockCombiner; +import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.world.level.block.entity.LidBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.ChestType; +import com.google.common.collect.Maps; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Vector3f; +import it.unimi.dsi.fastutil.floats.Float2FloatFunction; +import it.unimi.dsi.fastutil.ints.Int2IntFunction; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.EndChestBlock; import ru.betterend.blocks.entities.EChestBlockEntity; import ru.betterend.registry.EndItems; public class EndChestBlockEntityRenderer extends BlockEntityRenderer { - private static final HashMap LAYERS = Maps.newHashMap(); - private static RenderLayer[] defaultLayer; + private static final HashMap LAYERS = Maps.newHashMap(); + private static RenderType[] defaultLayer; private static final int ID_NORMAL = 0; private static final int ID_LEFT = 1; @@ -57,97 +55,88 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer abstractChestBlock = (AbstractChestBlock) block; boolean isDouble = chestType != ChestType.SINGLE; - float f = ((Direction) blockState.get(ChestBlock.FACING)).asRotation(); - PropertySource propertySource; + float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot(); + NeighborCombineResult propertySource; - matrices.push(); + matrices.pushPose(); matrices.translate(0.5D, 0.5D, 0.5D); - matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-f)); + matrices.mulPose(Vector3f.YP.rotationDegrees(-f)); matrices.translate(-0.5D, -0.5D, -0.5D); if (worldExists) { - propertySource = abstractChestBlock.getBlockEntitySource(blockState, world, entity.getPos(), true); + propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true); } else { - propertySource = DoubleBlockProperties.PropertyRetriever::getFallback; + propertySource = DoubleBlockCombiner.Combiner::acceptNone; } - float pitch = ((Float2FloatFunction) propertySource - .apply(ChestBlock.getAnimationProgressRetriever((ChestAnimationProgress) entity))).get(tickDelta); + float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta); pitch = 1.0F - pitch; pitch = 1.0F - pitch * pitch * pitch; @SuppressWarnings({ "unchecked", "rawtypes" }) - int blockLight = ((Int2IntFunction) propertySource.apply(new LightmapCoordinatesRetriever())) - .applyAsInt(light); + int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light); VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType); if (isDouble) { if (chestType == ChestType.LEFT) { - renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, - blockLight, overlay); + renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay); } else { - renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, - blockLight, overlay); + renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay); } } else { renderParts(matrices, vertexConsumer, this.partA, this.partB, this.partC, pitch, blockLight, overlay); } - matrices.pop(); + matrices.popPose(); } } - private void renderParts(MatrixStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, - ModelPart modelPart3, float pitch, int light, int overlay) { - modelPart.pitch = -(pitch * 1.5707964F); - modelPart2.pitch = modelPart.pitch; + private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) { + modelPart.xRot = -(pitch * 1.5707964F); + modelPart2.xRot = modelPart.xRot; modelPart.render(matrices, vertices, light, overlay); modelPart2.render(matrices, vertices, light, overlay); modelPart3.render(matrices, vertices, light, overlay); } - private static RenderLayer getChestTexture(ChestType type, RenderLayer[] layers) { + private static RenderType getChestTexture(ChestType type, RenderType[] layers) { switch (type) { case LEFT: return layers[ID_LEFT]; @@ -159,28 +148,28 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer { if (item instanceof BlockItem) { Block block = ((BlockItem) item).getBlock(); if (block instanceof EndChestBlock) { String name = Registry.BLOCK.getKey(block).getPath(); - LAYERS.put(block, new RenderLayer[] { - RenderLayer.getEntityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")), - RenderLayer - .getEntityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")), - RenderLayer.getEntityCutout( - BetterEnd.makeID("textures/entity/chest/" + name + "_right.png")) }); + LAYERS.put(block, new RenderType[] { + RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")), + RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")), + RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_right.png")) + }); } } }); diff --git a/src/main/java/ru/betterend/blocks/entities/render/EndSignBlockEntityRenderer.java b/src/main/java/ru/betterend/blocks/entities/render/EndSignBlockEntityRenderer.java index 287f9ec6..9c979617 100644 --- a/src/main/java/ru/betterend/blocks/entities/render/EndSignBlockEntityRenderer.java +++ b/src/main/java/ru/betterend/blocks/entities/render/EndSignBlockEntityRenderer.java @@ -2,122 +2,119 @@ package ru.betterend.blocks.entities.render; import java.util.HashMap; import java.util.List; - -import com.google.common.collect.Maps; - -import net.minecraft.world.level.block.SignBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.SignBlock; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.TexturedRenderLayers; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; -import net.minecraft.client.render.block.entity.BlockEntityRenderer; -import net.minecraft.client.render.block.entity.SignBlockEntityRenderer; -import net.minecraft.client.render.block.entity.SignBlockEntityRenderer.SignModel; -import net.minecraft.client.texture.NativeImage; -import net.minecraft.client.util.SpriteIdentifier; -import net.minecraft.client.util.math.MatrixStack; -import com.mojang.math.Vector3f; -import net.minecraft.world.item.BlockItem; -import net.minecraft.text.OrderedText; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.SignType; +import net.minecraft.client.gui.Font; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.Sheets; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.SignRenderer; +import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel; +import net.minecraft.client.resources.model.Material; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SignBlock; +import net.minecraft.world.level.block.StandingSignBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.WoodType; +import com.google.common.collect.Maps; +import com.mojang.blaze3d.platform.NativeImage; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Vector3f; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.EndSignBlock; import ru.betterend.blocks.entities.ESignBlockEntity; import ru.betterend.registry.EndItems; public class EndSignBlockEntityRenderer extends BlockEntityRenderer { - private static final HashMap LAYERS = Maps.newHashMap(); - private static RenderLayer defaultLayer; - private final SignModel model = new SignBlockEntityRenderer.SignModel(); + private static final HashMap LAYERS = Maps.newHashMap(); + private static RenderType defaultLayer; + private final SignModel model = new SignRenderer.SignModel(); public EndSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) { super(dispatcher); } - public void render(ESignBlockEntity signBlockEntity, float tickDelta, MatrixStack matrixStack, - VertexConsumerProvider provider, int light, int overlay) { - BlockState state = signBlockEntity.getCachedState(); - matrixStack.push(); + public void render(ESignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack, + MultiBufferSource provider, int light, int overlay) { + BlockState state = signBlockEntity.getBlockState(); + matrixStack.pushPose(); matrixStack.translate(0.5D, 0.5D, 0.5D); - float angle = -((float) ((Integer) state.getValue(SignBlock.ROTATION) * 360) / 16.0F); + float angle = -((float) ((Integer) state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F); - BlockState blockState = signBlockEntity.getCachedState(); - if (blockState.get(EndSignBlock.FLOOR)) { - matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle)); - this.model.foot.visible = true; + BlockState blockState = signBlockEntity.getBlockState(); + if (blockState.getValue(EndSignBlock.FLOOR)) { + matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle)); + this.model.stick.visible = true; } else { - matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle + 180)); + matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180)); matrixStack.translate(0.0D, -0.3125D, -0.4375D); - this.model.foot.visible = false; + this.model.stick.visible = false; } - matrixStack.push(); + matrixStack.pushPose(); matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F); VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock()); - model.field.render(matrixStack, vertexConsumer, light, overlay); - model.foot.render(matrixStack, vertexConsumer, light, overlay); - matrixStack.pop(); - TextRenderer textRenderer = dispatcher.getTextRenderer(); + model.sign.render(matrixStack, vertexConsumer, light, overlay); + model.stick.render(matrixStack, vertexConsumer, light, overlay); + matrixStack.popPose(); + Font textRenderer = renderer.getFont(); matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D); matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F); - int m = signBlockEntity.getTextColor().getSignColor(); - int n = (int) (NativeImage.getRed(m) * 0.4D); - int o = (int) (NativeImage.getGreen(m) * 0.4D); - int p = (int) (NativeImage.getBlue(m) * 0.4D); - int q = NativeImage.getAbgrColor(0, p, o, n); + int m = signBlockEntity.getColor().getTextColor(); + int n = (int) (NativeImage.getR(m) * 0.4D); + int o = (int) (NativeImage.getG(m) * 0.4D); + int p = (int) (NativeImage.getB(m) * 0.4D); + int q = NativeImage.combine(0, p, o, n); for (int s = 0; s < 4; ++s) { - OrderedText orderedText = signBlockEntity.getTextBeingEditedOnRow(s, (text) -> { - List list = textRenderer.wrapLines(text, 90); - return list.isEmpty() ? OrderedText.EMPTY : (OrderedText) list.get(0); + FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> { + List list = textRenderer.split(text, 90); + return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0); }); if (orderedText != null) { - float t = (float) (-textRenderer.getWidth(orderedText) / 2); - textRenderer.draw((OrderedText) orderedText, t, (float) (s * 10 - 20), q, false, - matrixStack.peek().getModel(), provider, false, 0, light); + float t = (float) (-textRenderer.width(orderedText) / 2); + textRenderer.drawInBatch((FormattedCharSequence) orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light); } } - matrixStack.pop(); + matrixStack.popPose(); } - public static SpriteIdentifier getModelTexture(Block block) { - SignType signType2; + public static Material getModelTexture(Block block) { + WoodType signType2; if (block instanceof SignBlock) { - signType2 = ((SignBlock) block).getSignType(); + signType2 = ((SignBlock) block).type(); } else { - signType2 = SignType.OAK; + signType2 = WoodType.OAK; } - return TexturedRenderLayers.getSignTextureId(signType2); + return Sheets.signTexture(signType2); } - - public static VertexConsumer getConsumer(VertexConsumerProvider provider, Block block) { + + public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) { return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer)); } static { - defaultLayer = RenderLayer.getEntitySolid(new ResourceLocation("textures/entity/sign/oak.png")); - + defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/sign/oak.png")); + EndItems.getModBlocks().forEach((item) -> { if (item instanceof BlockItem) { Block block = ((BlockItem) item).getBlock(); if (block instanceof EndSignBlock) { String name = Registry.BLOCK.getKey(block).getPath(); - RenderLayer layer = RenderLayer - .getEntitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png")); + RenderType layer = RenderType.entitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png")); LAYERS.put(block, layer); } } }); } + } diff --git a/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java b/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java index 9f876575..d989e57d 100644 --- a/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java +++ b/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java @@ -1,21 +1,21 @@ package ru.betterend.blocks.entities.render; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; -import net.minecraft.client.render.block.entity.BlockEntityRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; -import net.minecraft.client.util.math.MatrixStack; -import com.mojang.math.Vector3f; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.util.Mth; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.util.Mth; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.EternalPedestal; import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.entities.PedestalBlockEntity; @@ -27,31 +27,29 @@ import ru.betterend.registry.EndItems; @Environment(EnvType.CLIENT) public class PedestalItemRenderer extends BlockEntityRenderer { - + public PedestalItemRenderer(BlockEntityRenderDispatcher dispatcher) { super(dispatcher); } @Override - public void render(T blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, - int light, int overlay) { + public void render(T blockEntity, float tickDelta, PoseStack matrices, + MultiBufferSource vertexConsumers, int light, int overlay) { Level world = blockEntity.getLevel(); - if (world == null || blockEntity.isEmpty()) - return; + if (world == null || blockEntity.isEmpty()) return; - BlockState state = world.getBlockState(blockEntity.getPos()); - if (!(state.getBlock() instanceof PedestalBlock)) - return; + BlockState state = world.getBlockState(blockEntity.getBlockPos()); + if (!(state.getBlock() instanceof PedestalBlock)) return; + + ItemStack activeItem = blockEntity.getItem(0); - ItemStack activeItem = blockEntity.getStack(0); - - matrices.push(); + matrices.pushPose(); Minecraft minecraft = Minecraft.getInstance(); - BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, world, null); - Vector3f translate = model.getTransformation().ground.translation; + BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null); + Vector3f translate = model.getTransforms().ground.translation; PedestalBlock pedestal = (PedestalBlock) state.getBlock(); - matrices.translate(translate.getX(), translate.getY(), translate.getZ()); + matrices.translate(translate.x(), translate.y(), translate.z()); matrices.translate(0.5, pedestal.getHeight(state), 0.5); if (activeItem.getItem() instanceof BlockItem) { matrices.scale(1.5F, 1.5F, 1.5F); @@ -61,10 +59,9 @@ public class PedestalItemRenderer extends BlockEn int age = blockEntity.getAge(); if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) { float[] colors = EternalCrystalRenderer.colors(age); - int y = blockEntity.getPos().getY(); - - BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, - 0.16F); + int y = blockEntity.getBlockPos().getY(); + + BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, 0.16F); float altitude = Mth.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F; matrices.translate(0.0D, altitude, 0.0D); } @@ -74,10 +71,9 @@ public class PedestalItemRenderer extends BlockEn EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light); } else { float rotation = (age + tickDelta) / 25.0F + 6.0F; - matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation)); - minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices, - vertexConsumers, light, overlay, model); + matrices.mulPose(Vector3f.YP.rotation(rotation)); + minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model); } - matrices.pop(); + matrices.popPose(); } } diff --git a/src/main/java/ru/betterend/client/BetterEndClient.java b/src/main/java/ru/betterend/client/BetterEndClient.java index bdf5c88c..b9ba6104 100644 --- a/src/main/java/ru/betterend/client/BetterEndClient.java +++ b/src/main/java/ru/betterend/client/BetterEndClient.java @@ -2,7 +2,7 @@ package ru.betterend.client; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; -import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.client.render.ERenderLayer; @@ -24,15 +24,15 @@ public class BetterEndClient implements ClientModInitializer { EndEntitiesRenders.register(); EndModelProviders.register(); ClientOptions.init(); - + if (BetterEnd.isDevEnvironment()) { TranslationHelper.printMissingNames(); } } private void registerRenderLayers() { - RenderLayer cutout = RenderLayer.getCutout(); - RenderLayer translucent = RenderLayer.getTranslucent(); + RenderType cutout = RenderType.cutout(); + RenderType translucent = RenderType.translucent(); Registry.BLOCK.forEach(block -> { if (block instanceof IRenderTypeable) { ERenderLayer layer = ((IRenderTypeable) block).getRenderLayer(); diff --git a/src/main/java/ru/betterend/client/gui/BlockSignEditScreen.java b/src/main/java/ru/betterend/client/gui/BlockSignEditScreen.java index 8351c782..797438f7 100644 --- a/src/main/java/ru/betterend/client/gui/BlockSignEditScreen.java +++ b/src/main/java/ru/betterend/client/gui/BlockSignEditScreen.java @@ -3,32 +3,31 @@ package ru.betterend.client.gui; import java.util.Arrays; import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.Lighting; import com.mojang.blaze3d.systems.RenderSystem; - +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.BufferUploader; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix4f; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.Util; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.font.TextFieldHelper; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ScreenTexts; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.DiffuseLighting; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.render.block.entity.SignBlockEntityRenderer.SignModel; -import net.minecraft.client.util.SelectionManager; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket; -import net.minecraft.text.LiteralText; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Util; -import net.minecraft.util.math.Matrix4f; import ru.betterend.blocks.basis.EndSignBlock; import ru.betterend.blocks.entities.ESignBlockEntity; import ru.betterend.blocks.entities.render.EndSignBlockEntityRenderer; @@ -39,39 +38,39 @@ public class BlockSignEditScreen extends Screen { private final ESignBlockEntity sign; private int ticksSinceOpened; private int currentRow; - private SelectionManager selectionManager; + private TextFieldHelper selectionManager; private final String[] text = (String[]) Util.make(new String[4], (strings) -> { Arrays.fill(strings, ""); }); public BlockSignEditScreen(ESignBlockEntity sign) { - super(new TranslatableText("sign.edit")); + super(new TranslatableComponent("sign.edit")); this.sign = sign; } protected void init() { - this.client.keyboard.setRepeatEvents(true); - this.addButton(new ButtonWidget(this.width / 2 - 100, this.height / 4 + 120, 200, 20, ScreenTexts.DONE, + this.minecraft.keyboardHandler.setSendRepeatsToGui(true); + this.addButton(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, (buttonWidget) -> { this.finishEditing(); })); this.sign.setEditable(false); - this.selectionManager = new SelectionManager(() -> { + this.selectionManager = new TextFieldHelper(() -> { return this.text[this.currentRow]; }, (string) -> { this.text[this.currentRow] = string; - this.sign.setTextOnRow(this.currentRow, new LiteralText(string)); - }, SelectionManager.makeClipboardGetter(this.client), SelectionManager.makeClipboardSetter(this.client), + this.sign.setMessage(this.currentRow, new TextComponent(string)); + }, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), (string) -> { - return this.client.textRenderer.getWidth(string) <= 90; + return this.minecraft.font.width(string) <= 90; }); } public void removed() { - this.client.keyboard.setRepeatEvents(false); - ClientPlayNetworkHandler clientPlayNetworkHandler = this.client.getNetworkHandler(); + this.minecraft.keyboardHandler.setSendRepeatsToGui(false); + ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection(); if (clientPlayNetworkHandler != null) { - clientPlayNetworkHandler.sendPacket(new UpdateSignC2SPacket(this.sign.getPos(), this.text[0], this.text[1], + clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], this.text[2], this.text[3])); } @@ -80,18 +79,18 @@ public class BlockSignEditScreen extends Screen { public void tick() { ++this.ticksSinceOpened; - if (!this.sign.getType().supports(this.sign.getCachedState().getBlock())) { + if (!this.sign.getType().isValid(this.sign.getBlockState().getBlock())) { this.finishEditing(); } } private void finishEditing() { - this.sign.markDirty(); - this.client.openScreen((Screen) null); + this.sign.setChanged(); + this.minecraft.setScreen((Screen) null); } public boolean charTyped(char chr, int keyCode) { - this.selectionManager.insert(chr); + this.selectionManager.charTyped(chr); return true; } @@ -102,29 +101,29 @@ public class BlockSignEditScreen extends Screen { public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == 265) { this.currentRow = this.currentRow - 1 & 3; - this.selectionManager.moveCaretToEnd(); + this.selectionManager.setCursorToEnd(); return true; } else if (keyCode != 264 && keyCode != 257 && keyCode != 335) { - return this.selectionManager.handleSpecialKey(keyCode) ? true + return this.selectionManager.keyPressed(keyCode) ? true : super.keyPressed(keyCode, scanCode, modifiers); } else { this.currentRow = this.currentRow + 1 & 3; - this.selectionManager.moveCaretToEnd(); + this.selectionManager.setCursorToEnd(); return true; } } - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - DiffuseLighting.disableGuiDepthLighting(); + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + Lighting.setupForFlatItems(); this.renderBackground(matrices); - DrawableHelper.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 40, 16777215); - matrices.push(); + GuiComponent.drawCenteredString(matrices, this.font, this.title, this.width / 2, 40, 16777215); + matrices.pushPose(); matrices.translate((double) (this.width / 2), 0.0D, 50.0D); matrices.scale(93.75F, -93.75F, 93.75F); matrices.translate(0.0D, -1.3125D, 0.0D); - BlockState blockState = this.sign.getCachedState(); - boolean bl = blockState.get(EndSignBlock.FLOOR); + BlockState blockState = this.sign.getBlockState(); + boolean bl = blockState.getValue(EndSignBlock.FLOOR); if (!bl) { matrices.translate(0.0D, -0.3125D, 0.0D); @@ -132,25 +131,25 @@ public class BlockSignEditScreen extends Screen { boolean bl2 = this.ticksSinceOpened / 6 % 2 == 0; - matrices.push(); + matrices.pushPose(); matrices.scale(0.6666667F, -0.6666667F, -0.6666667F); - VertexConsumerProvider.Immediate immediate = this.client.getBufferBuilders().getEntityVertexConsumers(); + MultiBufferSource.BufferSource immediate = this.minecraft.renderBuffers().bufferSource(); VertexConsumer vertexConsumer = EndSignBlockEntityRenderer.getConsumer(immediate, blockState.getBlock()); - this.model.field.render(matrices, vertexConsumer, 15728880, OverlayTexture.DEFAULT_UV); + this.model.sign.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY); if (bl) { - this.model.foot.render(matrices, vertexConsumer, 15728880, OverlayTexture.DEFAULT_UV); + this.model.stick.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY); } - matrices.pop(); + matrices.popPose(); matrices.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D); matrices.scale(0.010416667F, -0.010416667F, 0.010416667F); - int i = this.sign.getTextColor().getSignColor(); - int j = this.selectionManager.getSelectionStart(); - int k = this.selectionManager.getSelectionEnd(); + int i = this.sign.getColor().getTextColor(); + int j = this.selectionManager.getCursorPos(); + int k = this.selectionManager.getSelectionPos(); int l = this.currentRow * 10 - this.text.length * 5; - Matrix4f matrix4f = matrices.peek().getModel(); + Matrix4f matrix4f = matrices.last().pose(); int m; String string2; @@ -159,73 +158,73 @@ public class BlockSignEditScreen extends Screen { for (m = 0; m < this.text.length; ++m) { string2 = this.text[m]; if (string2 != null) { - if (this.textRenderer.isRightToLeft()) { - string2 = this.textRenderer.mirror(string2); + if (this.font.isBidirectional()) { + string2 = this.font.bidirectionalShaping(string2); } - float n = (float) (-this.client.textRenderer.getWidth(string2) / 2); - this.client.textRenderer.draw(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, + float n = (float) (-this.minecraft.font.width(string2) / 2); + this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, immediate, false, 0, 15728880, false); if (m == this.currentRow && j >= 0 && bl2) { - s = this.client.textRenderer - .getWidth(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); - t = s - this.client.textRenderer.getWidth(string2) / 2; + s = this.minecraft.font + .width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); + t = s - this.minecraft.font.width(string2) / 2; if (j >= string2.length()) { - this.client.textRenderer.draw("_", (float) t, (float) l, i, false, matrix4f, immediate, false, + this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, 0, 15728880, false); } } } } - immediate.draw(); + immediate.endBatch(); for (m = 0; m < this.text.length; ++m) { string2 = this.text[m]; if (string2 != null && m == this.currentRow && j >= 0) { - int r = this.client.textRenderer - .getWidth(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); - s = r - this.client.textRenderer.getWidth(string2) / 2; + int r = this.minecraft.font + .width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); + s = r - this.minecraft.font.width(string2) / 2; if (bl2 && j < string2.length()) { int var31 = l - 1; int var10003 = s + 1; - this.client.textRenderer.getClass(); + this.minecraft.font.getClass(); fill(matrices, s, var31, var10003, l + 9, -16777216 | i); } if (k != j) { t = Math.min(j, k); int u = Math.max(j, k); - int v = this.client.textRenderer.getWidth(string2.substring(0, t)) - - this.client.textRenderer.getWidth(string2) / 2; - int w = this.client.textRenderer.getWidth(string2.substring(0, u)) - - this.client.textRenderer.getWidth(string2) / 2; + int v = this.minecraft.font.width(string2.substring(0, t)) + - this.minecraft.font.width(string2) / 2; + int w = this.minecraft.font.width(string2.substring(0, u)) + - this.minecraft.font.width(string2) / 2; int x = Math.min(v, w); int y = Math.max(v, w); - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferBuilder = tessellator.getBuffer(); + Tesselator tessellator = Tesselator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuilder(); RenderSystem.disableTexture(); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - bufferBuilder.begin(7, VertexFormats.POSITION_COLOR); + bufferBuilder.begin(7, DefaultVertexFormat.POSITION_COLOR); float var32 = (float) x; - this.client.textRenderer.getClass(); - bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).next(); + this.minecraft.font.getClass(); + bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).endVertex(); var32 = (float) y; - this.client.textRenderer.getClass(); - bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).next(); - bufferBuilder.vertex(matrix4f, (float) y, (float) l, 0.0F).color(0, 0, 255, 255).next(); - bufferBuilder.vertex(matrix4f, (float) x, (float) l, 0.0F).color(0, 0, 255, 255).next(); + this.minecraft.font.getClass(); + bufferBuilder.vertex(matrix4f, var32, (float) (l + 9), 0.0F).color(0, 0, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, (float) y, (float) l, 0.0F).color(0, 0, 255, 255).endVertex(); + bufferBuilder.vertex(matrix4f, (float) x, (float) l, 0.0F).color(0, 0, 255, 255).endVertex(); bufferBuilder.end(); - BufferRenderer.draw(bufferBuilder); + BufferUploader.end(bufferBuilder); RenderSystem.disableColorLogicOp(); RenderSystem.enableTexture(); } } } - matrices.pop(); - DiffuseLighting.enableGuiDepthLighting(); + matrices.popPose(); + Lighting.setupFor3DItems(); super.render(matrices, mouseX, mouseY, delta); } } diff --git a/src/main/java/ru/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java b/src/main/java/ru/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java index 5786893f..30cc0260 100644 --- a/src/main/java/ru/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java +++ b/src/main/java/ru/betterend/client/gui/EndStoneSmelterRecipeBookScreen.java @@ -5,72 +5,71 @@ import java.util.List; import java.util.Set; import com.mojang.blaze3d.systems.RenderSystem; - +import com.mojang.blaze3d.vertex.PoseStack; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.recipebook.BlastFurnaceRecipeBookScreen; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.recipebook.BlastingRecipeBookComponent; +import net.minecraft.core.NonNullList; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.screen.slot.Slot; -import net.minecraft.util.collection.DefaultedList; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; @Environment(EnvType.CLIENT) -public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScreen { +public class EndStoneSmelterRecipeBookScreen extends BlastingRecipeBookComponent { private Iterator fuelIterator; private Set fuels; private Slot fuelSlot; private Item currentItem; private float frameTime; - + @Override - protected Set getAllowedFuels() { + protected Set getFuelItems() { return EndStoneSmelterBlockEntity.availableFuels().keySet(); } - + @Override public void slotClicked(Slot slot) { super.slotClicked(slot); - if (slot != null && slot.id < this.craftingScreenHandler.getCraftingSlotCount()) { + if (slot != null && slot.index < this.menu.getSize()) { this.fuelSlot = null; } } - + @Override - public void showGhostRecipe(Recipe recipe, List slots) { - this.ghostSlots.reset(); - ItemStack result = recipe.getOutput(); - this.ghostSlots.setRecipe(recipe); - this.ghostSlots.addSlot(Ingredient.ofStacks(result), (slots.get(3)).x, (slots.get(3)).y); - DefaultedList inputs = recipe.getPreviewInputs(); + public void setupGhostRecipe(Recipe recipe, List slots) { + this.ghostRecipe.clear(); + ItemStack result = recipe.getResultItem(); + this.ghostRecipe.setRecipe(recipe); + this.ghostRecipe.addIngredient(Ingredient.of(result), (slots.get(3)).x, (slots.get(3)).y); + NonNullList inputs = recipe.getIngredients(); Iterator iterator = inputs.iterator(); - for (int i = 0; i < 2; i++) { + for(int i = 0; i < 2; i++) { if (!iterator.hasNext()) { return; } Ingredient ingredient = iterator.next(); if (!ingredient.isEmpty()) { Slot slot = slots.get(i); - this.ghostSlots.addSlot(ingredient, slot.x, slot.y); + this.ghostRecipe.addIngredient(ingredient, slot.x, slot.y); } } this.fuelSlot = slots.get(2); if (this.fuels == null) { - this.fuels = this.getAllowedFuels(); + this.fuels = this.getFuelItems(); } this.fuelIterator = this.fuels.iterator(); this.currentItem = null; } - + @Override - public void drawGhostSlots(MatrixStack matrices, int x, int y, boolean bl, float f) { - this.ghostSlots.draw(matrices, client, x, y, bl, f); + public void renderGhostRecipe(PoseStack matrices, int x, int y, boolean bl, float f) { + this.ghostRecipe.render(matrices, minecraft, x, y, bl, f); if (fuelSlot != null) { if (!Screen.hasControlDown()) { this.frameTime += f; @@ -78,21 +77,20 @@ public class EndStoneSmelterRecipeBookScreen extends BlastFurnaceRecipeBookScree int slotX = this.fuelSlot.x + x; int slotY = this.fuelSlot.y + y; - DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822018048); - this.client.getItemRenderer().renderInGuiWithOverrides(client.player, this.getItem().getDefaultStack(), - slotX, slotY); + GuiComponent.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822018048); + this.minecraft.getItemRenderer().renderAndDecorateItem(minecraft.player, this.getFuel().getDefaultInstance(), slotX, slotY); RenderSystem.depthFunc(516); - DrawableHelper.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822083583); + GuiComponent.fill(matrices, slotX, slotY, slotX + 16, slotY + 16, 822083583); RenderSystem.depthFunc(515); } } - private Item getItem() { + private Item getFuel() { if (this.currentItem == null || this.frameTime > 30.0F) { this.frameTime = 0.0F; if (this.fuelIterator == null || !this.fuelIterator.hasNext()) { if (this.fuels == null) { - this.fuels = this.getAllowedFuels(); + this.fuels = this.getFuelItems(); } this.fuelIterator = this.fuels.iterator(); } diff --git a/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreen.java b/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreen.java index 8831c3ef..6aba3065 100644 --- a/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreen.java +++ b/src/main/java/ru/betterend/client/gui/EndStoneSmelterScreen.java @@ -1,72 +1,69 @@ package ru.betterend.client.gui; import com.mojang.blaze3d.systems.RenderSystem; - +import com.mojang.blaze3d.vertex.PoseStack; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; -import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; -import net.minecraft.client.gui.widget.TexturedButtonWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.world.entity.player.PlayerInventory; -import net.minecraft.screen.slot.Slot; -import net.minecraft.screen.slot.SlotActionType; -import net.minecraft.text.StringVisitable; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; +import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.FormattedText; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.Slot; import ru.betterend.BetterEnd; @Environment(EnvType.CLIENT) -public class EndStoneSmelterScreen extends HandledScreen implements RecipeBookProvider { +public class EndStoneSmelterScreen extends AbstractContainerScreen implements RecipeUpdateListener { - private final static ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation( - "textures/gui/recipe_button.png"); + private final static ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation("textures/gui/recipe_button.png"); private final static ResourceLocation BACKGROUND_TEXTURE = BetterEnd.makeID("textures/gui/smelter_gui.png"); - + public final EndStoneSmelterRecipeBookScreen recipeBook; private boolean narrow; - - public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, PlayerInventory inventory, Text title) { + + public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, Inventory inventory, Component title) { super(handler, inventory, title); this.recipeBook = new EndStoneSmelterRecipeBookScreen(); } - + public void init() { super.init(); this.narrow = this.width < 379; - this.recipeBook.initialize(width, height, client, narrow, handler); - this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth); - this.addButton(new TexturedButtonWidget(x + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE, - (buttonWidget) -> { - this.recipeBook.reset(narrow); - this.recipeBook.toggleOpen(); - this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth); - ((TexturedButtonWidget) buttonWidget).setPos(this.x + 20, height / 2 - 49); - })); - this.titleX = (this.backgroundWidth - this.textRenderer.getWidth((StringVisitable) this.title)) / 2; + this.recipeBook.init(width, height, minecraft, narrow, menu); + this.leftPos = this.recipeBook.updateScreenPosition(narrow, width, imageWidth); + this.addButton(new ImageButton(leftPos + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE, (buttonWidget) -> { + this.recipeBook.initVisuals(narrow); + this.recipeBook.toggleVisibility(); + this.leftPos = this.recipeBook.updateScreenPosition(narrow, width, imageWidth); + ((ImageButton) buttonWidget).setPosition(this.leftPos + 20, height / 2 - 49); + })); + this.titleLabelX = (this.imageWidth - this.font.width((FormattedText)this.title)) / 2; } @Override public void tick() { super.tick(); - this.recipeBook.update(); + this.recipeBook.tick(); } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { this.renderBackground(matrices); - if (this.recipeBook.isOpen() && this.narrow) { - this.drawBackground(matrices, delta, mouseX, mouseY); + if (this.recipeBook.isVisible() && this.narrow) { + this.renderBg(matrices, delta, mouseX, mouseY); this.recipeBook.render(matrices, mouseX, mouseY, delta); } else { this.recipeBook.render(matrices, mouseX, mouseY, delta); super.render(matrices, mouseX, mouseY, delta); - this.recipeBook.drawGhostSlots(matrices, x, y, true, delta); + this.recipeBook.renderGhostRecipe(matrices, leftPos, topPos, true, delta); } - this.drawMouseoverTooltip(matrices, mouseX, mouseY); - this.recipeBook.drawTooltip(matrices, x, y, mouseX, mouseY); + this.renderTooltip(matrices, mouseX, mouseY); + this.recipeBook.renderTooltip(matrices, leftPos, topPos, mouseX, mouseY); } @Override @@ -74,28 +71,25 @@ public class EndStoneSmelterScreen extends HandledScreen= (left + backgroundWidth) - || mouseY >= (top + backgroundHeight); - return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, x, y, backgroundWidth, backgroundHeight, button) - && isMouseOut; + protected boolean hasClickedOutside(double mouseX, double mouseY, int left, int top, int button) { + boolean isMouseOut = mouseX < left || mouseY < top || mouseX >= (left + imageWidth) || mouseY >= (top + imageHeight); + return this.recipeBook.hasClickedOutside(mouseX, mouseY, leftPos, topPos, imageWidth, imageHeight, button) && isMouseOut; } @Override @@ -104,32 +98,32 @@ public class EndStoneSmelterScreen extends HandledScreen { +public class EndStoneSmelterScreenHandler extends RecipeBookMenu { - public final static ScreenHandlerType HANDLER_TYPE = ScreenHandlerRegistry - .registerSimple(BetterEnd.makeID(EndStoneSmelter.ID), EndStoneSmelterScreenHandler::new); - - private final Inventory inventory; - private final PropertyDelegate propertyDelegate; + public final static MenuType HANDLER_TYPE = ScreenHandlerRegistry.registerSimple( + BetterEnd.makeID(EndStoneSmelter.ID), EndStoneSmelterScreenHandler::new); + + private final Container inventory; + private final ContainerData propertyDelegate; protected final Level world; - - public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory) { - this(syncId, playerInventory, new SimpleInventory(4), new ArrayPropertyDelegate(4)); + + public EndStoneSmelterScreenHandler(int syncId, Inventory playerInventory) { + this(syncId, playerInventory, new SimpleContainer(4), new SimpleContainerData(4)); } - - public EndStoneSmelterScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, - PropertyDelegate propertyDelegate) { + + public EndStoneSmelterScreenHandler(int syncId, Inventory playerInventory, Container inventory, ContainerData propertyDelegate) { super(HANDLER_TYPE, syncId); this.inventory = inventory; this.propertyDelegate = propertyDelegate; - this.world = playerInventory.player.world; - - this.addProperties(propertyDelegate); + this.world = playerInventory.player.level; + + this.addDataSlots(propertyDelegate); this.addSlot(new Slot(inventory, 0, 45, 17)); this.addSlot(new Slot(inventory, 1, 67, 17)); this.addSlot(new SmelterFuelSlot(this, inventory, 2, 56, 53)); this.addSlot(new SmelterOutputSlot(playerInventory.player, inventory, 3, 129, 35)); - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { + for(int i = 0; i < 3; ++i) { + for(int j = 0; j < 9; ++j) { this.addSlot(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } - for (int i = 0; i < 9; ++i) { + for(int i = 0; i < 9; ++i) { this.addSlot(new Slot(playerInventory, i, 8 + i * 18, 142)); } } - + @Override - public ScreenHandlerType getType() { + public MenuType getType() { return HANDLER_TYPE; } @Override - public void populateRecipeFinder(RecipeFinder finder) { - if (inventory instanceof RecipeInputProvider) { - ((RecipeInputProvider) inventory).provideRecipeInputs(finder); + public void fillCraftSlotsStackedContents(StackedContents finder) { + if (inventory instanceof StackedContentsCompatible) { + ((StackedContentsCompatible) inventory).fillStackedContents(finder); } } @Override - public void clearCraftingSlots() { - this.inventory.clear(); + public void clearCraftingContent() { + this.inventory.clearContent(); } @Override - public boolean matches(Recipe recipe) { + public boolean recipeMatches(Recipe recipe) { return recipe.matches(this.inventory, this.world); } @Override - public int getCraftingResultSlotIndex() { + public int getResultSlotIndex() { return 3; } @Override - public int getCraftingWidth() { + public int getGridWidth() { return 2; } @Override - public int getCraftingHeight() { + public int getGridHeight() { return 1; } @Override - public int getCraftingSlotCount() { + public int getSize() { return 4; } @Override - public RecipeBookCategory getCategory() { - return RecipeBookCategory.BLAST_FURNACE; + public RecipeBookType getRecipeBookType() { + return RecipeBookType.BLAST_FURNACE; } @Override - public boolean canUse(Player player) { - return this.inventory.canPlayerUse(player); + public boolean stillValid(Player player) { + return this.inventory.stillValid(player); } protected boolean isSmeltable(ItemStack itemStack) { - return this.world.getRecipeManager() - .getFirstMatch(AlloyingRecipe.TYPE, new SimpleInventory(itemStack), this.world).isPresent(); + return this.world.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, new SimpleContainer(itemStack), this.world).isPresent(); } public boolean isFuel(ItemStack itemStack) { return EndStoneSmelterBlockEntity.canUseAsFuel(itemStack); } - + @Override - public ItemStack transferSlot(Player player, int index) { + public ItemStack quickMoveStack(Player player, int index) { ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.slots.get(index); - if (slot != null && slot.hasStack()) { - ItemStack itemStack2 = slot.getStack(); + if (slot != null && slot.hasItem()) { + ItemStack itemStack2 = slot.getItem(); itemStack = itemStack2.copy(); if (index == 3) { - if (insertItem(itemStack2, 4, 40, true)) { + if (moveItemStackTo(itemStack2, 4, 40, true)) { return ItemStack.EMPTY; } - slot.onStackChanged(itemStack2, itemStack); + slot.onQuickCraft(itemStack2, itemStack); } else if (index != 2 && index != 1 && index != 0) { if (isSmeltable(itemStack2)) { - if (!insertItem(itemStack2, 0, 2, false)) { + if (!moveItemStackTo(itemStack2, 0, 2, false)) { return ItemStack.EMPTY; } } else if (isFuel(itemStack2)) { - if (!this.insertItem(itemStack2, 2, 3, false)) { + if (!this.moveItemStackTo(itemStack2, 2, 3, false)) { return ItemStack.EMPTY; } } else if (index < 31) { - if (!insertItem(itemStack2, 31, 40, false)) { + if (!moveItemStackTo(itemStack2, 31, 40, false)) { return ItemStack.EMPTY; } - } else if (index < 40 && !insertItem(itemStack2, 4, 31, false)) { + } else if (index < 40 && !moveItemStackTo(itemStack2, 4, 31, false)) { return ItemStack.EMPTY; } - } else if (!insertItem(itemStack2, 4, 40, false)) { + } else if (!moveItemStackTo(itemStack2, 4, 40, false)) { return ItemStack.EMPTY; } if (itemStack2.isEmpty()) { - slot.setStack(ItemStack.EMPTY); + slot.set(ItemStack.EMPTY); } else { - slot.markDirty(); + slot.setChanged(); } if (itemStack2.getCount() == itemStack.getCount()) { return ItemStack.EMPTY; } - slot.onTakeItem(player, itemStack2); + slot.onTake(player, itemStack2); } return itemStack; } - + @Environment(EnvType.CLIENT) public int getSmeltProgress() { int time = this.propertyDelegate.get(2); diff --git a/src/main/java/ru/betterend/client/gui/slot/SmelterFuelSlot.java b/src/main/java/ru/betterend/client/gui/slot/SmelterFuelSlot.java index 9ee6b8ba..06ec70a5 100644 --- a/src/main/java/ru/betterend/client/gui/slot/SmelterFuelSlot.java +++ b/src/main/java/ru/betterend/client/gui/slot/SmelterFuelSlot.java @@ -1,25 +1,25 @@ package ru.betterend.client.gui.slot; -import net.minecraft.inventory.Inventory; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.FurnaceFuelSlot; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraft.screen.slot.FurnaceFuelSlot; -import net.minecraft.screen.slot.Slot; import ru.betterend.client.gui.EndStoneSmelterScreenHandler; public class SmelterFuelSlot extends Slot { private final EndStoneSmelterScreenHandler handler; - - public SmelterFuelSlot(EndStoneSmelterScreenHandler handler, Inventory inventory, int index, int x, int y) { + + public SmelterFuelSlot(EndStoneSmelterScreenHandler handler, Container inventory, int index, int x, int y) { super(inventory, index, x, y); this.handler = handler; } - - public boolean canInsert(ItemStack stack) { + + public boolean mayPlace(ItemStack stack) { return this.handler.isFuel(stack) || FurnaceFuelSlot.isBucket(stack); } - public int getMaxItemCount(ItemStack stack) { - return FurnaceFuelSlot.isBucket(stack) ? 1 : super.getMaxItemCount(stack); + public int getMaxStackSize(ItemStack stack) { + return FurnaceFuelSlot.isBucket(stack) ? 1 : super.getMaxStackSize(stack); } } diff --git a/src/main/java/ru/betterend/client/gui/slot/SmelterOutputSlot.java b/src/main/java/ru/betterend/client/gui/slot/SmelterOutputSlot.java index 1eec6448..212eb179 100644 --- a/src/main/java/ru/betterend/client/gui/slot/SmelterOutputSlot.java +++ b/src/main/java/ru/betterend/client/gui/slot/SmelterOutputSlot.java @@ -1,9 +1,9 @@ package ru.betterend.client.gui.slot; +import net.minecraft.world.Container; import net.minecraft.world.entity.player.Player; -import net.minecraft.inventory.Inventory; +import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraft.screen.slot.Slot; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; public class SmelterOutputSlot extends Slot { @@ -11,38 +11,38 @@ public class SmelterOutputSlot extends Slot { private Player player; private int amount; - public SmelterOutputSlot(Player player, Inventory inventory, int index, int x, int y) { + public SmelterOutputSlot(Player player, Container inventory, int index, int x, int y) { super(inventory, index, x, y); this.player = player; } - public boolean canInsert(ItemStack stack) { + public boolean mayPlace(ItemStack stack) { return false; } - public ItemStack takeStack(int amount) { - if (this.hasStack()) { - this.amount += Math.min(amount, this.getStack().getCount()); + public ItemStack remove(int amount) { + if (this.hasItem()) { + this.amount += Math.min(amount, this.getItem().getCount()); } - return super.takeStack(amount); + return super.remove(amount); } - public ItemStack onTakeItem(Player player, ItemStack stack) { - this.onCrafted(stack); - super.onTakeItem(player, stack); + public ItemStack onTake(Player player, ItemStack stack) { + this.checkTakeAchievements(stack); + super.onTake(player, stack); return stack; } - protected void onCrafted(ItemStack stack, int amount) { + protected void onQuickCraft(ItemStack stack, int amount) { this.amount += amount; - this.onCrafted(stack); + this.checkTakeAchievements(stack); } - protected void onCrafted(ItemStack stack) { - stack.onCraft(this.player.world, this.player, this.amount); - if (!this.player.world.isClientSide && this.inventory instanceof EndStoneSmelterBlockEntity) { - ((EndStoneSmelterBlockEntity) this.inventory).dropExperience(player); + protected void checkTakeAchievements(ItemStack stack) { + stack.onCraftedBy(this.player.level, this.player, this.amount); + if (!this.player.level.isClientSide && this.container instanceof EndStoneSmelterBlockEntity) { + ((EndStoneSmelterBlockEntity) this.container).dropExperience(player); } this.amount = 0; } diff --git a/src/main/java/ru/betterend/client/render/BeamRenderer.java b/src/main/java/ru/betterend/client/render/BeamRenderer.java index ada57911..fe8f8e3a 100644 --- a/src/main/java/ru/betterend/client/render/BeamRenderer.java +++ b/src/main/java/ru/betterend/client/render/BeamRenderer.java @@ -1,75 +1,62 @@ package ru.betterend.client.render; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; +import com.mojang.math.Matrix4f; import com.mojang.math.Vector3f; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.util.math.Matrix3f; -import net.minecraft.util.math.Matrix4f; public class BeamRenderer { private static final ResourceLocation BEAM_TEXTURE = new ResourceLocation("textures/entity/end_gateway_beam.png"); - - public static void renderLightBeam(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int age, - float tick, int minY, int maxY, float[] colors, float alpha, float beamIn, float beamOut) { + + public static void renderLightBeam(PoseStack matrices, MultiBufferSource vertexConsumers, int age, float tick, int minY, int maxY, float[] colors, float alpha, float beamIn, float beamOut) { float red = colors[0]; float green = colors[1]; float blue = colors[2]; - + int maxBY = minY + maxY; float delta = maxY < 0 ? tick : -tick; - float fractDelta = Mth.fractionalPart(delta * 0.2F - (float) Mth.floor(delta * 0.1F)); + float fractDelta = Mth.frac(delta * 0.2F - (float) Mth.floor(delta * 0.1F)); float xIn = -beamIn; float minV = Mth.clamp(fractDelta - 1.0F, 0.0F, 1.0F); float maxV = (float) maxY * (0.5F / beamIn) + minV; float rotation = (age + tick) / 25.0F + 6.0F; - - VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getBeaconBeam(BEAM_TEXTURE, true)); - - matrices.push(); - matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(-rotation)); - renderBeam(matrices, vertexConsumer, red, green, blue, alpha, minY, maxBY, beamIn, 0.0F, 0.0F, beamIn, 0.0F, - xIn, xIn, 0.0F, 0.0F, 1.0F, minV, maxV); - + + VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderType.beaconBeam(BEAM_TEXTURE, true)); + + matrices.pushPose(); + matrices.mulPose(Vector3f.YP.rotation(-rotation)); + renderBeam(matrices, vertexConsumer, red, green, blue, alpha, minY, maxBY, beamIn, 0.0F, 0.0F, beamIn, 0.0F, xIn, xIn, 0.0F, 0.0F, 1.0F, minV, maxV); + float xOut = -beamOut; maxV = (float) maxY + minV; - renderBeam(matrices, vertexConsumer, red, green, blue, alpha, minY, maxBY, xOut, xOut, beamOut, xOut, xOut, - beamOut, beamOut, beamOut, 0.0F, 1.0F, minV, maxV); - matrices.pop(); + renderBeam(matrices, vertexConsumer, red, green, blue, alpha, minY, maxBY, xOut, xOut, beamOut, xOut, xOut, beamOut, beamOut, beamOut, 0.0F, 1.0F, minV, maxV); + matrices.popPose(); } - private static void renderBeam(MatrixStack matrices, VertexConsumer vertexConsumer, float red, float green, - float blue, float alpha, int minY, int maxY, float x1, float d1, float x2, float d2, float x3, float d3, - float x4, float d4, float minU, float maxU, float minV, float maxV) { - MatrixStack.Entry entry = matrices.peek(); - Matrix4f matrix4f = entry.getModel(); - Matrix3f matrix3f = entry.getNormal(); - renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x1, d1, x2, d2, minU, maxU, - minV, maxV); - renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x4, d4, x3, d3, minU, maxU, - minV, maxV); - renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x2, d2, x4, d4, minU, maxU, - minV, maxV); - renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x3, d3, x1, d1, minU, maxU, - minV, maxV); + private static void renderBeam(PoseStack matrices, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int minY, int maxY, float x1, float d1, float x2, float d2, float x3, float d3, float x4, float d4, float minU, float maxU, float minV, float maxV) { + PoseStack.Pose entry = matrices.last(); + Matrix4f matrix4f = entry.pose(); + Matrix3f matrix3f = entry.normal(); + renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x1, d1, x2, d2, minU, maxU, minV, maxV); + renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x4, d4, x3, d3, minU, maxU, minV, maxV); + renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x2, d2, x4, d4, minU, maxU, minV, maxV); + renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxY, minY, x3, d3, x1, d1, minU, maxU, minV, maxV); } - private static void renderBeam(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, - float green, float blue, float alpha, int minY, int maxY, float minX, float minD, float maxX, float maxD, - float minU, float maxU, float minV, float maxV) { + private static void renderBeam(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int minY, int maxY, float minX, float minD, float maxX, float maxD, float minU, float maxU, float minV, float maxV) { addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxX, minY, maxD, maxU, minV); addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxX, maxY, maxD, maxU, maxV); addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, minX, maxY, minD, minU, maxV); addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, minX, minY, minD, minU, minV); } - private static void addVertex(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, - float green, float blue, float alpha, float x, float y, float d, float u, float v) { - vertexConsumer.vertex(matrix4f, x, y, d).color(red, green, blue, alpha).texture(u, v) - .overlay(OverlayTexture.DEFAULT_UV).light(15728880).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + private static void addVertex(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, float x, float y, float d, float u, float v) { + vertexConsumer.vertex(matrix4f, x, y, d).color(red, green, blue, alpha).uv(u, v).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(15728880).normal(matrix3f, 0.0F, 1.0F, 0.0F).endVertex(); } } diff --git a/src/main/java/ru/betterend/client/render/EndCrystalRenderer.java b/src/main/java/ru/betterend/client/render/EndCrystalRenderer.java index 1a4bf81b..9c559914 100644 --- a/src/main/java/ru/betterend/client/render/EndCrystalRenderer.java +++ b/src/main/java/ru/betterend/client/render/EndCrystalRenderer.java @@ -1,104 +1,94 @@ package ru.betterend.client.render; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; +import com.mojang.math.Matrix4f; +import com.mojang.math.Quaternion; import com.mojang.math.Vector3f; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.util.math.Matrix3f; -import net.minecraft.util.math.Matrix4f; -import net.minecraft.util.math.Quaternion; public class EndCrystalRenderer { - private static final ResourceLocation CRYSTAL_TEXTURE = new ResourceLocation( - "textures/entity/end_crystal/end_crystal.png"); - private static final ResourceLocation CRYSTAL_BEAM_TEXTURE = new ResourceLocation( - "textures/entity/end_crystal/end_crystal_beam.png"); - private static final RenderLayer CRYSTAL_BEAM_LAYER; - private static final RenderLayer END_CRYSTAL; + private static final ResourceLocation CRYSTAL_TEXTURE = new ResourceLocation("textures/entity/end_crystal/end_crystal.png"); + private static final ResourceLocation CRYSTAL_BEAM_TEXTURE = new ResourceLocation("textures/entity/end_crystal/end_crystal_beam.png"); + private static final RenderType CRYSTAL_BEAM_LAYER; + private static final RenderType END_CRYSTAL; private static final ModelPart CORE; private static final ModelPart FRAME; private static final int AGE_CYCLE = 240; private static final float SINE_45_DEGREES; - - public static void render(int age, int maxAge, float tickDelta, MatrixStack matrices, - VertexConsumerProvider vertexConsumerProvider, int light) { + + public static void render(int age, int maxAge, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumerProvider, int light) { float k = (float) AGE_CYCLE / maxAge; float rotation = (age * k + tickDelta) * 3.0F; VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(END_CRYSTAL); - matrices.push(); + matrices.pushPose(); matrices.scale(0.8F, 0.8F, 0.8F); matrices.translate(0.0D, -0.5D, 0.0D); - matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation)); + matrices.mulPose(Vector3f.YP.rotationDegrees(rotation)); matrices.translate(0.0D, 0.8F, 0.0D); - matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); - FRAME.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV); + matrices.mulPose(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + FRAME.render(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY); matrices.scale(0.875F, 0.875F, 0.875F); - matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); - matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation)); - FRAME.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV); + matrices.mulPose(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + matrices.mulPose(Vector3f.YP.rotationDegrees(rotation)); + FRAME.render(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY); matrices.scale(0.875F, 0.875F, 0.875F); - matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); - matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation)); - CORE.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV); - matrices.pop(); + matrices.mulPose(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true)); + matrices.mulPose(Vector3f.YP.rotationDegrees(rotation)); + CORE.render(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY); + matrices.popPose(); } - - public static void renderBeam(BlockPos start, BlockPos end, float tickDelta, int age, MatrixStack matrices, - VertexConsumerProvider vertexConsumers, int light) { + + public static void renderBeam(BlockPos start, BlockPos end, float tickDelta, int age, PoseStack matrices, MultiBufferSource vertexConsumers, int light) { float dx = start.getX() - end.getX() + 1.0F; float dy = start.getY() - end.getY() + 1.0F; float dz = start.getZ() - end.getZ() + 1.0F; float f = Mth.sqrt(dx * dx + dz * dz); float g = Mth.sqrt(dx * dx + dy * dy + dz * dz); - matrices.push(); + matrices.pushPose(); matrices.translate(0.0D, 2.0D, 0.0D); - matrices.multiply( - Vector3f.POSITIVE_Y.getRadialQuaternion((float) (-Math.atan2((double) dz, (double) dx)) - 1.5707964F)); - matrices.multiply( - Vector3f.POSITIVE_X.getRadialQuaternion((float) (-Math.atan2((double) f, (double) dy)) - 1.5707964F)); + matrices.mulPose(Vector3f.YP.rotation((float)(-Math.atan2((double) dz, (double) dx)) - 1.5707964F)); + matrices.mulPose(Vector3f.XP.rotation((float)(-Math.atan2((double) f, (double) dy)) - 1.5707964F)); VertexConsumer vertexConsumer = vertexConsumers.getBuffer(CRYSTAL_BEAM_LAYER); float h = 0.0F - ((float) age + tickDelta) * 0.01F; float i = Mth.sqrt(dx * dx + dy * dy + dz * dz) / 32.0F - ((float) age + tickDelta) * 0.01F; float k = 0.0F; float l = 0.75F; float m = 0.0F; - MatrixStack.Entry entry = matrices.peek(); - Matrix4f matrix4f = entry.getModel(); - Matrix3f matrix3f = entry.getNormal(); + PoseStack.Pose entry = matrices.last(); + Matrix4f matrix4f = entry.pose(); + Matrix3f matrix3f = entry.normal(); - for (int n = 1; n <= 8; ++n) { - float o = Mth.sin((float) n * 6.2831855F / 8.0F) * 0.75F; - float p = Mth.cos((float) n * 6.2831855F / 8.0F) * 0.75F; - float q = (float) n / 8.0F; - vertexConsumer.vertex(matrix4f, k * 0.2F, l * 0.2F, 0.0F).color(0, 0, 0, 255).texture(m, h) - .overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); - vertexConsumer.vertex(matrix4f, k, l, g).color(255, 255, 255, 255).texture(m, i) - .overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); - vertexConsumer.vertex(matrix4f, o, p, g).color(255, 255, 255, 255).texture(q, i) - .overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); - vertexConsumer.vertex(matrix4f, o * 0.2F, p * 0.2F, 0.0F).color(0, 0, 0, 255).texture(q, h) - .overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); - k = o; - l = p; - m = q; + for(int n = 1; n <= 8; ++n) { + float o = Mth.sin((float) n * 6.2831855F / 8.0F) * 0.75F; + float p = Mth.cos((float) n * 6.2831855F / 8.0F) * 0.75F; + float q = (float) n / 8.0F; + vertexConsumer.vertex(matrix4f, k * 0.2F, l * 0.2F, 0.0F).color(0, 0, 0, 255).uv(m, h).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).endVertex(); + vertexConsumer.vertex(matrix4f, k, l, g).color(255, 255, 255, 255).uv(m, i).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).endVertex(); + vertexConsumer.vertex(matrix4f, o, p, g).color(255, 255, 255, 255).uv(q, i).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).endVertex(); + vertexConsumer.vertex(matrix4f, o * 0.2F, p * 0.2F, 0.0F).color(0, 0, 0, 255).uv(q, h).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).endVertex(); + k = o; + l = p; + m = q; } - matrices.pop(); + matrices.popPose(); } - + static { - END_CRYSTAL = RenderLayer.getEntityCutoutNoCull(CRYSTAL_TEXTURE); - CRYSTAL_BEAM_LAYER = RenderLayer.getEntitySmoothCutout(CRYSTAL_BEAM_TEXTURE); + END_CRYSTAL = RenderType.entityCutoutNoCull(CRYSTAL_TEXTURE); + CRYSTAL_BEAM_LAYER = RenderType.entitySmoothCutout(CRYSTAL_BEAM_TEXTURE); SINE_45_DEGREES = (float) Math.sin(0.7853981633974483D); FRAME = new ModelPart(64, 32, 0, 0); - FRAME.addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + FRAME.addBox(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); CORE = new ModelPart(64, 32, 32, 0); - CORE.addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); + CORE.addBox(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F); } } diff --git a/src/main/java/ru/betterend/client/render/EternalCrystalRenderer.java b/src/main/java/ru/betterend/client/render/EternalCrystalRenderer.java index 505cf87c..a64ecc94 100644 --- a/src/main/java/ru/betterend/client/render/EternalCrystalRenderer.java +++ b/src/main/java/ru/betterend/client/render/EternalCrystalRenderer.java @@ -1,72 +1,69 @@ package ru.betterend.client.render; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Vector3f; -import net.minecraft.util.Mth; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.Vec3i; +import net.minecraft.util.Mth; import ru.betterend.BetterEnd; import ru.betterend.blocks.AuroraCrystalBlock; import ru.betterend.util.ColorUtil; import ru.betterend.util.MHelper; public class EternalCrystalRenderer { - private static final RenderLayer RENDER_LAYER; + private static final RenderType RENDER_LAYER; private static final ModelPart[] SHARDS; private static final ModelPart CORE; - - public static void render(int age, float tickDelta, MatrixStack matrices, - VertexConsumerProvider vertexConsumerProvider, int light) { + + public static void render(int age, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumerProvider, int light) { VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RENDER_LAYER); float[] colors = colors(age); float rotation = (age + tickDelta) / 25.0F + 6.0F; - matrices.push(); + matrices.pushPose(); matrices.scale(0.6F, 0.6F, 0.6F); - matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation)); - CORE.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, colors[0], colors[1], colors[2], - colors[3]); - + matrices.mulPose(Vector3f.YP.rotation(rotation)); + CORE.render(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, colors[0], colors[1], colors[2], colors[3]); + for (int i = 0; i < 4; i++) { - matrices.push(); + matrices.pushPose(); float offset = Mth.sin(rotation * 2 + i) * 0.15F; matrices.translate(0, offset, 0); - SHARDS[i].render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, colors[0], colors[1], - colors[2], colors[3]); - matrices.pop(); + SHARDS[i].render(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, colors[0], colors[1], colors[2], colors[3]); + matrices.popPose(); } - - matrices.pop(); + + matrices.popPose(); } - + public static float[] colors(int age) { double delta = age * 0.01; int index = MHelper.floor(delta); int index2 = (index + 1) & 3; delta -= index; index &= 3; - + Vec3i color1 = AuroraCrystalBlock.COLORS[index]; Vec3i color2 = AuroraCrystalBlock.COLORS[index2]; - + int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); - + return ColorUtil.toFloatArray(MHelper.color(r, g, b)); } - + static { - RENDER_LAYER = RenderLayer.getBeaconBeam(BetterEnd.makeID("textures/entity/eternal_crystal.png"), true); + RENDER_LAYER = RenderType.beaconBeam(BetterEnd.makeID("textures/entity/eternal_crystal.png"), true); SHARDS = new ModelPart[4]; - SHARDS[0] = new ModelPart(16, 16, 2, 4).addCuboid(-5.0F, 1.0F, -3.0F, 2.0F, 8.0F, 2.0F); - SHARDS[1] = new ModelPart(16, 16, 2, 4).addCuboid(3.0F, -1.0F, -1.0F, 2.0F, 8.0F, 2.0F); - SHARDS[2] = new ModelPart(16, 16, 2, 4).addCuboid(-1.0F, 0.0F, -5.0F, 2.0F, 4.0F, 2.0F); - SHARDS[3] = new ModelPart(16, 16, 2, 4).addCuboid(0.0F, 3.0F, 4.0F, 2.0F, 6.0F, 2.0F); + SHARDS[0] = new ModelPart(16, 16, 2, 4).addBox(-5.0F, 1.0F, -3.0F, 2.0F, 8.0F, 2.0F); + SHARDS[1] = new ModelPart(16, 16, 2, 4).addBox(3.0F, -1.0F, -1.0F, 2.0F, 8.0F, 2.0F); + SHARDS[2] = new ModelPart(16, 16, 2, 4).addBox(-1.0F, 0.0F, -5.0F, 2.0F, 4.0F, 2.0F); + SHARDS[3] = new ModelPart(16, 16, 2, 4).addBox(0.0F, 3.0F, 4.0F, 2.0F, 6.0F, 2.0F); CORE = new ModelPart(16, 16, 0, 0); - CORE.addCuboid(-2.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F); + CORE.addBox(-2.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F); } } diff --git a/src/main/java/ru/betterend/config/ConfigKeeper.java b/src/main/java/ru/betterend/config/ConfigKeeper.java index 84133efc..b98c942e 100644 --- a/src/main/java/ru/betterend/config/ConfigKeeper.java +++ b/src/main/java/ru/betterend/config/ConfigKeeper.java @@ -4,15 +4,13 @@ import java.lang.reflect.Type; import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; - +import net.minecraft.util.GsonHelper; import org.jetbrains.annotations.Nullable; import com.google.common.collect.Maps; import com.google.common.reflect.TypeToken; import com.google.gson.JsonElement; import com.google.gson.JsonObject; - -import net.minecraft.util.JsonHelper; import ru.betterend.util.JsonFactory; public final class ConfigKeeper { @@ -109,7 +107,7 @@ public final class ConfigKeeper { @Override public Boolean fromJson() { - return JsonHelper.getBoolean(location, key, defaultValue); + return GsonHelper.getAsBoolean(location, key, defaultValue); } @Override @@ -126,7 +124,7 @@ public final class ConfigKeeper { @Override public Float fromJson() { - return JsonHelper.getFloat(location, key, defaultValue); + return GsonHelper.getAsFloat(location, key, defaultValue); } @Override @@ -143,7 +141,7 @@ public final class ConfigKeeper { @Override public Float fromJson() { - return JsonHelper.getFloat(location, key, defaultValue); + return GsonHelper.getAsFloat(location, key, defaultValue); } @Override @@ -165,7 +163,7 @@ public final class ConfigKeeper { @Override public Integer fromJson() { - return JsonHelper.getInt(location, key, defaultValue); + return GsonHelper.getAsInt(location, key, defaultValue); } @Override @@ -182,7 +180,7 @@ public final class ConfigKeeper { @Override public Integer fromJson() { - return JsonHelper.getInt(location, key, defaultValue); + return GsonHelper.getAsInt(location, key, defaultValue); } @Override @@ -199,7 +197,7 @@ public final class ConfigKeeper { @Override public String fromJson() { - return JsonHelper.getString(location, key, defaultValue); + return GsonHelper.getAsString(location, key, defaultValue); } @Override diff --git a/src/main/java/ru/betterend/config/ConfigKey.java b/src/main/java/ru/betterend/config/ConfigKey.java index ab6ce6dd..de970d51 100644 --- a/src/main/java/ru/betterend/config/ConfigKey.java +++ b/src/main/java/ru/betterend/config/ConfigKey.java @@ -6,14 +6,14 @@ public class ConfigKey { private final String path[]; private final String entry; private final boolean root; - + public ConfigKey(String entry, String... path) { this.validate(entry); this.path = path; this.entry = entry; this.root = path.length == 0 || (path.length == 1 && path[0].isEmpty()); } - + public ConfigKey(String entry, ResourceLocation path) { this(entry, path.getNamespace(), path.getPath()); } @@ -25,7 +25,7 @@ public class ConfigKey { public String getEntry() { return entry; } - + public boolean isRoot() { return root; } @@ -61,7 +61,7 @@ public class ConfigKey { } return true; } - + @Override public String toString() { if (root) { @@ -73,7 +73,7 @@ public class ConfigKey { } return String.format("%s:%s", p, entry); } - + private void validate(String entry) { if (entry == null) { throw new NullPointerException("Config key must be not null!"); diff --git a/src/main/java/ru/betterend/config/IdConfig.java b/src/main/java/ru/betterend/config/IdConfig.java index 734c7aaf..e6e84f7f 100644 --- a/src/main/java/ru/betterend/config/IdConfig.java +++ b/src/main/java/ru/betterend/config/IdConfig.java @@ -1,26 +1,23 @@ package ru.betterend.config; import java.util.function.BiFunction; - -import org.jetbrains.annotations.Nullable; - import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; import ru.betterend.config.ConfigKeeper.Entry; import ru.betterend.config.ConfigKeeper.FloatRange; import ru.betterend.config.ConfigKeeper.IntegerRange; public class IdConfig extends Config { - + protected final BiFunction keyFactory; - + public IdConfig(String group, BiFunction keyFactory) { super(group); this.keyFactory = keyFactory; } @Override - protected void registerEntries() { - } + protected void registerEntries() {} protected ConfigKey createKey(ResourceLocation id, String key) { return this.keyFactory.apply(id, key); @@ -63,7 +60,7 @@ public class IdConfig extends Config { public boolean setRangedInt(ResourceLocation id, String key, int value) { return this.setRanged(createKey(id, key), value, IntegerRange.class); } - + public boolean setRangedFloat(ResourceLocation id, String key, float value) { return this.setRanged(createKey(id, key), value, FloatRange.class); } diff --git a/src/main/java/ru/betterend/effects/EndEnchantments.java b/src/main/java/ru/betterend/effects/EndEnchantments.java index dd801a02..6755a3de 100644 --- a/src/main/java/ru/betterend/effects/EndEnchantments.java +++ b/src/main/java/ru/betterend/effects/EndEnchantments.java @@ -1,17 +1,16 @@ package ru.betterend.effects; -import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.core.Registry; +import net.minecraft.world.item.enchantment.Enchantment; import ru.betterend.BetterEnd; import ru.betterend.effects.enchantment.EndVeilEnchantment; public class EndEnchantments { public final static Enchantment END_VEIL = registerEnchantment("end_veil", new EndVeilEnchantment()); - + public static Enchantment registerEnchantment(String name, Enchantment enchantment) { return Registry.register(Registry.ENCHANTMENT, BetterEnd.makeID(name), enchantment); } - - public static void register() { - } + + public static void register() {} } diff --git a/src/main/java/ru/betterend/effects/EndPotions.java b/src/main/java/ru/betterend/effects/EndPotions.java index ca53fca4..e0a91270 100644 --- a/src/main/java/ru/betterend/effects/EndPotions.java +++ b/src/main/java/ru/betterend/effects/EndPotions.java @@ -1,29 +1,28 @@ package ru.betterend.effects; +import net.minecraft.core.Registry; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.Potions; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.mixin.common.BrewingAccessor; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public class EndPotions { - public final static Potion END_VEIL = registerPotion("end_veil", EndMobEffects.END_VEIL, 3600); - public final static Potion LONG_END_VEIL = registerPotion("long_end_veil", EndMobEffects.END_VEIL, 9600); - + public final static Potion END_VEIL = registerPotion("end_veil", EndStatusEffects.END_VEIL, 3600); + public final static Potion LONG_END_VEIL = registerPotion("long_end_veil", EndStatusEffects.END_VEIL, 9600); + public static Potion registerPotion(String name, MobEffect effect, int duration) { - return registerPotion(name, - new Potion(name, new MobEffectInstance(effect, duration))); + return registerPotion(name, new Potion(name, new MobEffectInstance[]{ new MobEffectInstance(effect, duration) })); } - + public static Potion registerPotion(String name, Potion potion) { return Registry.register(Registry.POTION, BetterEnd.makeID(name), potion); } - + public static void register() { BrewingAccessor.callRegisterPotionRecipe(Potions.AWKWARD, EndItems.ENDER_DUST, END_VEIL); BrewingAccessor.callRegisterPotionRecipe(END_VEIL, Items.REDSTONE, LONG_END_VEIL); diff --git a/src/main/java/ru/betterend/effects/EndStatusEffects.java b/src/main/java/ru/betterend/effects/EndStatusEffects.java index 9ad50a28..b5176126 100644 --- a/src/main/java/ru/betterend/effects/EndStatusEffects.java +++ b/src/main/java/ru/betterend/effects/EndStatusEffects.java @@ -1,15 +1,15 @@ package ru.betterend.effects; -import net.minecraft.world.effect.MobEffect; import net.minecraft.core.Registry; +import net.minecraft.world.effect.MobEffect; import ru.betterend.BetterEnd; import ru.betterend.effects.status.EndVeilEffect; -public class EndMobEffects { - +public class EndStatusEffects { + public final static MobEffect END_VEIL = registerEffect("end_veil", new EndVeilEffect()); - + public static MobEffect registerEffect(String name, E effect) { - return Registry.register(Registry.STATUS_EFFECT, BetterEnd.makeID(name), effect); + return Registry.register(Registry.MOB_EFFECT, BetterEnd.makeID(name), effect); } } diff --git a/src/main/java/ru/betterend/effects/enchantment/EndVeilEnchantment.java b/src/main/java/ru/betterend/effects/enchantment/EndVeilEnchantment.java index 991cdd38..57d040e9 100644 --- a/src/main/java/ru/betterend/effects/enchantment/EndVeilEnchantment.java +++ b/src/main/java/ru/betterend/effects/enchantment/EndVeilEnchantment.java @@ -1,17 +1,17 @@ package ru.betterend.effects.enchantment; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentTarget; import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentCategory; public class EndVeilEnchantment extends Enchantment { public EndVeilEnchantment() { - super(Enchantment.Rarity.VERY_RARE, EnchantmentTarget.ARMOR_HEAD, new EquipmentSlot[] { EquipmentSlot.HEAD }); + super(Enchantment.Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, new EquipmentSlot[] { EquipmentSlot.HEAD }); } - + @Override - public boolean isAvailableForRandomSelection() { + public boolean isDiscoverable() { return false; } } diff --git a/src/main/java/ru/betterend/effects/status/EndVeilEffect.java b/src/main/java/ru/betterend/effects/status/EndVeilEffect.java index b9dfce0f..eff6cbb3 100644 --- a/src/main/java/ru/betterend/effects/status/EndVeilEffect.java +++ b/src/main/java/ru/betterend/effects/status/EndVeilEffect.java @@ -1,16 +1,16 @@ package ru.betterend.effects.status; import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectType; +import net.minecraft.world.effect.MobEffectCategory; public class EndVeilEffect extends MobEffect { public EndVeilEffect() { - super(MobEffectType.BENEFICIAL, 0x0D554A); + super(MobEffectCategory.BENEFICIAL, 0x0D554A); } - + @Override - public boolean canApplyUpdateEffect(int duration, int amplifier) { + public boolean isDurationEffectTick(int duration, int amplifier) { return false; } } diff --git a/src/main/java/ru/betterend/entity/CubozoaEntity.java b/src/main/java/ru/betterend/entity/CubozoaEntity.java index 5010e020..067e9226 100644 --- a/src/main/java/ru/betterend/entity/CubozoaEntity.java +++ b/src/main/java/ru/betterend/entity/CubozoaEntity.java @@ -2,143 +2,139 @@ package ru.betterend.entity; import java.util.List; import java.util.Random; - -import net.minecraft.world.entity.EntityData; -import net.minecraft.world.entity.EntityDimensions; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.ai.control.MoveControl; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.damage.DamageSource; -import net.minecraft.world.entity.data.DataTracker; -import net.minecraft.world.entity.data.TrackedData; -import net.minecraft.world.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.passive.SchoolingFishEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; +import net.minecraft.network.protocol.game.ClientboundGameEventPacket; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.FluidTags; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; import net.minecraft.util.Mth; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.entity.SpawnGroupData; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.control.MoveControl; +import net.minecraft.world.entity.animal.AbstractSchoolingFish; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.phys.AABB; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndItems; -public class CubozoaEntity extends SchoolingFishEntity { +public class CubozoaEntity extends AbstractSchoolingFish { public static final int VARIANTS = 2; - private static final TrackedData VARIANT = DataTracker.registerData(CubozoaEntity.class, - TrackedDataHandlerRegistry.BYTE); - private static final TrackedData SCALE = DataTracker.registerData(CubozoaEntity.class, - TrackedDataHandlerRegistry.BYTE); + private static final EntityDataAccessor VARIANT = SynchedEntityData.defineId(CubozoaEntity.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor SCALE = SynchedEntityData.defineId(CubozoaEntity.class, EntityDataSerializers.BYTE); public CubozoaEntity(EntityType entityType, Level world) { super(entityType, world); } @Override - public EntityData initialize(ServerLevelAccessor world, LocalDifficulty difficulty, SpawnReason spawnReason, - EntityData entityData, CompoundTag entityTag) { - EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityTag); - if (EndBiomes.getFromBiome(world.getBiome(getBlockPos())) == EndBiomes.SULPHUR_SPRINGS) { - this.dataTracker.set(VARIANT, (byte) 1); + public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData, CompoundTag entityTag) { + SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag); + if (EndBiomes.getFromBiome(world.getBiome(blockPosition())) == EndBiomes.SULPHUR_SPRINGS) { + this.entityData.set(VARIANT, (byte) 1); } - this.calculateDimensions(); + this.refreshDimensions(); return data; } @Override - protected void initDataTracker() { - super.initDataTracker(); - this.dataTracker.startTracking(VARIANT, (byte) 0); - this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16)); + protected void defineSynchedData() { + super.defineSynchedData(); + this.entityData.define(VARIANT, (byte) 0); + this.entityData.define(SCALE, (byte) this.getRandom().nextInt(16)); } @Override - public void writeCustomDataToTag(CompoundTag tag) { - super.writeCustomDataToTag(tag); + public void addAdditionalSaveData(CompoundTag tag) { + super.addAdditionalSaveData(tag); tag.putByte("Variant", (byte) getVariant()); tag.putByte("Scale", (byte) getScale()); } @Override - public void readCustomDataFromTag(CompoundTag tag) { - super.readCustomDataFromTag(tag); + public void readAdditionalSaveData(CompoundTag tag) { + super.readAdditionalSaveData(tag); if (tag.contains("Variant")) { - this.dataTracker.set(VARIANT, tag.getByte("Variant")); + this.entityData.set(VARIANT, tag.getByte("Variant")); } if (tag.contains("Scale")) { - this.dataTracker.set(SCALE, tag.getByte("Scale")); + this.entityData.set(SCALE, tag.getByte("Scale")); } } - public static DefaultAttributeContainer.Builder createMobAttributes() { - return LivingEntity.createLivingAttributes().add(Attributes.MAX_HEALTH, 2.0).add(Attributes.FOLLOW_RANGE, 16.0) + public static AttributeSupplier.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(Attributes.MAX_HEALTH, 2.0) + .add(Attributes.FOLLOW_RANGE, 16.0) .add(Attributes.MOVEMENT_SPEED, 0.5); } public int getVariant() { - return (int) this.dataTracker.get(VARIANT); + return (int) this.entityData.get(VARIANT); } public float getScale() { - return this.dataTracker.get(SCALE) / 32F + 0.75F; + return this.entityData.get(SCALE) / 32F + 0.75F; } - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, SpawnReason spawnReason, - BlockPos pos, Random random) { - Box box = new Box(pos).expand(16); - List list = world.getEntitiesByClass(CubozoaEntity.class, box, (entity) -> { + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + AABB box = new AABB(pos).inflate(16); + List list = world.getEntitiesOfClass(CubozoaEntity.class, box, (entity) -> { return true; }); return list.size() < 9; } - protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) { + protected float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) { return dimensions.height * 0.5F; } - + @Override - protected void dropLoot(DamageSource source, boolean causedByPlayer) { + protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) { int count = random.nextInt(3); if (count > 0) { - ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(EndItems.GELATINE, count)); - this.world.spawnEntity(drop); + ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(EndItems.GELATINE, count)); + this.level.addFreshEntity(drop); } } @Override - protected ItemStack getFishBucketItem() { + protected ItemStack getBucketItemStack() { return new ItemStack(Items.WATER_BUCKET); } @Override protected SoundEvent getFlopSound() { - return SoundEvents.ENTITY_SALMON_FLOP; + return SoundEvents.SALMON_FLOP; } - + @Override - public void onPlayerCollision(Player player) { - if (player instanceof ServerPlayer && player.damage(DamageSource.mob(this), 0.5F)) { + public void playerTouch(Player player) { + if (player instanceof ServerPlayer && player.hurt(DamageSource.mobAttack(this), 0.5F)) { if (!this.isSilent()) { - ((ServerPlayer) player).networkHandler - .sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PUFFERFISH_STING, 0.0F)); + ((ServerPlayer) player).connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.PUFFER_FISH_STING, 0.0F)); } if (random.nextBoolean()) { - player.addMobEffect(new MobEffectInstance(MobEffects.POISON, 20, 0)); + player.addEffect(new MobEffectInstance(MobEffects.POISON, 20, 0)); } } } @@ -149,30 +145,30 @@ public class CubozoaEntity extends SchoolingFishEntity { } public void tick() { - if (this.entity.isSubmergedIn(FluidTags.WATER)) { - this.entity.setVelocity(this.entity.getVelocity().add(0.0D, 0.005D, 0.0D)); + if (this.mob.isEyeInFluid(FluidTags.WATER)) { + this.mob.setDeltaMovement(this.mob.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); } - if (this.state == MoveControl.State.MOVE_TO && !this.entity.getNavigation().isIdle()) { - float f = (float) (this.speed * this.entity.getAttributeValue(Attributes.MOVEMENT_SPEED)); - this.entity.setMovementSpeed(Mth.lerp(0.125F, this.entity.getMovementSpeed(), f)); - double d = this.targetX - this.entity.getX(); - double e = this.targetY - this.entity.getY(); - double g = this.targetZ - this.entity.getZ(); + if (this.operation == MoveControl.Operation.MOVE_TO && !this.mob.getNavigation().isDone()) { + float f = (float) (this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED)); + this.mob.setSpeed(Mth.lerp(0.125F, this.mob.getSpeed(), f)); + double d = this.wantedX - this.mob.getX(); + double e = this.wantedY - this.mob.getY(); + double g = this.wantedZ - this.mob.getZ(); if (e != 0.0D) { double h = (double) Mth.sqrt(d * d + e * e + g * g); - this.entity.setVelocity(this.entity.getVelocity().add(0.0D, - (double) this.entity.getMovementSpeed() * (e / h) * 0.1D, 0.0D)); + this.mob.setDeltaMovement(this.mob.getDeltaMovement().add(0.0D, (double) this.mob.getSpeed() * (e / h) * 0.1D, 0.0D)); } if (d != 0.0D || g != 0.0D) { float i = (float) (Mth.atan2(g, d) * 57.2957763671875D) - 90.0F; - this.entity.yaw = this.changeAngle(this.entity.yaw, i, 90.0F); - this.entity.bodyYaw = this.entity.yaw; + this.mob.yRot = this.rotlerp(this.mob.yRot, i, 90.0F); + this.mob.yBodyRot = this.mob.yRot; } - } else { - this.entity.setMovementSpeed(0.0F); + } + else { + this.mob.setSpeed(0.0F); } } } diff --git a/src/main/java/ru/betterend/entity/DragonflyEntity.java b/src/main/java/ru/betterend/entity/DragonflyEntity.java index c8519aa4..a105912e 100644 --- a/src/main/java/ru/betterend/entity/DragonflyEntity.java +++ b/src/main/java/ru/betterend/entity/DragonflyEntity.java @@ -2,36 +2,35 @@ package ru.betterend.entity; import java.util.EnumSet; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.Flutterer; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.ai.TargetFinder; -import net.minecraft.world.entity.ai.control.FlightMoveControl; -import net.minecraft.world.entity.ai.control.LookControl; -import net.minecraft.world.entity.ai.goal.AnimalMateGoal; -import net.minecraft.world.entity.ai.goal.FollowParentGoal; -import net.minecraft.world.entity.ai.goal.Goal; -import net.minecraft.world.entity.ai.goal.SwimGoal; -import net.minecraft.world.entity.ai.pathing.BirdNavigation; -import net.minecraft.world.entity.ai.pathing.EntityNavigation; -import net.minecraft.world.entity.ai.pathing.Path; -import net.minecraft.world.entity.ai.pathing.PathNodeType; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.mob.MobEntity; -import net.minecraft.world.entity.passive.AnimalEntity; -import net.minecraft.world.entity.passive.PassiveEntity; +import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; -import net.minecraft.core.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.Heightmap.Type; -import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.entity.AgableMob; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.control.FlyingMoveControl; +import net.minecraft.world.entity.ai.control.LookControl; +import net.minecraft.world.entity.ai.goal.BreedGoal; +import net.minecraft.world.entity.ai.goal.FloatGoal; +import net.minecraft.world.entity.ai.goal.FollowParentGoal; +import net.minecraft.world.entity.ai.goal.Goal; +import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.util.RandomPos; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.FlyingAnimal; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.pathfinder.BlockPathTypes; +import net.minecraft.world.level.pathfinder.Path; +import net.minecraft.world.phys.Vec3; import ru.betterend.entity.DragonflyEntity.DragonflyLookControl; import ru.betterend.entity.DragonflyEntity.WanderAroundGoal; import ru.betterend.registry.EndEntities; @@ -39,51 +38,53 @@ import ru.betterend.registry.EndSounds; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; -public class DragonflyEntity extends AnimalEntity implements Flutterer { +public class DragonflyEntity extends Animal implements FlyingAnimal { public DragonflyEntity(EntityType entityType, Level world) { super(entityType, world); - this.moveControl = new FlightMoveControl(this, 20, true); + this.moveControl = new FlyingMoveControl(this, 20, true); this.lookControl = new DragonflyLookControl(this); - this.setPathfindingPenalty(PathNodeType.WATER, -1.0F); - this.setPathfindingPenalty(PathNodeType.DANGER_FIRE, -1.0F); - this.experiencePoints = 1; + this.setPathfindingMalus(BlockPathTypes.WATER, -1.0F); + this.setPathfindingMalus(BlockPathTypes.DANGER_FIRE, -1.0F); + this.xpReward = 1; } - public static DefaultAttributeContainer.Builder createMobAttributes() { - return LivingEntity.createLivingAttributes().add(Attributes.MAX_HEALTH, 8.0D) - .add(Attributes.FOLLOW_RANGE, 16.0D).add(Attributes.FLYING_SPEED, 1.0D) + public static AttributeSupplier.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(Attributes.MAX_HEALTH, 8.0D) + .add(Attributes.FOLLOW_RANGE, 16.0D) + .add(Attributes.FLYING_SPEED, 1.0D) .add(Attributes.MOVEMENT_SPEED, 0.1D); } @Override - protected EntityNavigation createNavigation(Level world) { - BirdNavigation birdNavigation = new BirdNavigation(this, world) { - public boolean isValidPosition(BlockPos pos) { - BlockState state = this.world.getBlockState(pos); - return state.isAir() || !state.getMaterial().blocksMovement(); + protected PathNavigation createNavigation(Level world) { + FlyingPathNavigation birdNavigation = new FlyingPathNavigation(this, world) { + public boolean isStableDestination(BlockPos pos) { + BlockState state = this.level.getBlockState(pos); + return state.isAir() || !state.getMaterial().blocksMotion(); } public void tick() { super.tick(); } }; - birdNavigation.setCanPathThroughDoors(false); - birdNavigation.setCanSwim(false); - birdNavigation.setCanEnterOpenDoors(true); + birdNavigation.setCanOpenDoors(false); + birdNavigation.setCanFloat(false); + birdNavigation.setCanPassDoors(true); return birdNavigation; } @Override - public float getPathfindingFavor(BlockPos pos, WorldView world) { + public float getWalkTargetValue(BlockPos pos, LevelReader world) { return world.getBlockState(pos).isAir() ? 10.0F : 0.0F; } @Override - protected void initGoals() { - this.goalSelector.add(1, new SwimGoal(this)); - this.goalSelector.add(2, new AnimalMateGoal(this, 1.0D)); - this.goalSelector.add(3, new FollowParentGoal(this, 1.0D)); - this.goalSelector.add(4, new WanderAroundGoal()); + protected void registerGoals() { + this.goalSelector.addGoal(1, new FloatGoal(this)); + this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); + this.goalSelector.addGoal(3, new FollowParentGoal(this, 1.0D)); + this.goalSelector.addGoal(4, new WanderAroundGoal()); } @Override @@ -92,22 +93,22 @@ public class DragonflyEntity extends AnimalEntity implements Flutterer { } @Override - protected boolean hasWings() { + protected boolean makeFlySound() { return true; } @Override - public boolean handleFallDamage(float fallDistance, float damageMultiplier) { + public boolean causeFallDamage(float fallDistance, float damageMultiplier) { return false; } @Override - public boolean canClimb() { + public boolean isMovementNoisy() { return false; } @Override - public boolean hasNoGravity() { + public boolean isNoGravity() { return true; } @@ -122,79 +123,78 @@ public class DragonflyEntity extends AnimalEntity implements Flutterer { } class DragonflyLookControl extends LookControl { - DragonflyLookControl(MobEntity entity) { + DragonflyLookControl(Mob entity) { super(entity); } - protected boolean shouldStayHorizontal() { + protected boolean resetXRotOnTick() { return true; } } class WanderAroundGoal extends Goal { WanderAroundGoal() { - this.setControls(EnumSet.of(Goal.Control.MOVE)); + this.setFlags(EnumSet.of(Goal.Flag.MOVE)); } - public boolean canStart() { - return DragonflyEntity.this.navigation.isIdle() && DragonflyEntity.this.random.nextInt(10) == 0; + public boolean canUse() { + return DragonflyEntity.this.navigation.isDone() && DragonflyEntity.this.random.nextInt(10) == 0; } - public boolean shouldContinue() { - return DragonflyEntity.this.navigation.isFollowingPath(); + public boolean canContinueToUse() { + return DragonflyEntity.this.navigation.isInProgress(); } public void start() { - Vec3d vec3d = this.getRandomLocation(); + Vec3 vec3d = this.getRandomLocation(); if (vec3d != null) { BlockPos pos = new BlockPos(vec3d); try { - Path path = DragonflyEntity.this.navigation.findPathTo(pos, 1); + Path path = DragonflyEntity.this.navigation.createPath(pos, 1); if (path != null) { - DragonflyEntity.this.navigation.startMovingAlong(path, 1.0D); + DragonflyEntity.this.navigation.moveTo(path, 1.0D); } - } catch (Exception e) { } + catch (Exception e) {} } super.start(); } - private Vec3d getRandomLocation() { - int h = BlocksHelper.downRay(DragonflyEntity.this.world, DragonflyEntity.this.getBlockPos(), 16); - Vec3d rotation = DragonflyEntity.this.getRotationVec(0.0F); - Vec3d airPos = TargetFinder.findAirTarget(DragonflyEntity.this, 8, 7, rotation, 1.5707964F, 2, 1); + private Vec3 getRandomLocation() { + int h = BlocksHelper.downRay(DragonflyEntity.this.level, DragonflyEntity.this.blockPosition(), 16); + Vec3 rotation = DragonflyEntity.this.getViewVector(0.0F); + Vec3 airPos = RandomPos.getAboveLandPos(DragonflyEntity.this, 8, 7, rotation, 1.5707964F, 2, 1); if (airPos != null) { if (isInVoid(airPos)) { for (int i = 0; i < 8; i++) { - airPos = TargetFinder.findAirTarget(DragonflyEntity.this, 16, 7, rotation, MHelper.PI2, 2, 1); + airPos = RandomPos.getAboveLandPos(DragonflyEntity.this, 16, 7, rotation, MHelper.PI2, 2, 1); if (airPos != null && !isInVoid(airPos)) { return airPos; } } return null; } - if (h > 5 && airPos.getY() >= DragonflyEntity.this.getBlockPos().getY()) { - airPos = new Vec3d(airPos.x, airPos.y - h * 0.5, airPos.z); + if (h > 5 && airPos.y() >= DragonflyEntity.this.blockPosition().getY()) { + airPos = new Vec3(airPos.x, airPos.y - h * 0.5, airPos.z); } return airPos; } - return TargetFinder.findGroundTarget(DragonflyEntity.this, 8, 4, -2, rotation, 1.5707963705062866D); + return RandomPos.getAirPos(DragonflyEntity.this, 8, 4, -2, rotation, 1.5707963705062866D); } - private boolean isInVoid(Vec3d pos) { - int h = BlocksHelper.downRay(DragonflyEntity.this.world, new BlockPos(pos), 128); + private boolean isInVoid(Vec3 pos) { + int h = BlocksHelper.downRay(DragonflyEntity.this.level, new BlockPos(pos), 128); return h > 100; } } @Override - public PassiveEntity createChild(ServerLevel world, PassiveEntity entity) { + public AgableMob getBreedOffspring(ServerLevel world, AgableMob entity) { return EndEntities.DRAGONFLY.create(world); } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, SpawnReason spawnReason, - BlockPos pos, Random random) { - int y = world.getChunk(pos).sampleHeightmap(Type.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); + + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + int y = world.getChunk(pos).getHeight(Types.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); return y > 0 && pos.getY() >= y; } } diff --git a/src/main/java/ru/betterend/entity/EndFishEntity.java b/src/main/java/ru/betterend/entity/EndFishEntity.java index eef8815f..a37d3854 100644 --- a/src/main/java/ru/betterend/entity/EndFishEntity.java +++ b/src/main/java/ru/betterend/entity/EndFishEntity.java @@ -2,143 +2,138 @@ package ru.betterend.entity; import java.util.List; import java.util.Random; - -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.entity.EntityData; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.damage.DamageSource; -import net.minecraft.world.entity.data.DataTracker; -import net.minecraft.world.entity.data.TrackedData; -import net.minecraft.world.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.world.entity.passive.SchoolingFishEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; +import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnGroupData; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.animal.AbstractSchoolingFish; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.AABB; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndItems; -public class EndFishEntity extends SchoolingFishEntity { +public class EndFishEntity extends AbstractSchoolingFish { public static final int VARIANTS_NORMAL = 5; public static final int VARIANTS_SULPHUR = 3; public static final int VARIANTS = VARIANTS_NORMAL + VARIANTS_SULPHUR; - private static final TrackedData VARIANT = DataTracker.registerData(EndFishEntity.class, - TrackedDataHandlerRegistry.BYTE); - private static final TrackedData SCALE = DataTracker.registerData(EndFishEntity.class, - TrackedDataHandlerRegistry.BYTE); - + private static final EntityDataAccessor VARIANT = SynchedEntityData.defineId(EndFishEntity.class, EntityDataSerializers.BYTE); + private static final EntityDataAccessor SCALE = SynchedEntityData.defineId(EndFishEntity.class, EntityDataSerializers.BYTE); + public EndFishEntity(EntityType entityType, Level world) { super(entityType, world); } - + @Override - public EntityData initialize(ServerLevelAccessor world, LocalDifficulty difficulty, SpawnReason spawnReason, - EntityData entityData, CompoundTag entityTag) { - EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityTag); - if (EndBiomes.getFromBiome(world.getBiome(getBlockPos())) == EndBiomes.SULPHUR_SPRINGS) { - this.dataTracker.set(VARIANT, (byte) (random.nextInt(VARIANTS_SULPHUR) + VARIANTS_NORMAL)); + public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData, CompoundTag entityTag) { + SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag); + if (EndBiomes.getFromBiome(world.getBiome(blockPosition())) == EndBiomes.SULPHUR_SPRINGS) { + this.entityData.set(VARIANT, (byte) (random.nextInt(VARIANTS_SULPHUR) + VARIANTS_NORMAL)); } - this.calculateDimensions(); + this.refreshDimensions(); return data; } - + @Override - protected void initDataTracker() { - super.initDataTracker(); - this.dataTracker.startTracking(VARIANT, (byte) this.getRandom().nextInt(VARIANTS_NORMAL)); - this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16)); + protected void defineSynchedData() { + super.defineSynchedData(); + this.entityData.define(VARIANT, (byte) this.getRandom().nextInt(VARIANTS_NORMAL)); + this.entityData.define(SCALE, (byte) this.getRandom().nextInt(16)); } - + @Override - public void writeCustomDataToTag(CompoundTag tag) { - super.writeCustomDataToTag(tag); + public void addAdditionalSaveData(CompoundTag tag) { + super.addAdditionalSaveData(tag); tag.putByte("Variant", (byte) getVariant()); tag.putByte("Scale", (byte) getScale()); } @Override - public void readCustomDataFromTag(CompoundTag tag) { - super.readCustomDataFromTag(tag); + public void readAdditionalSaveData(CompoundTag tag) { + super.readAdditionalSaveData(tag); if (tag.contains("Variant")) { - this.dataTracker.set(VARIANT, tag.getByte("Variant")); + this.entityData.set(VARIANT, tag.getByte("Variant")); } if (tag.contains("Scale")) { - this.dataTracker.set(SCALE, tag.getByte("Scale")); + this.entityData.set(SCALE, tag.getByte("Scale")); } } @Override - protected ItemStack getFishBucketItem() { + protected ItemStack getBucketItemStack() { return new ItemStack(EndItems.BUCKET_END_FISH); } @Override protected SoundEvent getFlopSound() { - return SoundEvents.ENTITY_TROPICAL_FISH_FLOP; + return SoundEvents.TROPICAL_FISH_FLOP; } @Override protected SoundEvent getAmbientSound() { - return SoundEvents.ENTITY_SALMON_AMBIENT; + return SoundEvents.SALMON_AMBIENT; } @Override protected SoundEvent getDeathSound() { - return SoundEvents.ENTITY_SALMON_DEATH; + return SoundEvents.SALMON_DEATH; } @Override protected SoundEvent getHurtSound(DamageSource source) { - return SoundEvents.ENTITY_SALMON_HURT; + return SoundEvents.SALMON_HURT; } - + @Override public void tick() { super.tick(); - if (random.nextInt(8) == 0 && getBlockState().is(Blocks.WATER)) { + if (random.nextInt(8) == 0 && getFeetBlockState().is(Blocks.WATER)) { double x = getX() + random.nextGaussian() * 0.2; double y = getY() + random.nextGaussian() * 0.2; double z = getZ() + random.nextGaussian() * 0.2; - world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); + level.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0); } } - - public static DefaultAttributeContainer.Builder createMobAttributes() { - return LivingEntity.createLivingAttributes().add(Attributes.MAX_HEALTH, 2.0).add(Attributes.FOLLOW_RANGE, 16.0) + + public static AttributeSupplier.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(Attributes.MAX_HEALTH, 2.0) + .add(Attributes.FOLLOW_RANGE, 16.0) .add(Attributes.MOVEMENT_SPEED, 0.75); } - + public int getVariant() { - return (int) this.dataTracker.get(VARIANT); + return (int) this.entityData.get(VARIANT); } - + public float getScale() { - return this.dataTracker.get(SCALE) / 32F + 0.75F; + return this.entityData.get(SCALE) / 32F + 0.75F; } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, SpawnReason spawnReason, - BlockPos pos, Random random) { - Box box = new Box(pos).expand(16); - List list = world.getEntitiesByClass(EndFishEntity.class, box, (entity) -> { - return true; - }); + + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + AABB box = new AABB(pos).inflate(16); + List list = world.getEntitiesOfClass(EndFishEntity.class, box, (entity) -> { return true; }); return list.size() < 9; } - + @Override - protected void dropLoot(DamageSource source, boolean causedByPlayer) { - ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(EndItems.END_FISH_RAW)); - this.world.spawnEntity(drop); + protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) { + ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(EndItems.END_FISH_RAW)); + this.level.addFreshEntity(drop); } } diff --git a/src/main/java/ru/betterend/entity/EndSlimeEntity.java b/src/main/java/ru/betterend/entity/EndSlimeEntity.java index a8fcf67e..f23f8c99 100644 --- a/src/main/java/ru/betterend/entity/EndSlimeEntity.java +++ b/src/main/java/ru/betterend/entity/EndSlimeEntity.java @@ -3,41 +3,40 @@ package ru.betterend.entity; import java.util.EnumSet; import java.util.List; import java.util.Random; - -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.entity.EntityData; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.ItemEntity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.ai.control.MoveControl; -import net.minecraft.world.entity.ai.goal.FollowTargetGoal; -import net.minecraft.world.entity.ai.goal.Goal; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.damage.DamageSource; -import net.minecraft.world.entity.data.DataTracker; -import net.minecraft.world.entity.data.TrackedData; -import net.minecraft.world.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.util.Mth; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.mob.SlimeEntity; -import net.minecraft.world.entity.passive.IronGolemEntity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnGroupData; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.control.MoveControl; +import net.minecraft.world.entity.ai.goal.Goal; +import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; +import net.minecraft.world.entity.animal.IronGolem; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.monster.Slime; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.text.Text; -import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.util.Mth; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; +import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.AABB; import ru.betterend.entity.EndSlimeEntity.EndSlimeMoveControl; import ru.betterend.entity.EndSlimeEntity.FaceTowardTargetGoal; import ru.betterend.entity.EndSlimeEntity.MoveGoal; @@ -49,131 +48,132 @@ import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; import ru.betterend.world.biome.EndBiome; -public class EndSlimeEntity extends SlimeEntity { - private static final TrackedData VARIANT = DataTracker.registerData(EndSlimeEntity.class, - TrackedDataHandlerRegistry.BYTE); +public class EndSlimeEntity extends Slime { + private static final EntityDataAccessor VARIANT = SynchedEntityData.defineId(EndSlimeEntity.class, EntityDataSerializers.BYTE); private static final MutableBlockPos POS = new MutableBlockPos(); - + public EndSlimeEntity(EntityType entityType, Level world) { super(entityType, world); this.moveControl = new EndSlimeMoveControl(this); } - - protected void initGoals() { - this.goalSelector.add(1, new SwimmingGoal()); - this.goalSelector.add(2, new FaceTowardTargetGoal()); - this.goalSelector.add(3, new RandomLookGoal()); - this.goalSelector.add(5, new MoveGoal()); - this.targetSelector.add(1, new FollowTargetGoal(this, Player.class, 10, true, false, (livingEntity) -> { + + protected void registerGoals() { + this.goalSelector.addGoal(1, new SwimmingGoal()); + this.goalSelector.addGoal(2, new FaceTowardTargetGoal()); + this.goalSelector.addGoal(3, new RandomLookGoal()); + this.goalSelector.addGoal(5, new MoveGoal()); + this.targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, Player.class, 10, true, false, (livingEntity) -> { return Math.abs(livingEntity.getY() - this.getY()) <= 4.0D; })); - this.targetSelector.add(3, new FollowTargetGoal(this, IronGolemEntity.class, true)); + this.targetSelector.addGoal(3, new NearestAttackableTargetGoal(this, IronGolem.class, true)); } - - public static DefaultAttributeContainer.Builder createMobAttributes() { - return LivingEntity.createLivingAttributes().add(Attributes.MAX_HEALTH, 1.0D) - .add(Attributes.ATTACK_DAMAGE, 1.0D).add(Attributes.FOLLOW_RANGE, 16.0D) + + public static AttributeSupplier.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(Attributes.MAX_HEALTH, 1.0D) + .add(Attributes.ATTACK_DAMAGE, 1.0D) + .add(Attributes.FOLLOW_RANGE, 16.0D) .add(Attributes.MOVEMENT_SPEED, 0.15D); } - + @Override - public EntityData initialize(ServerLevelAccessor world, LocalDifficulty difficulty, SpawnReason spawnReason, - EntityData entityData, CompoundTag entityTag) { - EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityTag); - EndBiome biome = EndBiomes.getFromBiome(world.getBiome(getBlockPos())); + public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData, CompoundTag entityTag) { + SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag); + EndBiome biome = EndBiomes.getFromBiome(world.getBiome(blockPosition())); if (biome == EndBiomes.FOGGY_MUSHROOMLAND) { this.setMossy(); - } else if (biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) { + } + else if (biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) { this.setLake(); - } else if (biome == EndBiomes.AMBER_LAND) { + } + else if (biome == EndBiomes.AMBER_LAND) { this.setAmber(true); } - this.calculateDimensions(); + this.refreshDimensions(); return data; } @Override - protected void initDataTracker() { - super.initDataTracker(); - this.dataTracker.startTracking(VARIANT, (byte) 0); + protected void defineSynchedData() { + super.defineSynchedData(); + this.entityData.define(VARIANT, (byte) 0); } - + @Override - public void writeCustomDataToTag(CompoundTag tag) { - super.writeCustomDataToTag(tag); + public void addAdditionalSaveData(CompoundTag tag) { + super.addAdditionalSaveData(tag); tag.putByte("Variant", (byte) getSlimeType()); } @Override - public void readCustomDataFromTag(CompoundTag tag) { - super.readCustomDataFromTag(tag); + public void readAdditionalSaveData(CompoundTag tag) { + super.readAdditionalSaveData(tag); if (tag.contains("Variant")) { - this.dataTracker.set(VARIANT, tag.getByte("Variant")); + this.entityData.set(VARIANT, tag.getByte("Variant")); } } @Override - protected ParticleOptions getParticles() { + protected ParticleOptions getParticleType() { return ParticleTypes.PORTAL; } - + @Override public void remove() { int i = this.getSize(); - if (!this.world.isClientSide && i > 1 && this.isDead()) { - Text text = this.getCustomName(); - boolean bl = this.isAiDisabled(); + if (!this.level.isClientSide && i > 1 && this.isDeadOrDying()) { + Component text = this.getCustomName(); + boolean bl = this.isNoAi(); float f = (float) i / 4.0F; int j = i / 2; int k = 2 + this.random.nextInt(3); int type = this.getSlimeType(); - + for (int l = 0; l < k; ++l) { float g = ((float) (l % 2) - 0.5F) * f; float h = ((float) (l / 2) - 0.5F) * f; - EndSlimeEntity slimeEntity = (EndSlimeEntity) this.getType().create(this.world); - if (this.isPersistent()) { - slimeEntity.setPersistent(); + EndSlimeEntity slimeEntity = (EndSlimeEntity) this.getType().create(this.level); + if (this.isPersistenceRequired()) { + slimeEntity.setPersistenceRequired(); } slimeEntity.setSlimeType(type); slimeEntity.setCustomName(text); - slimeEntity.setAiDisabled(bl); + slimeEntity.setNoAi(bl); slimeEntity.setInvulnerable(this.isInvulnerable()); ((ISlime) slimeEntity).beSetSlimeSize(j, true); - slimeEntity.calculateDimensions(); - slimeEntity.refreshPositionAndAngles(this.getX() + (double) g, this.getY() + 0.5D, - this.getZ() + (double) h, this.random.nextFloat() * 360.0F, 0.0F); - this.world.spawnEntity(slimeEntity); + slimeEntity.refreshDimensions(); + slimeEntity.moveTo(this.getX() + (double) g, this.getY() + 0.5D, this.getZ() + (double) h, this.random.nextFloat() * 360.0F, 0.0F); + this.level.addFreshEntity(slimeEntity); } } this.removed = true; } - + @Override - protected void dropLoot(DamageSource source, boolean causedByPlayer) { + protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) { int maxCount = this.getSize(); int minCount = maxCount >> 1; if (minCount < 1) { minCount = 1; } - if (causedByPlayer && this.attackingPlayer != null) { - int looting = EnchantmentHelper.getLooting(this.attackingPlayer); + if (causedByPlayer && this.lastHurtByPlayer != null) { + int looting = EnchantmentHelper.getMobLooting(this.lastHurtByPlayer); minCount += looting; } int count = minCount < maxCount ? MHelper.randRange(minCount, maxCount, random) : maxCount; - ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(Items.SLIME_BALL, count)); - this.world.spawnEntity(drop); + ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(Items.SLIME_BALL, count)); + this.level.addFreshEntity(drop); } - + public int getSlimeType() { - return this.dataTracker.get(VARIANT).intValue(); + return this.entityData.get(VARIANT).intValue(); } - + public void setSlimeType(int value) { - this.dataTracker.set(VARIANT, (byte) value); + this.entityData.set(VARIANT, (byte) value); } - + protected void setMossy() { setSlimeType(1); } @@ -181,7 +181,7 @@ public class EndSlimeEntity extends SlimeEntity { public boolean isMossy() { return getSlimeType() == 1; } - + protected void setLake() { setSlimeType(2); } @@ -189,38 +189,34 @@ public class EndSlimeEntity extends SlimeEntity { public boolean isLake() { return getSlimeType() == 2; } - + protected void setAmber(boolean mossy) { - this.dataTracker.set(VARIANT, (byte) 3); + this.entityData.set(VARIANT, (byte) 3); } public boolean isAmber() { - return this.dataTracker.get(VARIANT) == 3; + return this.entityData.get(VARIANT) == 3; } - + public boolean isChorus() { - return this.dataTracker.get(VARIANT) == 0; + return this.entityData.get(VARIANT) == 0; } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, SpawnReason spawnReason, - BlockPos pos, Random random) { - return random.nextInt(16) == 0 || isPermanentBiome(world, pos) - || (notManyEntities(world, pos, 32, 3) && isWaterNear(world, pos, 32, 8)); + + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + return random.nextInt(16) == 0 || isPermanentBiome(world, pos) || (notManyEntities(world, pos, 32, 3) && isWaterNear(world, pos, 32, 8)); } - + private static boolean isPermanentBiome(ServerLevelAccessor world, BlockPos pos) { Biome biome = world.getBiome(pos); return EndBiomes.getFromBiome(biome) == EndBiomes.CHORUS_FOREST; } - + private static boolean notManyEntities(ServerLevelAccessor world, BlockPos pos, int radius, int maxCount) { - Box box = new Box(pos).expand(radius); - List list = world.getEntitiesByClass(EndSlimeEntity.class, box, (entity) -> { - return true; - }); + AABB box = new AABB(pos).inflate(radius); + List list = world.getEntitiesOfClass(EndSlimeEntity.class, box, (entity) -> { return true; }); return list.size() <= maxCount; } - + private static boolean isWaterNear(ServerLevelAccessor world, BlockPos pos, int radius, int radius2) { for (int x = pos.getX() - radius; x <= pos.getX() + radius; x++) { POS.setX(x); @@ -236,27 +232,27 @@ public class EndSlimeEntity extends SlimeEntity { } return false; } - + class MoveGoal extends Goal { public MoveGoal() { - this.setControls(EnumSet.of(Goal.Control.JUMP, Goal.Control.MOVE)); + this.setFlags(EnumSet.of(Goal.Flag.JUMP, Goal.Flag.MOVE)); } - public boolean canStart() { - if (EndSlimeEntity.this.hasVehicle()) { + public boolean canUse() { + if (EndSlimeEntity.this.isPassenger()) { return false; } - - float yaw = EndSlimeEntity.this.getHeadYaw(); - float speed = EndSlimeEntity.this.getMovementSpeed(); + + float yaw = EndSlimeEntity.this.getYHeadRot(); + float speed = EndSlimeEntity.this.getSpeed(); if (speed > 0.1) { float dx = Mth.sin(-yaw * 0.017453292F); float dz = Mth.cos(-yaw * 0.017453292F); - BlockPos pos = EndSlimeEntity.this.getBlockPos().add(dx * speed * 4, 0, dz * speed * 4); - int down = BlocksHelper.downRay(EndSlimeEntity.this.world, pos, 16); + BlockPos pos = EndSlimeEntity.this.blockPosition().offset(dx * speed * 4, 0, dz * speed * 4); + int down = BlocksHelper.downRay(EndSlimeEntity.this.level, pos, 16); return down < 5; } - + return true; } @@ -267,18 +263,19 @@ public class EndSlimeEntity extends SlimeEntity { class SwimmingGoal extends Goal { public SwimmingGoal() { - this.setControls(EnumSet.of(Goal.Control.JUMP, Goal.Control.MOVE)); - EndSlimeEntity.this.getNavigation().setCanSwim(true); + this.setFlags(EnumSet.of(Goal.Flag.JUMP, Goal.Flag.MOVE)); + EndSlimeEntity.this.getNavigation().setCanFloat(true); } - public boolean canStart() { - return (EndSlimeEntity.this.isTouchingWater() || EndSlimeEntity.this.isInLava()) + public boolean canUse() { + return (EndSlimeEntity.this.isInWater() + || EndSlimeEntity.this.isInLava()) && EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl; } public void tick() { if (EndSlimeEntity.this.getRandom().nextFloat() < 0.8F) { - EndSlimeEntity.this.getJumpControl().setActive(); + EndSlimeEntity.this.getJumpControl().jump(); } ((EndSlimeMoveControl) EndSlimeEntity.this.getMoveControl()).move(1.2D); @@ -290,14 +287,15 @@ public class EndSlimeEntity extends SlimeEntity { private int timer; public RandomLookGoal() { - this.setControls(EnumSet.of(Goal.Control.LOOK)); + this.setFlags(EnumSet.of(Goal.Flag.LOOK)); } - public boolean canStart() { + public boolean canUse() { return EndSlimeEntity.this.getTarget() == null - && (EndSlimeEntity.this.onGround || EndSlimeEntity.this.isTouchingWater() + && (EndSlimeEntity.this.onGround + || EndSlimeEntity.this.isInWater() || EndSlimeEntity.this.isInLava() - || EndSlimeEntity.this.hasMobEffect(MobEffects.LEVITATION)) + || EndSlimeEntity.this.hasEffect(MobEffects.LEVITATION)) && EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl; } @@ -315,18 +313,19 @@ public class EndSlimeEntity extends SlimeEntity { private int ticksLeft; public FaceTowardTargetGoal() { - this.setControls(EnumSet.of(Goal.Control.LOOK)); + this.setFlags(EnumSet.of(Goal.Flag.LOOK)); } - public boolean canStart() { + public boolean canUse() { LivingEntity livingEntity = EndSlimeEntity.this.getTarget(); if (livingEntity == null) { return false; - } else if (!livingEntity.isAlive()) { + } + else if (!livingEntity.isAlive()) { return false; - } else { - return livingEntity instanceof Player && ((Player) livingEntity).abilities.invulnerable ? false - : EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl; + } + else { + return livingEntity instanceof Player && ((Player) livingEntity).abilities.invulnerable ? false : EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl; } } @@ -335,23 +334,25 @@ public class EndSlimeEntity extends SlimeEntity { super.start(); } - public boolean shouldContinue() { + public boolean canContinueToUse() { LivingEntity livingEntity = EndSlimeEntity.this.getTarget(); if (livingEntity == null) { return false; - } else if (!livingEntity.isAlive()) { + } + else if (!livingEntity.isAlive()) { return false; - } else if (livingEntity instanceof Player && ((Player) livingEntity).abilities.invulnerable) { + } + else if (livingEntity instanceof Player && ((Player) livingEntity).abilities.invulnerable) { return false; - } else { + } + else { return --this.ticksLeft > 0; } } public void tick() { - EndSlimeEntity.this.lookAtEntity(EndSlimeEntity.this.getTarget(), 10.0F, 10.0F); - ((EndSlimeMoveControl) EndSlimeEntity.this.getMoveControl()).look(EndSlimeEntity.this.yaw, - EndSlimeEntity.this.canAttack()); + EndSlimeEntity.this.lookAt(EndSlimeEntity.this.getTarget(), 10.0F, 10.0F); + ((EndSlimeMoveControl) EndSlimeEntity.this.getMoveControl()).look(EndSlimeEntity.this.yRot, EndSlimeEntity.this.isDealsDamage()); } } @@ -362,7 +363,7 @@ public class EndSlimeEntity extends SlimeEntity { public EndSlimeMoveControl(EndSlimeEntity slime) { super(slime); - this.targetYaw = 180.0F * slime.yaw / 3.1415927F; + this.targetYaw = 180.0F * slime.yRot / 3.1415927F; } public void look(float targetYaw, boolean jumpOften) { @@ -371,49 +372,48 @@ public class EndSlimeEntity extends SlimeEntity { } public void move(double speed) { - this.speed = speed; - this.state = MoveControl.State.MOVE_TO; + this.speedModifier = speed; + this.operation = MoveControl.Operation.MOVE_TO; } public void tick() { - this.entity.yaw = this.changeAngle(this.entity.yaw, this.targetYaw, 90.0F); - this.entity.headYaw = this.entity.yaw; - this.entity.bodyYaw = this.entity.yaw; - if (this.state != MoveControl.State.MOVE_TO) { - this.entity.setForwardSpeed(0.0F); - } else { - this.state = MoveControl.State.WAIT; - if (this.entity.isOnGround()) { - this.entity.setMovementSpeed( - (float) (this.speed * this.entity.getAttributeValue(Attributes.MOVEMENT_SPEED))); + this.mob.yRot = this.rotlerp(this.mob.yRot, this.targetYaw, 90.0F); + this.mob.yHeadRot = this.mob.yRot; + this.mob.yBodyRot = this.mob.yRot; + if (this.operation != MoveControl.Operation.MOVE_TO) { + this.mob.setZza(0.0F); + } + else { + this.operation = MoveControl.Operation.WAIT; + if (this.mob.isOnGround()) { + this.mob.setSpeed((float) (this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED))); if (this.ticksUntilJump-- <= 0) { - this.ticksUntilJump = EndSlimeEntity.this.getTicksUntilNextJump(); + this.ticksUntilJump = EndSlimeEntity.this.getJumpDelay(); if (this.jumpOften) { this.ticksUntilJump /= 3; } - EndSlimeEntity.this.getJumpControl().setActive(); - if (EndSlimeEntity.this.makesJumpSound()) { - EndSlimeEntity.this.playSound(EndSlimeEntity.this.getJumpSound(), - EndSlimeEntity.this.getSoundVolume(), getJumpSoundPitch()); + EndSlimeEntity.this.getJumpControl().jump(); + if (EndSlimeEntity.this.doPlayJumpSound()) { + EndSlimeEntity.this.playSound(EndSlimeEntity.this.getJumpSound(), EndSlimeEntity.this.getSoundVolume(), getJumpSoundPitch()); } - } else { - EndSlimeEntity.this.sidewaysSpeed = 0.0F; - EndSlimeEntity.this.forwardSpeed = 0.0F; - this.entity.setMovementSpeed(0.0F); } - } else { - this.entity.setMovementSpeed( - (float) (this.speed * this.entity.getAttributeValue(Attributes.MOVEMENT_SPEED))); + else { + EndSlimeEntity.this.xxa = 0.0F; + EndSlimeEntity.this.zza = 0.0F; + this.mob.setSpeed(0.0F); + } + } + else { + this.mob.setSpeed((float) (this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED))); } } } private float getJumpSoundPitch() { - float f = EndSlimeEntity.this.isSmall() ? 1.4F : 0.8F; - return ((EndSlimeEntity.this.random.nextFloat() - EndSlimeEntity.this.random.nextFloat()) * 0.2F + 1.0F) - * f; + float f = EndSlimeEntity.this.isTiny() ? 1.4F : 0.8F; + return ((EndSlimeEntity.this.random.nextFloat() - EndSlimeEntity.this.random.nextFloat()) * 0.2F + 1.0F) * f; } } } diff --git a/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java b/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java index e9f28bea..9e466de1 100644 --- a/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java +++ b/src/main/java/ru/betterend/entity/ShadowWalkerEntity.java @@ -2,64 +2,75 @@ package ru.betterend.entity; import java.util.List; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.ai.goal.FollowTargetGoal; -import net.minecraft.world.entity.ai.goal.LookAroundGoal; -import net.minecraft.world.entity.ai.goal.LookAtEntityGoal; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; import net.minecraft.world.entity.ai.goal.MeleeAttackGoal; -import net.minecraft.world.entity.ai.goal.WanderAroundFarGoal; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.damage.DamageSource; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.mob.HostileEntity; +import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal; +import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal; +import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; +import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.Level; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import ru.betterend.registry.EndSounds; import ru.betterend.util.MHelper; -public class ShadowWalkerEntity extends HostileEntity { +public class ShadowWalkerEntity extends Monster { public ShadowWalkerEntity(EntityType entityType, Level world) { super(entityType, world); } - + @Override - protected void initGoals() { - this.goalSelector.add(2, new AttackGoal(this, 1.0D, false)); - this.goalSelector.add(7, new WanderAroundFarGoal(this, 1.0D)); - this.goalSelector.add(8, new LookAtEntityGoal(this, Player.class, 8.0F)); - this.goalSelector.add(8, new LookAroundGoal(this)); - this.targetSelector.add(2, new FollowTargetGoal(this, Player.class, true)); + protected void registerGoals() { + this.goalSelector.addGoal(2, new AttackGoal(this, 1.0D, false)); + this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0D)); + this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F)); + this.goalSelector.addGoal(8, new RandomLookAroundGoal(this)); + this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, Player.class, true)); } - public static DefaultAttributeContainer.Builder createMobAttributes() { - return HostileEntity.createHostileAttributes().add(Attributes.FOLLOW_RANGE, 35.0) - .add(Attributes.MOVEMENT_SPEED, 0.15).add(Attributes.ATTACK_DAMAGE, 4.5).add(Attributes.ARMOR, 2.0) - .add(Attributes.ZOMBIE_SPAWN_REINFORCEMENTS); + public static AttributeSupplier.Builder createMobAttributes() { + return Monster.createMonsterAttributes() + .add(Attributes.FOLLOW_RANGE, 35.0) + .add(Attributes.MOVEMENT_SPEED, 0.15) + .add(Attributes.ATTACK_DAMAGE, 4.5) + .add(Attributes.ARMOR, 2.0) + .add(Attributes.SPAWN_REINFORCEMENTS_CHANCE); } - + @Override public void tick() { super.tick(); - world.addParticle(ParticleTypes.ASH, getX() + random.nextGaussian() * 0.2, - getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0); - world.addParticle(ParticleTypes.SMOKE, getX() + random.nextGaussian() * 0.2, - getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0); - world.addParticle(ParticleTypes.ENTITY_EFFECT, getX() + random.nextGaussian() * 0.2, - getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0); + level.addParticle(ParticleTypes.ASH, + getX() + random.nextGaussian() * 0.2, + getY() + random.nextGaussian() * 0.5 + 1, + getZ() + random.nextGaussian() * 0.2, + 0, 0, 0); + level.addParticle(ParticleTypes.SMOKE, + getX() + random.nextGaussian() * 0.2, + getY() + random.nextGaussian() * 0.5 + 1, + getZ() + random.nextGaussian() * 0.2, + 0, 0, 0); + level.addParticle(ParticleTypes.ENTITY_EFFECT, + getX() + random.nextGaussian() * 0.2, + getY() + random.nextGaussian() * 0.5 + 1, + getZ() + random.nextGaussian() * 0.2, + 0, 0, 0); } - + @Override protected SoundEvent getAmbientSound() { return EndSounds.ENTITY_SHADOW_WALKER; @@ -76,51 +87,47 @@ public class ShadowWalkerEntity extends HostileEntity { } @Override - protected void playStepSound(BlockPos pos, BlockState state) { - } - + protected void playStepSound(BlockPos pos, BlockState state) {} + @Override protected float getSoundVolume() { return MHelper.randRange(0.25F, 0.5F, random); } - + @Override - protected float getSoundPitch() { + protected float getVoicePitch() { return MHelper.randRange(0.75F, 1.25F, random); } - + @Override - public boolean tryAttack(Entity target) { - boolean attack = super.tryAttack(target); + public boolean doHurtTarget(Entity target) { + boolean attack = super.doHurtTarget(target); if (attack && target instanceof LivingEntity) { LivingEntity living = (LivingEntity) target; - if (!(living.hasMobEffect(MobEffects.BLINDNESS))) { - living.addMobEffect(new MobEffectInstance(MobEffects.BLINDNESS, 60)); + if (!(living.hasEffect(MobEffects.BLINDNESS))) { + living.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 60)); } } return attack; } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, - SpawnReason spawnReason, BlockPos pos, Random random) { - if (HostileEntity.canSpawnInDark(type, world, spawnReason, pos, random)) { - Box box = new Box(pos).expand(16); - List entities = world.getEntitiesByClass(ShadowWalkerEntity.class, box, (entity) -> { - return true; - }); + + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + if (Monster.checkMonsterSpawnRules(type, world, spawnReason, pos, random)) { + AABB box = new AABB(pos).inflate(16); + List entities = world.getEntitiesOfClass(ShadowWalkerEntity.class, box, (entity) -> { return true; }); return entities.size() < 6; } return false; } - + private final class AttackGoal extends MeleeAttackGoal { private final ShadowWalkerEntity walker; private int ticks; public AttackGoal(ShadowWalkerEntity walker, double speed, boolean pauseWhenMobIdle) { - super(walker, speed, pauseWhenMobIdle); - this.walker = walker; - } + super(walker, speed, pauseWhenMobIdle); + this.walker = walker; + } public void start() { super.start(); @@ -129,16 +136,17 @@ public class ShadowWalkerEntity extends HostileEntity { public void stop() { super.stop(); - this.walker.setAttacking(false); + this.walker.setAggressive(false); } public void tick() { super.tick(); ++this.ticks; - if (this.ticks >= 5 && this.method_28348() < this.method_28349() / 2) { - this.walker.setAttacking(true); - } else { - this.walker.setAttacking(false); + if (this.ticks >= 5 && this.getTicksUntilNextAttack() < this.getAttackInterval() / 2) { + this.walker.setAggressive(true); + } + else { + this.walker.setAggressive(false); } } } diff --git a/src/main/java/ru/betterend/entity/SilkMothEntity.java b/src/main/java/ru/betterend/entity/SilkMothEntity.java index 967f496c..a88a78e8 100644 --- a/src/main/java/ru/betterend/entity/SilkMothEntity.java +++ b/src/main/java/ru/betterend/entity/SilkMothEntity.java @@ -5,46 +5,45 @@ import java.util.List; import java.util.Random; import org.jetbrains.annotations.Nullable; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.AgableMob; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.Flutterer; -import net.minecraft.world.entity.ItemEntity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.ai.TargetFinder; -import net.minecraft.world.entity.ai.control.FlightMoveControl; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.control.FlyingMoveControl; import net.minecraft.world.entity.ai.control.LookControl; -import net.minecraft.world.entity.ai.goal.AnimalMateGoal; +import net.minecraft.world.entity.ai.goal.BreedGoal; +import net.minecraft.world.entity.ai.goal.FloatGoal; import net.minecraft.world.entity.ai.goal.FollowParentGoal; import net.minecraft.world.entity.ai.goal.Goal; -import net.minecraft.world.entity.ai.goal.SwimGoal; -import net.minecraft.world.entity.ai.pathing.BirdNavigation; -import net.minecraft.world.entity.ai.pathing.EntityNavigation; -import net.minecraft.world.entity.ai.pathing.PathNodeType; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer; -import net.minecraft.world.entity.attribute.Attributes; -import net.minecraft.world.entity.damage.DamageSource; -import net.minecraft.world.entity.mob.MobEntity; -import net.minecraft.world.entity.passive.AnimalEntity; -import net.minecraft.world.entity.passive.PassiveEntity; +import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.util.RandomPos; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.FlyingAnimal; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.state.property.Properties; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.util.math.Vec3d; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.Heightmap.Type; -import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.level.Level; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.pathfinder.BlockPathTypes; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; import ru.betterend.BetterEnd; import ru.betterend.blocks.BlockProperties; import ru.betterend.entity.SilkMothEntity.MothLookControl; @@ -56,77 +55,80 @@ import ru.betterend.registry.EndItems; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; -public class SilkMothEntity extends AnimalEntity implements Flutterer { +public class SilkMothEntity extends Animal implements FlyingAnimal { private BlockPos hivePos; private BlockPos entrance; private Level hiveWorld; - + public SilkMothEntity(EntityType entityType, Level world) { super(entityType, world); - this.moveControl = new FlightMoveControl(this, 20, true); + this.moveControl = new FlyingMoveControl(this, 20, true); this.lookControl = new MothLookControl(this); - this.setPathfindingPenalty(PathNodeType.WATER, -1.0F); - this.setPathfindingPenalty(PathNodeType.DANGER_FIRE, -1.0F); - this.experiencePoints = 1; + this.setPathfindingMalus(BlockPathTypes.WATER, -1.0F); + this.setPathfindingMalus(BlockPathTypes.DANGER_FIRE, -1.0F); + this.xpReward = 1; } - - public static DefaultAttributeContainer.Builder createMobAttributes() { - return LivingEntity.createLivingAttributes().add(Attributes.MAX_HEALTH, 2.0D) - .add(Attributes.FOLLOW_RANGE, 16.0D).add(Attributes.FLYING_SPEED, 0.4D) + + public static AttributeSupplier.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(Attributes.MAX_HEALTH, 2.0D) + .add(Attributes.FOLLOW_RANGE, 16.0D) + .add(Attributes.FLYING_SPEED, 0.4D) .add(Attributes.MOVEMENT_SPEED, 0.1D); } - + public void setHive(Level world, BlockPos hive) { this.hivePos = hive; this.hiveWorld = world; } - + @Override - public void writeCustomDataToTag(CompoundTag tag) { + public void addAdditionalSaveData(CompoundTag tag) { if (hivePos != null) { - tag.put("HivePos", NbtHelper.fromBlockPos(hivePos)); + tag.put("HivePos", NbtUtils.writeBlockPos(hivePos)); tag.putString("HiveWorld", hiveWorld.dimension().location().toString()); } } - + @Override - public void readCustomDataFromTag(CompoundTag tag) { + public void readAdditionalSaveData(CompoundTag tag) { if (tag.contains("HivePos")) { - hivePos = NbtHelper.toBlockPos(tag.getCompound("HivePos")); + hivePos = NbtUtils.readBlockPos(tag.getCompound("HivePos")); ResourceLocation worldID = new ResourceLocation(tag.getString("HiveWorld")); try { - hiveWorld = world.getServer().getLevel(ResourceKey.of(Registry.DIMENSION, worldID)); - } catch (Exception e) { - BetterEnd.LOGGER.warning("Silk Moth Hive Level {} is missing!", worldID); + hiveWorld = level.getServer().getLevel(ResourceKey.create(Registry.DIMENSION_REGISTRY, worldID)); + } + catch (Exception e) { + BetterEnd.LOGGER.warning("Silk Moth Hive World {} is missing!", worldID); hivePos = null; } } } @Override - protected void initGoals() { - this.goalSelector.add(1, new ReturnToHiveGoal()); - this.goalSelector.add(2, new AnimalMateGoal(this, 1.0D)); - this.goalSelector.add(5, new FollowParentGoal(this, 1.25D)); - this.goalSelector.add(8, new WanderAroundGoal()); - this.goalSelector.add(9, new SwimGoal(this)); + protected void registerGoals() { + this.goalSelector.addGoal(1, new ReturnToHiveGoal()); + this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); + this.goalSelector.addGoal(5, new FollowParentGoal(this, 1.25D)); + this.goalSelector.addGoal(8, new WanderAroundGoal()); + this.goalSelector.addGoal(9, new FloatGoal(this)); } - + @Override - protected EntityNavigation createNavigation(Level world) { - BirdNavigation birdNavigation = new BirdNavigation(this, world) { - public boolean isValidPosition(BlockPos pos) { - BlockState state = this.world.getBlockState(pos); - return state.isAir() || !state.getMaterial().blocksMovement(); + protected PathNavigation createNavigation(Level world) { + FlyingPathNavigation birdNavigation = new FlyingPathNavigation(this, world) { + public boolean isStableDestination(BlockPos pos) { + BlockState state = this.level.getBlockState(pos); + return state.isAir() || !state.getMaterial().blocksMotion(); } public void tick() { super.tick(); } }; - birdNavigation.setCanPathThroughDoors(false); - birdNavigation.setCanSwim(false); - birdNavigation.setCanEnterOpenDoors(true); + birdNavigation.setCanOpenDoors(false); + birdNavigation.setCanFloat(false); + birdNavigation.setCanPassDoors(true); return birdNavigation; } @@ -136,36 +138,36 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer { } @Override - protected boolean hasWings() { + protected boolean makeFlySound() { return true; } @Override - public boolean handleFallDamage(float fallDistance, float damageMultiplier) { + public boolean causeFallDamage(float fallDistance, float damageMultiplier) { return false; } @Override - public boolean canClimb() { + public boolean isMovementNoisy() { return false; } @Override - public boolean hasNoGravity() { + public boolean isNoGravity() { return true; } @Override - public PassiveEntity createChild(ServerLevel world, PassiveEntity entity) { + public AgableMob getBreedOffspring(ServerLevel world, AgableMob entity) { return EndEntities.SILK_MOTH.create(world); } - + @Override - protected void dropLoot(DamageSource source, boolean causedByPlayer) { + protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) { int minCount = 0; int maxCount = 1; - if (causedByPlayer && this.attackingPlayer != null) { - int looting = EnchantmentHelper.getLooting(this.attackingPlayer); + if (causedByPlayer && this.lastHurtByPlayer != null) { + int looting = EnchantmentHelper.getMobLooting(this.lastHurtByPlayer); minCount += looting; maxCount += looting; if (maxCount > 2) { @@ -173,111 +175,104 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer { } } int count = minCount < maxCount ? MHelper.randRange(minCount, maxCount, random) : maxCount; - ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(EndItems.SILK_FIBER, count)); - this.world.spawnEntity(drop); + ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(EndItems.SILK_FIBER, count)); + this.level.addFreshEntity(drop); } - - public static boolean canSpawn(EntityType type, ServerLevelAccessor world, SpawnReason spawnReason, - BlockPos pos, Random random) { - int y = world.getChunk(pos).sampleHeightmap(Type.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); + + public static boolean canSpawn(EntityType type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + int y = world.getChunk(pos).getHeight(Types.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15); return y > 0 && pos.getY() >= y && notManyEntities(world, pos, 32, 1); } - + private static boolean notManyEntities(ServerLevelAccessor world, BlockPos pos, int radius, int maxCount) { - Box box = new Box(pos).expand(radius); - List list = world.getEntitiesByClass(SilkMothEntity.class, box, (entity) -> true); + AABB box = new AABB(pos).inflate(radius); + List list = world.getEntitiesOfClass(SilkMothEntity.class, box, (entity) -> true); return list.size() <= maxCount; } - + class MothLookControl extends LookControl { - MothLookControl(MobEntity entity) { + MothLookControl(Mob entity) { super(entity); } - protected boolean shouldStayHorizontal() { + protected boolean resetXRotOnTick() { return true; } } class WanderAroundGoal extends Goal { WanderAroundGoal() { - this.setControls(EnumSet.of(Goal.Control.MOVE)); + this.setFlags(EnumSet.of(Goal.Flag.MOVE)); } @Override - public boolean canStart() { - return SilkMothEntity.this.navigation.isIdle() && SilkMothEntity.this.random.nextInt(10) == 0; + public boolean canUse() { + return SilkMothEntity.this.navigation.isDone() && SilkMothEntity.this.random.nextInt(10) == 0; } @Override - public boolean shouldContinue() { - return SilkMothEntity.this.navigation.isFollowingPath(); + public boolean canContinueToUse() { + return SilkMothEntity.this.navigation.isInProgress(); } @Override public void start() { - Vec3d vec3d = null; - if (SilkMothEntity.this.hivePos != null && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.world) { - if (SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(), - SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) > 16) { - vec3d = SilkMothEntity.this.getPos().add(random.nextGaussian() * 2, 0, random.nextGaussian() * 2); + Vec3 vec3d = null; + if (SilkMothEntity.this.hivePos != null && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.level) { + if (SilkMothEntity.this.position().distanceToSqr(SilkMothEntity.this.hivePos.getX(), SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) > 16) { + vec3d = SilkMothEntity.this.position().add(random.nextGaussian() * 2, 0, random.nextGaussian() * 2); } } vec3d = vec3d == null ? this.getRandomLocation() : vec3d; if (vec3d != null) { try { - SilkMothEntity.this.navigation - .startMovingAlong(SilkMothEntity.this.navigation.findPathTo(new BlockPos(vec3d), 1), 1.0D); - } catch (Exception e) { + SilkMothEntity.this.navigation.moveTo(SilkMothEntity.this.navigation.createPath(new BlockPos(vec3d), 1), 1.0D); } + catch (Exception e) {} } } @Nullable - private Vec3d getRandomLocation() { - Vec3d vec3d3 = SilkMothEntity.this.getRotationVec(0.0F); - Vec3d vec3d4 = TargetFinder.findAirTarget(SilkMothEntity.this, 8, 7, vec3d3, 1.5707964F, 2, 1); - return vec3d4 != null ? vec3d4 - : TargetFinder.findGroundTarget(SilkMothEntity.this, 8, 4, -2, vec3d3, 1.5707963705062866D); + private Vec3 getRandomLocation() { + Vec3 vec3d3 = SilkMothEntity.this.getViewVector(0.0F); + Vec3 vec3d4 = RandomPos.getAboveLandPos(SilkMothEntity.this, 8, 7, vec3d3, 1.5707964F, 2, 1); + return vec3d4 != null ? vec3d4 : RandomPos.getAirPos(SilkMothEntity.this, 8, 4, -2, vec3d3, 1.5707963705062866D); } } - + class ReturnToHiveGoal extends Goal { ReturnToHiveGoal() { - this.setControls(EnumSet.of(Goal.Control.MOVE)); + this.setFlags(EnumSet.of(Goal.Flag.MOVE)); } - + @Override - public boolean canStart() { - return SilkMothEntity.this.hivePos != null && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.world - && SilkMothEntity.this.navigation.isIdle() && SilkMothEntity.this.random.nextInt(16) == 0 - && SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(), - SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) < 64; + public boolean canUse() { + return SilkMothEntity.this.hivePos != null + && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.level + && SilkMothEntity.this.navigation.isDone() + && SilkMothEntity.this.random.nextInt(16) == 0 + && SilkMothEntity.this.position().distanceToSqr(SilkMothEntity.this.hivePos.getX(), SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) < 64; } - + @Override - public boolean shouldContinue() { - return SilkMothEntity.this.navigation.isFollowingPath() && world.getBlockState(entrance).isAir() - && (world.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_NEST) - || world.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_HIVE)); + public boolean canContinueToUse() { + return SilkMothEntity.this.navigation.isInProgress() && level.getBlockState(entrance).isAir() && (level.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_NEST) || level.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_HIVE)); } - + @Override public void start() { - BlockState state = SilkMothEntity.this.world.getBlockState(SilkMothEntity.this.hivePos); + BlockState state = SilkMothEntity.this.level.getBlockState(SilkMothEntity.this.hivePos); if (!state.is(EndBlocks.SILK_MOTH_NEST) && !state.is(EndBlocks.SILK_MOTH_HIVE)) { SilkMothEntity.this.hivePos = null; return; } try { - SilkMothEntity.this.entrance = SilkMothEntity.this.hivePos - .offset(state.getValue(Properties.HORIZONTAL_FACING)); - SilkMothEntity.this.navigation.startMovingAlong(SilkMothEntity.this.navigation.findPathTo(entrance, 1), - 1.0D); - } catch (Exception e) { + SilkMothEntity.this.entrance = SilkMothEntity.this.hivePos.relative(state.getValue(BlockStateProperties.HORIZONTAL_FACING)); + SilkMothEntity.this.navigation.moveTo(SilkMothEntity.this.navigation.createPath(entrance, 1), 1.0D); } + catch (Exception e) {} } - + @Override public void tick() { super.tick(); @@ -288,7 +283,7 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer { double dy = Math.abs(SilkMothEntity.this.entrance.getY() - SilkMothEntity.this.getY()); double dz = Math.abs(SilkMothEntity.this.entrance.getZ() - SilkMothEntity.this.getZ()); if (dx + dy + dz < 1) { - BlockState state = SilkMothEntity.this.world.getBlockState(hivePos); + BlockState state = SilkMothEntity.this.level.getBlockState(hivePos); if (state.is(EndBlocks.SILK_MOTH_NEST) || state.is(EndBlocks.SILK_MOTH_HIVE)) { int fullness = state.getValue(BlockProperties.FULLNESS); boolean isHive = state.is(EndBlocks.SILK_MOTH_HIVE); @@ -297,13 +292,12 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer { if (fullness > 3) { fullness = 3; } - BlocksHelper.setWithUpdate(SilkMothEntity.this.hiveWorld, SilkMothEntity.this.hivePos, - state.with(BlockProperties.FULLNESS, fullness)); + BlocksHelper.setWithUpdate(SilkMothEntity.this.hiveWorld, SilkMothEntity.this.hivePos, state.setValue(BlockProperties.FULLNESS, fullness)); } - SilkMothEntity.this.world.playLocalSound(null, SilkMothEntity.this.entrance, - SoundEvents.BLOCK_BEEHIVE_ENTER, SoundSource.BLOCKS, 1, 1); + SilkMothEntity.this.level.playSound(null, SilkMothEntity.this.entrance, SoundEvents.BEEHIVE_ENTER, SoundSource.BLOCKS, 1, 1); SilkMothEntity.this.remove(); - } else { + } + else { SilkMothEntity.this.hivePos = null; } } diff --git a/src/main/java/ru/betterend/entity/model/BlockBenchModel.java b/src/main/java/ru/betterend/entity/model/BlockBenchModel.java index 052ade1b..de949560 100644 --- a/src/main/java/ru/betterend/entity/model/BlockBenchModel.java +++ b/src/main/java/ru/betterend/entity/model/BlockBenchModel.java @@ -1,25 +1,24 @@ package ru.betterend.entity.model; import java.util.function.Function; - -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.world.entity.Entity; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; public abstract class BlockBenchModel extends EntityModel { public BlockBenchModel() { super(); } - - public BlockBenchModel(Function function) { + + public BlockBenchModel(Function function) { super(function); } - + protected void setRotationAngle(ModelPart modelRenderer, float x, float y, float z) { - modelRenderer.pitch = x; - modelRenderer.yaw = y; - modelRenderer.roll = z; + modelRenderer.xRot = x; + modelRenderer.yRot = y; + modelRenderer.zRot = z; } } diff --git a/src/main/java/ru/betterend/entity/model/CubozoaEntityModel.java b/src/main/java/ru/betterend/entity/model/CubozoaEntityModel.java index 97187ee1..68d9021b 100644 --- a/src/main/java/ru/betterend/entity/model/CubozoaEntityModel.java +++ b/src/main/java/ru/betterend/entity/model/CubozoaEntityModel.java @@ -1,9 +1,9 @@ package ru.betterend.entity.model; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Mth; import ru.betterend.entity.CubozoaEntity; @@ -22,81 +22,82 @@ public class CubozoaEntityModel extends BlockBenchModel { private float scaleXZ; public CubozoaEntityModel() { - super(RenderLayer::getEntityTranslucent); - - textureWidth = 48; - textureHeight = 48; - + super(RenderType::entityTranslucent); + + texWidth = 48; + texHeight = 48; + model = new ModelPart(this); - model.setPivot(0.0F, 24.0F, 0.0F); - model.setTextureOffset(0, 17).addCuboid(-2.0F, -12.5F, -2.0F, 4.0F, 4.0F, 4.0F, 0.0F); + model.setPos(0.0F, 24.0F, 0.0F); + model.texOffs(0, 17).addBox(-2.0F, -12.5F, -2.0F, 4.0F, 4.0F, 4.0F, 0.0F); main_cube_r1 = new ModelPart(this); - main_cube_r1.setPivot(0.0F, -14.0F, 0.0F); + main_cube_r1.setPos(0.0F, -14.0F, 0.0F); model.addChild(main_cube_r1); setRotationAngle(main_cube_r1, 0.0F, 0.0F, -3.1416F); - main_cube_r1.setTextureOffset(0, 0).addCuboid(-5.0F, -7.0F, -5.0F, 10.0F, 7.0F, 10.0F, 0.0F); + main_cube_r1.texOffs(0, 0).addBox(-5.0F, -7.0F, -5.0F, 10.0F, 7.0F, 10.0F, 0.0F); tentacle_center_1 = new ModelPart(this); - tentacle_center_1.setPivot(0.0F, 0.0F, 0.0F); + tentacle_center_1.setPos(0.0F, 0.0F, 0.0F); model.addChild(tentacle_center_1); + tentacle_1 = new ModelPart(this); - tentacle_1.setPivot(0.0F, -7.0F, 4.5F); + tentacle_1.setPos(0.0F, -7.0F, 4.5F); tentacle_center_1.addChild(tentacle_1); - tentacle_1.setTextureOffset(16, 17).addCuboid(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); + tentacle_1.texOffs(16, 17).addBox(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); tentacle_center_2 = new ModelPart(this); - tentacle_center_2.setPivot(0.0F, 0.0F, 0.0F); + tentacle_center_2.setPos(0.0F, 0.0F, 0.0F); model.addChild(tentacle_center_2); setRotationAngle(tentacle_center_2, 0.0F, -1.5708F, 0.0F); + tentacle_2 = new ModelPart(this); - tentacle_2.setPivot(0.0F, -7.0F, 4.5F); + tentacle_2.setPos(0.0F, -7.0F, 4.5F); tentacle_center_2.addChild(tentacle_2); - tentacle_2.setTextureOffset(16, 17).addCuboid(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); + tentacle_2.texOffs(16, 17).addBox(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); tentacle_center_3 = new ModelPart(this); - tentacle_center_3.setPivot(0.0F, 0.0F, 0.0F); + tentacle_center_3.setPos(0.0F, 0.0F, 0.0F); model.addChild(tentacle_center_3); setRotationAngle(tentacle_center_3, 0.0F, 3.1416F, 0.0F); + tentacle_3 = new ModelPart(this); - tentacle_3.setPivot(0.0F, -7.0F, 4.5F); + tentacle_3.setPos(0.0F, -7.0F, 4.5F); tentacle_center_3.addChild(tentacle_3); - tentacle_3.setTextureOffset(16, 17).addCuboid(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); + tentacle_3.texOffs(16, 17).addBox(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); tentacle_center_4 = new ModelPart(this); - tentacle_center_4.setPivot(0.0F, 0.0F, 0.0F); + tentacle_center_4.setPos(0.0F, 0.0F, 0.0F); model.addChild(tentacle_center_4); setRotationAngle(tentacle_center_4, 0.0F, 1.5708F, 0.0F); + tentacle_4 = new ModelPart(this); - tentacle_4.setPivot(0.0F, -7.0F, 4.5F); + tentacle_4.setPos(0.0F, -7.0F, 4.5F); tentacle_center_4.addChild(tentacle_4); - tentacle_4.setTextureOffset(16, 17).addCuboid(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); + tentacle_4.texOffs(16, 17).addBox(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F); } - + @Override - public void setAngles(CubozoaEntity entity, float limbAngle, float limbDistance, float animationProgress, - float headYaw, float headPitch) { + public void setupAnim(CubozoaEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { float sin = Mth.sin(animationProgress * 0.13F); scaleY = sin * 0.1F + 0.9F; scaleXZ = Mth.sin(animationProgress * 0.13F + 3.14F) * 0.1F + 0.9F; - - tentacle_1.pitch = sin * 0.15F; - tentacle_2.pitch = sin * 0.15F; - tentacle_3.pitch = sin * 0.15F; - tentacle_4.pitch = sin * 0.15F; + + tentacle_1.xRot = sin * 0.15F; + tentacle_2.xRot = sin * 0.15F; + tentacle_3.xRot = sin * 0.15F; + tentacle_4.xRot = sin * 0.15F; } @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, - float blue, float alpha) { - matrices.push(); + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + matrices.pushPose(); matrices.scale(scaleXZ, scaleY, scaleXZ); model.render(matrices, vertices, light, overlay); - matrices.pop(); + matrices.popPose(); } - } diff --git a/src/main/java/ru/betterend/entity/model/DragonflyEntityModel.java b/src/main/java/ru/betterend/entity/model/DragonflyEntityModel.java index 47acf4a6..08b04474 100644 --- a/src/main/java/ru/betterend/entity/model/DragonflyEntityModel.java +++ b/src/main/java/ru/betterend/entity/model/DragonflyEntityModel.java @@ -1,9 +1,9 @@ package ru.betterend.entity.model; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import ru.betterend.entity.DragonflyEntity; public class DragonflyEntityModel extends BlockBenchModel { @@ -19,86 +19,87 @@ public class DragonflyEntityModel extends BlockBenchModel { private final ModelPart legs_2; public DragonflyEntityModel() { - super(RenderLayer::getEntityCutout); - - textureWidth = 64; - textureHeight = 64; + super(RenderType::entityCutout); + + texWidth = 64; + texHeight = 64; model = new ModelPart(this); - model.setPivot(2.0F, 21.5F, -4.0F); - model.setTextureOffset(0, 0).addCuboid(-4.0F, -4.0F, 0.0F, 4.0F, 4.0F, 9.0F, 0.0F); + model.setPos(2.0F, 21.5F, -4.0F); + model.texOffs(0, 0).addBox(-4.0F, -4.0F, 0.0F, 4.0F, 4.0F, 9.0F, 0.0F); head = new ModelPart(this); - head.setPivot(-2.0F, -2.0F, 0.0F); + head.setPos(-2.0F, -2.0F, 0.0F); model.addChild(head); setRotationAngle(head, 0.3491F, 0.0F, 0.0F); - head.setTextureOffset(17, 0).addCuboid(-1.5F, -1.5F, -2.5F, 3.0F, 3.0F, 3.0F, 0.0F); + head.texOffs(17, 0).addBox(-1.5F, -1.5F, -2.5F, 3.0F, 3.0F, 3.0F, 0.0F); tail = new ModelPart(this); - tail.setPivot(-2.0F, -2.0F, 9.0F); + tail.setPos(-2.0F, -2.0F, 9.0F); model.addChild(tail); - tail.setTextureOffset(26, 0).addCuboid(-1.5F, -1.5F, 0.0F, 3.0F, 3.0F, 7.0F, 0.0F); + tail.texOffs(26, 0).addBox(-1.5F, -1.5F, 0.0F, 3.0F, 3.0F, 7.0F, 0.0F); tail_2 = new ModelPart(this); - tail_2.setPivot(0.0F, 0.0F, 7.0F); + tail_2.setPos(0.0F, 0.0F, 7.0F); tail.addChild(tail_2); - tail_2.setTextureOffset(36, 0).addCuboid(-1.0F, -1.0F, 0.0F, 2.0F, 2.0F, 10.0F, 0.0F); + tail_2.texOffs(36, 0).addBox(-1.0F, -1.0F, 0.0F, 2.0F, 2.0F, 10.0F, 0.0F); wing_1 = new ModelPart(this); - wing_1.setPivot(-2.0F, -4.0F, 4.0F); + wing_1.setPos(-2.0F, -4.0F, 4.0F); model.addChild(wing_1); - wing_1.setTextureOffset(0, 13).addCuboid(-15.0F, 0.0F, -3.0F, 15.0F, 0.0F, 4.0F, 0.0F); + wing_1.texOffs(0, 13).addBox(-15.0F, 0.0F, -3.0F, 15.0F, 0.0F, 4.0F, 0.0F); wing_2 = new ModelPart(this); - wing_2.setPivot(-2.0F, -4.0F, 4.0F); + wing_2.setPos(-2.0F, -4.0F, 4.0F); model.addChild(wing_2); wing_2.mirror = true; - wing_2.setTextureOffset(0, 13).addCuboid(0.0F, 0.0F, -3.0F, 15.0F, 0.0F, 4.0F, 0.0F); + wing_2.texOffs(0, 13).addBox(0.0F, 0.0F, -3.0F, 15.0F, 0.0F, 4.0F, 0.0F); wing_3 = new ModelPart(this); - wing_3.setPivot(-2.0F, -4.0F, 8.0F); + wing_3.setPos(-2.0F, -4.0F, 8.0F); model.addChild(wing_3); - wing_3.setTextureOffset(4, 17).addCuboid(-12.0F, 0.0F, -2.5F, 12.0F, 0.0F, 3.0F, 0.0F); + wing_3.texOffs(4, 17).addBox(-12.0F, 0.0F, -2.5F, 12.0F, 0.0F, 3.0F, 0.0F); wing_4 = new ModelPart(this); - wing_4.setPivot(-2.0F, -4.0F, 8.0F); + wing_4.setPos(-2.0F, -4.0F, 8.0F); model.addChild(wing_4); wing_4.mirror = true; - wing_4.setTextureOffset(4, 17).addCuboid(0.0F, 0.0F, -2.5F, 12.0F, 0.0F, 3.0F, 0.0F); + wing_4.texOffs(4, 17).addBox(0.0F, 0.0F, -2.5F, 12.0F, 0.0F, 3.0F, 0.0F); legs_1 = new ModelPart(this); - legs_1.setPivot(-1.0F, 0.0F, 1.0F); + legs_1.setPos(-1.0F, 0.0F, 1.0F); model.addChild(legs_1); setRotationAngle(legs_1, 0.0F, 0.0F, -0.5236F); - legs_1.setTextureOffset(50, 1).addCuboid(0.0F, 0.0F, 0.0F, 0.0F, 3.0F, 6.0F, 0.0F); + legs_1.texOffs(50, 1).addBox(0.0F, 0.0F, 0.0F, 0.0F, 3.0F, 6.0F, 0.0F); legs_2 = new ModelPart(this); - legs_2.setPivot(-3.0F, 0.0F, 1.0F); + legs_2.setPos(-3.0F, 0.0F, 1.0F); model.addChild(legs_2); setRotationAngle(legs_2, 0.0F, 0.0F, 0.5236F); - legs_2.setTextureOffset(50, 1).addCuboid(0.0F, 0.0F, 0.0F, 0.0F, 3.0F, 6.0F, 0.0F); + legs_2.texOffs(50, 1).addBox(0.0F, 0.0F, 0.0F, 0.0F, 3.0F, 6.0F, 0.0F); } - @Override - public void setAngles(DragonflyEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { + public void setupAnim(DragonflyEntity entity, float limbAngle, float limbDistance, float animationProgress, + float headYaw, float headPitch) { float progress = animationProgress * 2F; - - wing_1.roll = 0.3491F + (float) Math.sin(progress) * 0.3491F; - wing_2.roll = -wing_1.roll; - - wing_3.roll = 0.3491F + (float) Math.cos(progress) * 0.3491F; - wing_4.roll = -wing_3.roll; - + + wing_1.zRot = 0.3491F + (float) Math.sin(progress) * 0.3491F; + wing_2.zRot = -wing_1.zRot; + + wing_3.zRot = 0.3491F + (float) Math.cos(progress) * 0.3491F; + wing_4.zRot = -wing_3.zRot; + progress = animationProgress * 0.05F; - - head.pitch = 0.3491F + (float) Math.sin(progress * 0.7F) * 0.1F; - tail.pitch = (float) Math.cos(progress) * 0.05F - 0.05F; - tail_2.pitch = -tail.pitch * 1.5F; + + head.xRot = 0.3491F + (float) Math.sin(progress * 0.7F) * 0.1F; + tail.xRot = (float) Math.cos(progress) * 0.05F - 0.05F; + tail_2.xRot = -tail.xRot * 1.5F; } @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, + float green, float blue, float alpha) { model.render(matrices, vertices, light, overlay); } } diff --git a/src/main/java/ru/betterend/entity/model/EndFishEntityModel.java b/src/main/java/ru/betterend/entity/model/EndFishEntityModel.java index c2a75cec..20357336 100644 --- a/src/main/java/ru/betterend/entity/model/EndFishEntityModel.java +++ b/src/main/java/ru/betterend/entity/model/EndFishEntityModel.java @@ -1,9 +1,9 @@ package ru.betterend.entity.model; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import ru.betterend.entity.EndFishEntity; public class EndFishEntityModel extends BlockBenchModel { @@ -15,60 +15,61 @@ public class EndFishEntityModel extends BlockBenchModel { private final ModelPart fin_left; public EndFishEntityModel() { - super(RenderLayer::getEntityCutout); - - textureWidth = 32; - textureHeight = 32; + super(RenderType::entityCutout); + + texWidth = 32; + texHeight = 32; model = new ModelPart(this); - model.setPivot(0.0F, 20.0F, 0.0F); - model.setTextureOffset(0, 0).addCuboid(-1.0F, -2.0F, -4.0F, 2.0F, 4.0F, 8.0F, 0.0F); + model.setPos(0.0F, 20.0F, 0.0F); + model.texOffs(0, 0).addBox(-1.0F, -2.0F, -4.0F, 2.0F, 4.0F, 8.0F, 0.0F); fin_top = new ModelPart(this); - fin_top.setPivot(0.0F, -2.0F, -4.0F); + fin_top.setPos(0.0F, -2.0F, -4.0F); model.addChild(fin_top); setRotationAngle(fin_top, -0.6981F, 0.0F, 0.0F); - fin_top.setTextureOffset(0, 6).addCuboid(0.0F, -8.0F, 0.0F, 0.0F, 8.0F, 6.0F, 0.0F); + fin_top.texOffs(0, 6).addBox(0.0F, -8.0F, 0.0F, 0.0F, 8.0F, 6.0F, 0.0F); fin_bottom = new ModelPart(this); - fin_bottom.setPivot(0.0F, 2.0F, -4.0F); + fin_bottom.setPos(0.0F, 2.0F, -4.0F); model.addChild(fin_bottom); setRotationAngle(fin_bottom, 0.6981F, 0.0F, 0.0F); - fin_bottom.setTextureOffset(0, 6).addCuboid(0.0F, 0.0F, 0.0F, 0.0F, 8.0F, 6.0F, 0.0F); + fin_bottom.texOffs(0, 6).addBox(0.0F, 0.0F, 0.0F, 0.0F, 8.0F, 6.0F, 0.0F); flipper = new ModelPart(this); - flipper.setPivot(0.0F, 0.0F, 2.0F); + flipper.setPos(0.0F, 0.0F, 2.0F); model.addChild(flipper); setRotationAngle(flipper, -0.7854F, 0.0F, 0.0F); - flipper.setTextureOffset(0, 15).addCuboid(0.0F, -5.0F, 0.0F, 0.0F, 5.0F, 5.0F, 0.0F); + flipper.texOffs(0, 15).addBox(0.0F, -5.0F, 0.0F, 0.0F, 5.0F, 5.0F, 0.0F); fin_right = new ModelPart(this); - fin_right.setPivot(-1.0F, 0.0F, -1.0F); + fin_right.setPos(-1.0F, 0.0F, -1.0F); model.addChild(fin_right); setRotationAngle(fin_right, 1.5708F, 0.7854F, 0.0F); - fin_right.setTextureOffset(0, 25).addCuboid(-3.7071F, 0.7071F, -1.5F, 3.0F, 0.0F, 3.0F, 0.0F); + fin_right.texOffs(0, 25).addBox(-3.7071F, 0.7071F, -1.5F, 3.0F, 0.0F, 3.0F, 0.0F); fin_left = new ModelPart(this); - fin_left.setPivot(1.0F, 0.0F, -1.0F); + fin_left.setPos(1.0F, 0.0F, -1.0F); model.addChild(fin_left); setRotationAngle(fin_left, 1.5708F, -0.7854F, 0.0F); - fin_left.setTextureOffset(0, 25).addCuboid(0.7071F, 0.7071F, -1.5F, 3.0F, 0.0F, 3.0F, 0.0F, true); + fin_left.texOffs(0, 25).addBox(0.7071F, 0.7071F, -1.5F, 3.0F, 0.0F, 3.0F, 0.0F, true); } - @Override - public void setAngles(EndFishEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { + public void setupAnim(EndFishEntity entity, float limbAngle, float limbDistance, float animationProgress, + float headYaw, float headPitch) { float s1 = (float) Math.sin(animationProgress * 0.1); float s2 = (float) Math.sin(animationProgress * 0.05); - flipper.yaw = s1 * 0.3F; - fin_top.pitch = s2 * 0.02F - 0.6981F; - fin_bottom.pitch = 0.6981F - s2 * 0.02F; - fin_left.yaw = s1 * 0.3F - 0.7854F; - fin_right.yaw = 0.7854F - s1 * 0.3F; + flipper.yRot = s1 * 0.3F; + fin_top.xRot = s2 * 0.02F - 0.6981F; + fin_bottom.xRot = 0.6981F - s2 * 0.02F; + fin_left.yRot = s1 * 0.3F - 0.7854F; + fin_right.yRot = 0.7854F - s1 * 0.3F; } @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) { + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, + float green, float blue, float alpha) { model.render(matrices, vertices, light, overlay); } } diff --git a/src/main/java/ru/betterend/entity/model/EndSlimeEntityModel.java b/src/main/java/ru/betterend/entity/model/EndSlimeEntityModel.java index 6725e790..2f07e710 100644 --- a/src/main/java/ru/betterend/entity/model/EndSlimeEntityModel.java +++ b/src/main/java/ru/betterend/entity/model/EndSlimeEntityModel.java @@ -1,26 +1,25 @@ package ru.betterend.entity.model; import com.google.common.collect.ImmutableList; - -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.model.CompositeEntityModel; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.ListModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import ru.betterend.entity.EndSlimeEntity; import ru.betterend.util.MHelper; -public class EndSlimeEntityModel extends CompositeEntityModel { +public class EndSlimeEntityModel extends ListModel { private final ModelPart flower; private final ModelPart crop; private final ModelPart innerCube; private final ModelPart rightEye; private final ModelPart leftEye; private final ModelPart mouth; - + public EndSlimeEntityModel(boolean onlyShell) { - super(RenderLayer::getEntityCutout); - + super(RenderType::entityCutout); + this.innerCube = new ModelPart(this, 0, 16); this.rightEye = new ModelPart(this, 32, 0); this.leftEye = new ModelPart(this, 32, 4); @@ -29,54 +28,55 @@ public class EndSlimeEntityModel extends CompositeEnti this.crop = new ModelPart(this); if (onlyShell) { - this.innerCube.setTextureOffset(0, 0); - this.innerCube.addCuboid(-4.0F, 16.0F, -4.0F, 8.0F, 8.0F, 8.0F); - } - else { - this.innerCube.addCuboid(-3.0F, 17.0F, -3.0F, 6.0F, 6.0F, 6.0F); - this.rightEye.addCuboid(-3.25F, 18.0F, -3.5F, 2.0F, 2.0F, 2.0F); - this.leftEye.addCuboid(1.25F, 18.0F, -3.5F, 2.0F, 2.0F, 2.0F); - this.mouth.addCuboid(0.0F, 21.0F, -3.5F, 1.0F, 1.0F, 1.0F); - + this.innerCube.texOffs(0, 0); + this.innerCube.addBox(-4.0F, 16.0F, -4.0F, 8.0F, 8.0F, 8.0F); + } else { + this.innerCube.addBox(-3.0F, 17.0F, -3.0F, 6.0F, 6.0F, 6.0F); + this.rightEye.addBox(-3.25F, 18.0F, -3.5F, 2.0F, 2.0F, 2.0F); + this.leftEye.addBox(1.25F, 18.0F, -3.5F, 2.0F, 2.0F, 2.0F); + this.mouth.addBox(0.0F, 21.0F, -3.5F, 1.0F, 1.0F, 1.0F); + for (int i = 0; i < 4; i++) { ModelPart petalRot = new ModelPart(this); - petalRot.yaw = MHelper.degreesToRadians(i * 45F); - + petalRot.yRot = MHelper.degreesToRadians(i * 45F); + ModelPart petal = new ModelPart(this, 40, 0); - petal.setPivot(-4, 8, 0); - petal.addCuboid(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 0.0F, 0.0F); - + petal.setPos(-4, 8, 0); + petal.addBox(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 0.0F, 0.0F); + this.flower.addChild(petalRot); petalRot.addChild(petal); } - + for (int i = 0; i < 2; i++) { ModelPart petalRot = new ModelPart(this); - petalRot.yaw = MHelper.degreesToRadians(i * 90F + 45F); - + petalRot.yRot = MHelper.degreesToRadians(i * 90F + 45F); + ModelPart petal = new ModelPart(this, 40, 0); - petal.setPivot(-4, 8, 0); - petal.addCuboid(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 0.0F, 0.0F); - + petal.setPos(-4, 8, 0); + petal.addBox(0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 0.0F, 0.0F); + this.crop.addChild(petalRot); petalRot.addChild(petal); } } } - + @Override - public void setAngles(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {} - - public void renderFlower(MatrixStack matrices, VertexConsumer vertices, int light, int overlay) { + public void setupAnim(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, + float headPitch) { + } + + public void renderFlower(PoseStack matrices, VertexConsumer vertices, int light, int overlay) { flower.render(matrices, vertices, light, overlay); } - - public void renderCrop(MatrixStack matrices, VertexConsumer vertices, int light, int overlay) { + + public void renderCrop(PoseStack matrices, VertexConsumer vertices, int light, int overlay) { crop.render(matrices, vertices, light, overlay); } @Override - public Iterable getParts() { + public Iterable parts() { return ImmutableList.of(this.innerCube, this.rightEye, this.leftEye, this.mouth); } } diff --git a/src/main/java/ru/betterend/entity/model/SilkMothEntityModel.java b/src/main/java/ru/betterend/entity/model/SilkMothEntityModel.java index 21579703..55766a70 100644 --- a/src/main/java/ru/betterend/entity/model/SilkMothEntityModel.java +++ b/src/main/java/ru/betterend/entity/model/SilkMothEntityModel.java @@ -1,9 +1,9 @@ package ru.betterend.entity.model; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Mth; import ru.betterend.entity.SilkMothEntity; @@ -25,110 +25,110 @@ public class SilkMothEntityModel extends BlockBenchModel { private final ModelPart abdomen_r1; public SilkMothEntityModel() { - super(RenderLayer::getEntityCutout); + super(RenderType::entityCutout); - textureWidth = 64; - textureHeight = 64; + texWidth = 64; + texHeight = 64; legsL = new ModelPart(this); - legsL.setPivot(1.5F, 19.9F, -0.45F); + legsL.setPos(1.5F, 19.9F, -0.45F); setRotationAngle(legsL, 0.0F, 0.0F, 0.6981F); cube_r1 = new ModelPart(this); - cube_r1.setPivot(0.0F, 0.0F, -1.0F); + cube_r1.setPos(0.0F, 0.0F, -1.0F); legsL.addChild(cube_r1); setRotationAngle(cube_r1, 0.0F, 0.2182F, 0.3927F); - cube_r1.setTextureOffset(0, 13).addCuboid(0.0216F, 0.0F, -0.5976F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r1.texOffs(0, 13).addBox(0.0216F, 0.0F, -0.5976F, 3.0F, 0.0F, 1.0F, 0.0F); cube_r2 = new ModelPart(this); - cube_r2.setPivot(0.5F, 0.1F, -0.05F); + cube_r2.setPos(0.5F, 0.1F, -0.05F); legsL.addChild(cube_r2); setRotationAngle(cube_r2, 0.0F, 0.0F, 0.3927F); - cube_r2.setTextureOffset(0, 15).addCuboid(0.0F, 0.0F, -0.6F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r2.texOffs(0, 15).addBox(0.0F, 0.0F, -0.6F, 3.0F, 0.0F, 1.0F, 0.0F); cube_r3 = new ModelPart(this); - cube_r3.setPivot(0.0F, 0.0F, 0.9F); + cube_r3.setPos(0.0F, 0.0F, 0.9F); legsL.addChild(cube_r3); setRotationAngle(cube_r3, 0.0F, -0.2182F, 0.3927F); - cube_r3.setTextureOffset(0, 14).addCuboid(0.0F, 0.0F, -0.5F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r3.texOffs(0, 14).addBox(0.0F, 0.0F, -0.5F, 3.0F, 0.0F, 1.0F, 0.0F); legsR = new ModelPart(this); - legsR.setPivot(-1.5F, 19.9F, -0.55F); + legsR.setPos(-1.5F, 19.9F, -0.55F); setRotationAngle(legsR, 0.0F, 3.1416F, -0.6545F); cube_r4 = new ModelPart(this); - cube_r4.setPivot(0.0F, 0.0F, -1.0F); + cube_r4.setPos(0.0F, 0.0F, -1.0F); legsR.addChild(cube_r4); setRotationAngle(cube_r4, 0.0F, 0.2182F, 0.3927F); - cube_r4.setTextureOffset(0, 10).addCuboid(0.0F, 0.0F, -0.5F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r4.texOffs(0, 10).addBox(0.0F, 0.0F, -0.5F, 3.0F, 0.0F, 1.0F, 0.0F); cube_r5 = new ModelPart(this); - cube_r5.setPivot(0.5F, 0.1F, -0.05F); + cube_r5.setPos(0.5F, 0.1F, -0.05F); legsR.addChild(cube_r5); setRotationAngle(cube_r5, 0.0F, 0.0F, 0.3927F); - cube_r5.setTextureOffset(0, 11).addCuboid(0.0F, 0.0F, -0.4F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r5.texOffs(0, 11).addBox(0.0F, 0.0F, -0.4F, 3.0F, 0.0F, 1.0F, 0.0F); cube_r6 = new ModelPart(this); - cube_r6.setPivot(0.0F, 0.0F, 0.9F); + cube_r6.setPos(0.0F, 0.0F, 0.9F); legsR.addChild(cube_r6); setRotationAngle(cube_r6, 0.0F, -0.2182F, 0.3927F); - cube_r6.setTextureOffset(0, 12).addCuboid(0.0216F, 0.0F, -0.4024F, 3.0F, 0.0F, 1.0F, 0.0F); + cube_r6.texOffs(0, 12).addBox(0.0216F, 0.0F, -0.4024F, 3.0F, 0.0F, 1.0F, 0.0F); head_pivot = new ModelPart(this); - head_pivot.setPivot(0.0F, 18.0F, -3.0F); - head_pivot.setTextureOffset(15, 10).addCuboid(-1.5F, -1.5F, -2.0F, 3.0F, 3.0F, 3.0F, 0.0F); + head_pivot.setPos(0.0F, 18.0F, -3.0F); + head_pivot.texOffs(15, 10).addBox(-1.5F, -1.5F, -2.0F, 3.0F, 3.0F, 3.0F, 0.0F); tendril_r_r1 = new ModelPart(this); - tendril_r_r1.setPivot(1.0F, -1.15F, -1.0F); + tendril_r_r1.setPos(1.0F, -1.15F, -1.0F); head_pivot.addChild(tendril_r_r1); setRotationAngle(tendril_r_r1, 0.0F, 0.0F, 0.3927F); - tendril_r_r1.setTextureOffset(23, 0).addCuboid(-1.5F, -5.0F, 0.0F, 3.0F, 5.0F, 0.0F, 0.0F, true); + tendril_r_r1.texOffs(23, 0).addBox(-1.5F, -5.0F, 0.0F, 3.0F, 5.0F, 0.0F, 0.0F, true); tendril_r_r2 = new ModelPart(this); - tendril_r_r2.setPivot(-1.0F, -1.15F, -1.0F); + tendril_r_r2.setPos(-1.0F, -1.15F, -1.0F); head_pivot.addChild(tendril_r_r2); setRotationAngle(tendril_r_r2, 0.0F, 0.0F, -0.3927F); - tendril_r_r2.setTextureOffset(23, 0).addCuboid(-1.5F, -5.0F, 0.0F, 3.0F, 5.0F, 0.0F, 0.0F); + tendril_r_r2.texOffs(23, 0).addBox(-1.5F, -5.0F, 0.0F, 3.0F, 5.0F, 0.0F, 0.0F); bb_main = new ModelPart(this); - bb_main.setPivot(0.0F, 24.0F, 0.0F); - bb_main.setTextureOffset(19, 19).addCuboid(-2.5F, -8.5F, -3.0F, 5.0F, 5.0F, 3.0F, 0.0F); + bb_main.setPos(0.0F, 24.0F, 0.0F); + bb_main.texOffs(19, 19).addBox(-2.5F, -8.5F, -3.0F, 5.0F, 5.0F, 3.0F, 0.0F); wingR_r1 = new ModelPart(this); - wingR_r1.setPivot(-1.5F, -6.5F, 0.5F); + wingR_r1.setPos(-1.5F, -6.5F, 0.5F); bb_main.addChild(wingR_r1); setRotationAngle(wingR_r1, 0.0F, 0.0F, 0.3927F); - wingR_r1.setTextureOffset(0, 5).addCuboid(-7.0F, 0.0F, -3.0F, 9.0F, 0.0F, 5.0F, 0.0F, true); + wingR_r1.texOffs(0, 5).addBox(-7.0F, 0.0F, -3.0F, 9.0F, 0.0F, 5.0F, 0.0F, true); wingL_r1 = new ModelPart(this); - wingL_r1.setPivot(1.5F, -6.5F, 0.5F); + wingL_r1.setPos(1.5F, -6.5F, 0.5F); bb_main.addChild(wingL_r1); setRotationAngle(wingL_r1, 0.0F, 0.0F, -0.3927F); - wingL_r1.setTextureOffset(0, 5).addCuboid(-2.0F, 0.0F, -3.0F, 9.0F, 0.0F, 5.0F, 0.0F); + wingL_r1.texOffs(0, 5).addBox(-2.0F, 0.0F, -3.0F, 9.0F, 0.0F, 5.0F, 0.0F); abdomen_r1 = new ModelPart(this); - abdomen_r1.setPivot(1.0F, -3.9F, 0.0F); + abdomen_r1.setPos(1.0F, -3.9F, 0.0F); bb_main.addChild(abdomen_r1); setRotationAngle(abdomen_r1, -0.3927F, 0.0F, 0.0F); - abdomen_r1.setTextureOffset(0, 10).addCuboid(-3.0F, -4.0F, -1.0F, 4.0F, 4.0F, 7.0F, 0.0F); + abdomen_r1.texOffs(0, 10).addBox(-3.0F, -4.0F, -1.0F, 4.0F, 4.0F, 7.0F, 0.0F); } @Override - public void setAngles(SilkMothEntity entity, float limbAngle, float limbDistance, float animationProgress, + public void setupAnim(SilkMothEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { - wingR_r1.roll = Mth.sin(animationProgress * 2F) * 0.4F + 0.3927F; - wingL_r1.roll = -wingR_r1.roll; - head_pivot.pitch = Mth.sin(animationProgress * 0.03F) * 0.1F; - tendril_r_r1.roll = Mth.sin(animationProgress * 0.07F) * 0.2F + 0.3927F; - tendril_r_r2.roll = -tendril_r_r1.roll; - abdomen_r1.pitch = Mth.sin(animationProgress * 0.05F) * 0.1F - 0.3927F; - legsR.roll = Mth.sin(animationProgress * 0.07F) * 0.1F - 0.6545F; - legsL.roll = -legsR.roll; + wingR_r1.zRot = Mth.sin(animationProgress * 2F) * 0.4F + 0.3927F; + wingL_r1.zRot = -wingR_r1.zRot; + head_pivot.xRot = Mth.sin(animationProgress * 0.03F) * 0.1F; + tendril_r_r1.zRot = Mth.sin(animationProgress * 0.07F) * 0.2F + 0.3927F; + tendril_r_r2.zRot = -tendril_r_r1.zRot; + abdomen_r1.xRot = Mth.sin(animationProgress * 0.05F) * 0.1F - 0.3927F; + legsR.zRot = Mth.sin(animationProgress * 0.07F) * 0.1F - 0.6545F; + legsL.zRot = -legsR.zRot; } @Override - public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, - float blue, float alpha) { + public void renderToBuffer(PoseStack matrices, VertexConsumer vertices, int light, int overlay, float red, + float green, float blue, float alpha) { bb_main.render(matrices, vertices, light, overlay); head_pivot.render(matrices, vertices, light, overlay); legsL.render(matrices, vertices, light, overlay); diff --git a/src/main/java/ru/betterend/entity/render/RendererEntityCubozoa.java b/src/main/java/ru/betterend/entity/render/RendererEntityCubozoa.java index 0bb0b984..0e23ffed 100644 --- a/src/main/java/ru/betterend/entity/render/RendererEntityCubozoa.java +++ b/src/main/java/ru/betterend/entity/render/RendererEntityCubozoa.java @@ -1,57 +1,54 @@ package ru.betterend.entity.render; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.client.render.entity.feature.EyesFeatureRenderer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.MobRenderer; +import net.minecraft.client.renderer.entity.layers.EyesLayer; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import ru.betterend.BetterEnd; import ru.betterend.entity.CubozoaEntity; import ru.betterend.entity.model.CubozoaEntityModel; -public class RendererEntityCubozoa extends MobEntityRenderer { +public class RendererEntityCubozoa extends MobRenderer { private static final ResourceLocation[] TEXTURE = new ResourceLocation[2]; - private static final RenderLayer[] GLOW = new RenderLayer[2]; + private static final RenderType[] GLOW = new RenderType[2]; public RendererEntityCubozoa(EntityRenderDispatcher entityRenderDispatcher) { super(entityRenderDispatcher, new CubozoaEntityModel(), 0.5f); - this.addFeature(new EyesFeatureRenderer(this) { + this.addLayer(new EyesLayer(this) { @Override - public RenderLayer getEyesTexture() { + public RenderType renderType() { return GLOW[0]; } @Override - public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, - CubozoaEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, - float headYaw, float headPitch) { + public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, CubozoaEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) { VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getVariant()]); - this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, - 1.0F, 1.0F); + this.getParentModel().renderToBuffer(matrices, vertexConsumer, 15728640, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F); } - }); + }); } @Override - protected void scale(CubozoaEntity entity, MatrixStack matrixStack, float f) { + protected void scale(CubozoaEntity entity, PoseStack matrixStack, float f) { float scale = entity.getScale(); matrixStack.scale(scale, scale, scale); } @Override - public ResourceLocation getTexture(CubozoaEntity entity) { + public ResourceLocation getTextureLocation(CubozoaEntity entity) { return TEXTURE[entity.getVariant()]; } - + static { TEXTURE[0] = BetterEnd.makeID("textures/entity/cubozoa/cubozoa.png"); TEXTURE[1] = BetterEnd.makeID("textures/entity/cubozoa/cubozoa_sulphur.png"); - - GLOW[0] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_glow.png")); - GLOW[1] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_sulphur_glow.png")); + + GLOW[0] = RenderType.eyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_glow.png")); + GLOW[1] = RenderType.eyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_sulphur_glow.png")); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/entity/render/RendererEntityDragonfly.java b/src/main/java/ru/betterend/entity/render/RendererEntityDragonfly.java index 64901b1b..37e82160 100644 --- a/src/main/java/ru/betterend/entity/render/RendererEntityDragonfly.java +++ b/src/main/java/ru/betterend/entity/render/RendererEntityDragonfly.java @@ -1,30 +1,30 @@ package ru.betterend.entity.render; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.client.render.entity.feature.EyesFeatureRenderer; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.MobRenderer; +import net.minecraft.client.renderer.entity.layers.EyesLayer; import net.minecraft.resources.ResourceLocation; import ru.betterend.BetterEnd; import ru.betterend.entity.DragonflyEntity; import ru.betterend.entity.model.DragonflyEntityModel; -public class RendererEntityDragonfly extends MobEntityRenderer { +public class RendererEntityDragonfly extends MobRenderer { private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/dragonfly.png"); - private static final RenderLayer GLOW = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/dragonfly_glow.png")); + private static final RenderType GLOW = RenderType.eyes(BetterEnd.makeID("textures/entity/dragonfly_glow.png")); public RendererEntityDragonfly(EntityRenderDispatcher entityRenderDispatcher) { super(entityRenderDispatcher, new DragonflyEntityModel(), 0.5f); - this.addFeature(new EyesFeatureRenderer(this) { + this.addLayer(new EyesLayer(this) { @Override - public RenderLayer getEyesTexture() { + public RenderType renderType() { return GLOW; } }); } @Override - public ResourceLocation getTexture(DragonflyEntity entity) { + public ResourceLocation getTextureLocation(DragonflyEntity entity) { return TEXTURE; } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/entity/render/RendererEntityEndFish.java b/src/main/java/ru/betterend/entity/render/RendererEntityEndFish.java index c96ae77d..e37fe63d 100644 --- a/src/main/java/ru/betterend/entity/render/RendererEntityEndFish.java +++ b/src/main/java/ru/betterend/entity/render/RendererEntityEndFish.java @@ -1,56 +1,56 @@ package ru.betterend.entity.render; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.client.render.entity.feature.EyesFeatureRenderer; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.MobRenderer; +import net.minecraft.client.renderer.entity.layers.EyesLayer; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import ru.betterend.BetterEnd; import ru.betterend.entity.EndFishEntity; import ru.betterend.entity.model.EndFishEntityModel; -public class RendererEntityEndFish extends MobEntityRenderer { +public class RendererEntityEndFish extends MobRenderer { private static final ResourceLocation[] TEXTURE = new ResourceLocation[EndFishEntity.VARIANTS]; - private static final RenderLayer[] GLOW = new RenderLayer[EndFishEntity.VARIANTS]; + private static final RenderType[] GLOW = new RenderType[EndFishEntity.VARIANTS]; public RendererEntityEndFish(EntityRenderDispatcher entityRenderDispatcher) { super(entityRenderDispatcher, new EndFishEntityModel(), 0.5f); - this.addFeature(new EyesFeatureRenderer(this) { + this.addLayer(new EyesLayer(this) { @Override - public RenderLayer getEyesTexture() { + public RenderType renderType() { return GLOW[0]; } @Override - public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, - EndFishEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, - float headYaw, float headPitch) { + public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, EndFishEntity entity, + float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, + float headPitch) { VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getVariant()]); - this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, - 1.0F, 1.0F); + this.getParentModel().renderToBuffer(matrices, vertexConsumer, 15728640, OverlayTexture.NO_OVERLAY, + 1.0F, 1.0F, 1.0F, 1.0F); } }); } @Override - protected void scale(EndFishEntity entity, MatrixStack matrixStack, float f) { + protected void scale(EndFishEntity entity, PoseStack matrixStack, float f) { float scale = entity.getScale(); matrixStack.scale(scale, scale, scale); } @Override - public ResourceLocation getTexture(EndFishEntity entity) { + public ResourceLocation getTextureLocation(EndFishEntity entity) { return TEXTURE[entity.getVariant()]; } static { for (int i = 0; i < EndFishEntity.VARIANTS; i++) { TEXTURE[i] = BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + ".png"); - GLOW[i] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + "_glow.png")); + GLOW[i] = RenderType.eyes(BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + "_glow.png")); } } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/entity/render/RendererEntityEndSlime.java b/src/main/java/ru/betterend/entity/render/RendererEntityEndSlime.java index 6075d9eb..fa3de633 100644 --- a/src/main/java/ru/betterend/entity/render/RendererEntityEndSlime.java +++ b/src/main/java/ru/betterend/entity/render/RendererEntityEndSlime.java @@ -1,103 +1,103 @@ package ru.betterend.entity.render; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.LivingEntityRenderer; -import net.minecraft.client.render.entity.MobEntityRenderer; -import net.minecraft.client.render.entity.feature.EyesFeatureRenderer; -import net.minecraft.client.render.entity.feature.FeatureRenderer; -import net.minecraft.client.render.entity.feature.FeatureRendererContext; -import net.minecraft.client.util.math.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.LivingEntityRenderer; +import net.minecraft.client.renderer.entity.MobRenderer; +import net.minecraft.client.renderer.entity.RenderLayerParent; +import net.minecraft.client.renderer.entity.layers.EyesLayer; +import net.minecraft.client.renderer.entity.layers.RenderLayer; +import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import ru.betterend.BetterEnd; import ru.betterend.entity.EndSlimeEntity; import ru.betterend.entity.model.EndSlimeEntityModel; -public class RendererEntityEndSlime extends MobEntityRenderer> { +public class RendererEntityEndSlime extends MobRenderer> { private static final ResourceLocation TEXTURE[] = new ResourceLocation[4]; - private static final RenderLayer GLOW[] = new RenderLayer[4]; + private static final RenderType GLOW[] = new RenderType[4]; public RendererEntityEndSlime(EntityRenderDispatcher entityRenderDispatcher) { super(entityRenderDispatcher, new EndSlimeEntityModel(false), 0.25F); - this.addFeature(new OverlayFeatureRenderer(this)); - this.addFeature(new EyesFeatureRenderer>(this) { + this.addLayer(new OverlayFeatureRenderer(this)); + this.addLayer(new EyesLayer>(this) { @Override - public RenderLayer getEyesTexture() { + public RenderType renderType() { return GLOW[0]; } @Override - public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, - EndSlimeEntity entity, float limbAngle, float limbDistance, float tickDelta, - float animationProgress, float headYaw, float headPitch) { + public void render(PoseStack matrices, MultiBufferSource vertexConsumers, int light, EndSlimeEntity entity, + float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, + float headPitch) { VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getSlimeType()]); - this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, - 1.0F, 1.0F); + this.getParentModel().renderToBuffer(matrices, vertexConsumer, 15728640, OverlayTexture.NO_OVERLAY, + 1.0F, 1.0F, 1.0F, 1.0F); if (entity.isLake()) { - this.getContextModel().renderFlower(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV); + this.getParentModel().renderFlower(matrices, vertexConsumer, 15728640, OverlayTexture.NO_OVERLAY); } } }); } @Override - public ResourceLocation getTexture(EndSlimeEntity entity) { + public ResourceLocation getTextureLocation(EndSlimeEntity entity) { return TEXTURE[entity.getSlimeType()]; } @Override - public void render(EndSlimeEntity slimeEntity, float f, float g, MatrixStack matrixStack, - VertexConsumerProvider vertexConsumerProvider, int i) { + public void render(EndSlimeEntity slimeEntity, float f, float g, PoseStack matrixStack, + MultiBufferSource vertexConsumerProvider, int i) { this.shadowRadius = 0.25F * (float) slimeEntity.getSize(); super.render(slimeEntity, f, g, matrixStack, vertexConsumerProvider, i); } @Override - protected void scale(EndSlimeEntity slimeEntity, MatrixStack matrixStack, float f) { + protected void scale(EndSlimeEntity slimeEntity, PoseStack matrixStack, float f) { matrixStack.scale(0.999F, 0.999F, 0.999F); matrixStack.translate(0.0D, 0.0010000000474974513D, 0.0D); float h = (float) slimeEntity.getSize(); - float i = Mth.lerp(f, slimeEntity.lastStretch, slimeEntity.stretch) / (h * 0.5F + 1.0F); + float i = Mth.lerp(f, slimeEntity.oSquish, slimeEntity.squish) / (h * 0.5F + 1.0F); float j = 1.0F / (i + 1.0F); matrixStack.scale(j * h, 1.0F / j * h, j * h); } private final class OverlayFeatureRenderer - extends FeatureRenderer> { + extends RenderLayer> { private final EndSlimeEntityModel modelOrdinal = new EndSlimeEntityModel(true); private final EndSlimeEntityModel modelLake = new EndSlimeEntityModel(true); - public OverlayFeatureRenderer(FeatureRendererContext> featureRendererContext) { + public OverlayFeatureRenderer(RenderLayerParent> featureRendererContext) { super(featureRendererContext); } - public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, - T livingEntity, float f, float g, float h, float j, float k, float l) { + public void render(PoseStack matrixStack, MultiBufferSource vertexConsumerProvider, int i, T livingEntity, + float f, float g, float h, float j, float k, float l) { if (!livingEntity.isInvisible()) { if (livingEntity.isLake()) { VertexConsumer vertexConsumer = vertexConsumerProvider - .getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity))); - this.getContextModel().renderFlower(matrixStack, vertexConsumer, i, - LivingEntityRenderer.getOverlay(livingEntity, 0.0F)); + .getBuffer(RenderType.entityCutout(this.getTextureLocation(livingEntity))); + this.getParentModel().renderFlower(matrixStack, vertexConsumer, i, + LivingEntityRenderer.getOverlayCoords(livingEntity, 0.0F)); } else if (livingEntity.isAmber() || livingEntity.isChorus()) { VertexConsumer vertexConsumer = vertexConsumerProvider - .getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity))); - this.getContextModel().renderCrop(matrixStack, vertexConsumer, i, - LivingEntityRenderer.getOverlay(livingEntity, 0.0F)); + .getBuffer(RenderType.entityCutout(this.getTextureLocation(livingEntity))); + this.getParentModel().renderCrop(matrixStack, vertexConsumer, i, + LivingEntityRenderer.getOverlayCoords(livingEntity, 0.0F)); } EndSlimeEntityModel model = livingEntity.getSlimeType() == 1 ? modelLake : modelOrdinal; - this.getContextModel().copyStateTo(model); - model.animateModel(livingEntity, f, g, h); - model.setAngles(livingEntity, f, g, j, k, l); + this.getParentModel().copyPropertiesTo(model); + model.prepareMobModel(livingEntity, f, g, h); + model.setupAnim(livingEntity, f, g, j, k, l); VertexConsumer vertexConsumer = vertexConsumerProvider - .getBuffer(RenderLayer.getEntityTranslucent(this.getTexture(livingEntity))); - model.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0F), 1.0F, - 1.0F, 1.0F, 1.0F); + .getBuffer(RenderType.entityTranslucent(this.getTextureLocation(livingEntity))); + model.renderToBuffer(matrixStack, vertexConsumer, i, + LivingEntityRenderer.getOverlayCoords(livingEntity, 0.0F), 1.0F, 1.0F, 1.0F, 1.0F); } } } @@ -107,9 +107,9 @@ public class RendererEntityEndSlime extends MobEntityRenderer> { + extends HumanoidMobRenderer> { private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/shadow_walker.png"); public RendererEntityShadowWalker(EntityRenderDispatcher entityRenderDispatcher) { - super(entityRenderDispatcher, new PlayerEntityModel(0.0F, false), 0.5F); + super(entityRenderDispatcher, new PlayerModel(0.0F, false), 0.5F); } @Override - public ResourceLocation getTexture(ShadowWalkerEntity zombieEntity) { + public ResourceLocation getTextureLocation(ShadowWalkerEntity zombieEntity) { return TEXTURE; } } diff --git a/src/main/java/ru/betterend/entity/render/SilkMothEntityRenderer.java b/src/main/java/ru/betterend/entity/render/SilkMothEntityRenderer.java index f6514e5d..7d3a2745 100644 --- a/src/main/java/ru/betterend/entity/render/SilkMothEntityRenderer.java +++ b/src/main/java/ru/betterend/entity/render/SilkMothEntityRenderer.java @@ -1,13 +1,13 @@ package ru.betterend.entity.render; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.MobEntityRenderer; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.resources.ResourceLocation; import ru.betterend.BetterEnd; import ru.betterend.entity.SilkMothEntity; import ru.betterend.entity.model.SilkMothEntityModel; -public class SilkMothEntityRenderer extends MobEntityRenderer { +public class SilkMothEntityRenderer extends MobRenderer { private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/silk_moth.png"); public SilkMothEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) { @@ -15,7 +15,7 @@ public class SilkMothEntityRenderer extends MobEntityRenderer PLAYER_ADVANCEMENT_COMPLETE = EventFactory - .createArrayBacked(AdvancementComplete.class, callbacks -> (player, advancement, criterionName) -> { - for (AdvancementComplete event : callbacks) { - event.onAdvancementComplete(player, advancement, criterionName); - } - }); - + + public static Event PLAYER_ADVENCEMENT_COMPLETE = EventFactory.createArrayBacked(AdvancementComplete.class, callbacks -> (player, advancement, criterionName) -> { + for (AdvancementComplete event : callbacks) { + event.onAdvancementComplete(player, advancement, criterionName); + } + }); + public interface AdvancementComplete { void onAdvancementComplete(ServerPlayer player, Advancement advancement, String criterionName); } diff --git a/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java b/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java index 8a910df0..d5f6e224 100644 --- a/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java +++ b/src/main/java/ru/betterend/integration/FlamboyantRefabricatedIntegration.java @@ -2,10 +2,8 @@ package ru.betterend.integration; import java.awt.Color; import java.util.Map; - -import com.google.common.collect.Maps; - import net.minecraft.world.level.ItemLike; +import com.google.common.collect.Maps; import ru.betterend.blocks.HydraluxPetalColoredBlock; import ru.betterend.blocks.complex.ColoredMaterial; import ru.betterend.registry.EndBlocks; @@ -18,24 +16,25 @@ public class FlamboyantRefabricatedIntegration extends ModIntegration { @Override public void register() { - /* - * Class fDyeColor = - * getClass("com.github.EltrutCo.flamboyant.items.FDyeColor"); Object[] values = - * getStaticFieldValue(fDyeColor, "VALUES"); - * - * if (values == null) { return; } - */ - + /*Class fDyeColor = getClass("com.github.EltrutCo.flamboyant.items.FDyeColor"); + Object[] values = getStaticFieldValue(fDyeColor, "VALUES"); + + if (values == null) { + return; + }*/ + Map colors = Maps.newHashMap(); Map dyes = Maps.newHashMap(); - /* - * for (Object val: values) { Integer color = (Integer) getFieldValue(fDyeColor, - * "signColor", val); String name = (String) getFieldValue(fDyeColor, "name", - * val); if (color != null && name != null) { colors.put(color, name); - * System.out.println(name + " " + color + " " + new Color(color)); - * dyes.put(color, getItem(name + "_dye")); } } - */ - + /*for (Object val: values) { + Integer color = (Integer) getFieldValue(fDyeColor, "signColor", val); + String name = (String) getFieldValue(fDyeColor, "name", val); + if (color != null && name != null) { + colors.put(color, name); + System.out.println(name + " " + color + " " + new Color(color)); + dyes.put(color, getItem(name + "_dye")); + } + }*/ + addColor("fead1d", "amber", colors, dyes); addColor("bd9a5f", "beige", colors, dyes); addColor("edeada", "cream", colors, dyes); @@ -52,15 +51,15 @@ public class FlamboyantRefabricatedIntegration extends ModIntegration { addColor("6bb1cf", "sky_blue", colors, dyes); addColor("6e8c9c", "slate_gray", colors, dyes); addColor("b02454", "violet", colors, dyes); - + new ColoredMaterial(HydraluxPetalColoredBlock::new, EndBlocks.HYDRALUX_PETAL_BLOCK, colors, dyes, true); } - + private void addColor(String hex, String name, Map colors, Map dyes) { int color = MHelper.color(hex); colors.put(color, name); dyes.put(color, getItem(name + "_dye")); - + System.out.println(name + " " + color + " " + new Color(color)); } } diff --git a/src/main/java/ru/betterend/integration/ModIntegration.java b/src/main/java/ru/betterend/integration/ModIntegration.java index 9489940a..24c01e58 100644 --- a/src/main/java/ru/betterend/integration/ModIntegration.java +++ b/src/main/java/ru/betterend/integration/ModIntegration.java @@ -7,19 +7,19 @@ import java.lang.reflect.Method; import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.item.Item; +import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; import net.minecraft.tags.Tag.Named; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.Item; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.BetterEnd; @@ -27,25 +27,23 @@ import ru.betterend.world.features.EndFeature; public abstract class ModIntegration { private final String modID; - - public void register() { - } - - public void addBiomes() { - } - + + public void register() {} + + public void addBiomes() {} + public ModIntegration(String modID) { this.modID = modID; } - + public ResourceLocation getID(String name) { return new ResourceLocation(modID, name); } - + public Block getBlock(String name) { return Registry.BLOCK.get(getID(name)); } - + public Item getItem(String name) { return Registry.ITEM.get(getID(name)); } @@ -53,39 +51,39 @@ public abstract class ModIntegration { public BlockState getDefaultState(String name) { return getBlock(name).defaultBlockState(); } - + public ResourceKey getKey(String name) { - return ResourceKey.of(Registry.BIOME_KEY, getID(name)); + return ResourceKey.create(Registry.BIOME_REGISTRY, getID(name)); } - + public boolean modIsInstalled() { return FabricLoader.getInstance().isModLoaded(modID); } - - public EndFeature getFeature(String featureID, String configuredFeatureID, GenerationStep.Feature featureStep) { + + public EndFeature getFeature(String featureID, String configuredFeatureID, GenerationStep.Decoration featureStep) { Feature feature = Registry.FEATURE.get(getID(featureID)); - ConfiguredFeature featureConfigured = BuiltinRegistries.CONFIGURED_FEATURE - .get(getID(configuredFeatureID)); + ConfiguredFeature featureConfigured = BuiltinRegistries.CONFIGURED_FEATURE.get(getID(configuredFeatureID)); return new EndFeature(feature, featureConfigured, featureStep); } - - public EndFeature getFeature(String name, GenerationStep.Feature featureStep) { + + public EndFeature getFeature(String name, GenerationStep.Decoration featureStep) { return getFeature(name, name, featureStep); } - + public ConfiguredFeature getConfiguredFeature(String name) { return BuiltinRegistries.CONFIGURED_FEATURE.get(getID(name)); } - + public Biome getBiome(String name) { return BuiltinRegistries.BIOME.get(getID(name)); } - + public Class getClass(String path) { Class cl = null; try { cl = Class.forName(path); - } catch (ClassNotFoundException e) { + } + catch (ClassNotFoundException e) { BetterEnd.LOGGER.error(e.getMessage()); if (BetterEnd.isDevEnvironment()) { e.printStackTrace(); @@ -93,7 +91,7 @@ public abstract class ModIntegration { } return cl; } - + @SuppressWarnings("unchecked") public T getStaticFieldValue(Class cl, String name) { if (cl != null) { @@ -102,13 +100,14 @@ public abstract class ModIntegration { if (field != null) { return (T) field.get(null); } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } return null; } - + public Object getFieldValue(Class cl, String name, Object classInstance) { if (cl != null) { try { @@ -116,18 +115,20 @@ public abstract class ModIntegration { if (field != null) { return field.get(classInstance); } - } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + } + catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } return null; } - + public Method getMethod(Class cl, String functionName, Class... args) { if (cl != null) { try { return cl.getMethod(functionName, args); - } catch (NoSuchMethodException | SecurityException e) { + } + catch (NoSuchMethodException | SecurityException e) { BetterEnd.LOGGER.error(e.getMessage()); if (BetterEnd.isDevEnvironment()) { e.printStackTrace(); @@ -136,12 +137,13 @@ public abstract class ModIntegration { } return null; } - + public Object executeMethod(Object instance, Method method, Object... args) { if (method != null) { try { return method.invoke(instance, args); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { BetterEnd.LOGGER.error(e.getMessage()); if (BetterEnd.isDevEnvironment()) { e.printStackTrace(); @@ -150,7 +152,7 @@ public abstract class ModIntegration { } return null; } - + public Object getAndExecuteStatic(Class cl, String functionName, Object... args) { if (cl != null) { Class[] classes = new Class[args.length]; @@ -162,10 +164,9 @@ public abstract class ModIntegration { } return null; } - + @SuppressWarnings("unchecked") - public T getAndExecuteRuntime(Class cl, Object instance, String functionName, - Object... args) { + public T getAndExecuteRuntime(Class cl, Object instance, String functionName, Object... args) { if (instance != null) { Class[] classes = new Class[args.length]; for (int i = 0; i < args.length; i++) { @@ -176,15 +177,15 @@ public abstract class ModIntegration { } return null; } - + public Object newInstance(Class cl, Object... args) { if (cl != null) { - for (Constructor constructor : cl.getConstructors()) { + for (Constructor constructor: cl.getConstructors()) { if (constructor.getParameterCount() == args.length) { try { return constructor.newInstance(args); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException e) { + } + catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { BetterEnd.LOGGER.error(e.getMessage()); if (BetterEnd.isDevEnvironment()) { e.printStackTrace(); @@ -195,16 +196,16 @@ public abstract class ModIntegration { } return null; } - + public Tag.Named getItemTag(String name) { ResourceLocation id = getID(name); - Tag tag = ItemTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.item(id) : (Identified) tag; + Tag tag = ItemTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; } - + public Tag.Named getBlockTag(String name) { ResourceLocation id = getID(name); - Tag tag = BlockTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.block(id) : (Identified) tag; + Tag tag = BlockTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; } } diff --git a/src/main/java/ru/betterend/integration/NourishIntegration.java b/src/main/java/ru/betterend/integration/NourishIntegration.java index 0697e356..37a92fa6 100644 --- a/src/main/java/ru/betterend/integration/NourishIntegration.java +++ b/src/main/java/ru/betterend/integration/NourishIntegration.java @@ -1,7 +1,7 @@ package ru.betterend.integration; -import net.minecraft.world.item.Item; import net.minecraft.tags.Tag; +import net.minecraft.world.item.Item; import ru.betterend.registry.EndItems; import ru.betterend.util.TagHelper; @@ -16,10 +16,9 @@ public class NourishIntegration extends ModIntegration { Tag.Named fruit = getItemTag("fruit"); Tag.Named protein = getItemTag("protein"); Tag.Named sweets = getItemTag("sweets"); - + TagHelper.addTag(fats, EndItems.END_FISH_RAW, EndItems.END_FISH_COOKED); - TagHelper.addTag(fruit, EndItems.SHADOW_BERRY_RAW, EndItems.SHADOW_BERRY_COOKED, EndItems.BLOSSOM_BERRY, - EndItems.SHADOW_BERRY_JELLY, EndItems.SWEET_BERRY_JELLY); + TagHelper.addTag(fruit, EndItems.SHADOW_BERRY_RAW, EndItems.SHADOW_BERRY_COOKED, EndItems.BLOSSOM_BERRY, EndItems.SHADOW_BERRY_JELLY, EndItems.SWEET_BERRY_JELLY); TagHelper.addTag(protein, EndItems.END_FISH_RAW, EndItems.END_FISH_COOKED); TagHelper.addTag(sweets, EndItems.SHADOW_BERRY_JELLY, EndItems.SWEET_BERRY_JELLY); } diff --git a/src/main/java/ru/betterend/integration/byg/BYGBlocks.java b/src/main/java/ru/betterend/integration/byg/BYGBlocks.java index 3dd5635f..911ea1ea 100644 --- a/src/main/java/ru/betterend/integration/byg/BYGBlocks.java +++ b/src/main/java/ru/betterend/integration/byg/BYGBlocks.java @@ -8,9 +8,8 @@ import ru.betterend.registry.EndBlocks; public class BYGBlocks { public static final Block IVIS_MOSS = EndBlocks.registerBlock("ivis_moss", new EndWallPlantBlock()); public static final Block NIGHTSHADE_MOSS = EndBlocks.registerBlock("nightshade_moss", new EndWallPlantBlock()); - + public static final Block IVIS_VINE = EndBlocks.registerBlock("ivis_vine", new VineBlock()); - - public static void register() { - } + + public static void register() {} } diff --git a/src/main/java/ru/betterend/integration/byg/BYGIntegration.java b/src/main/java/ru/betterend/integration/byg/BYGIntegration.java index b7250223..4e18f028 100644 --- a/src/main/java/ru/betterend/integration/byg/BYGIntegration.java +++ b/src/main/java/ru/betterend/integration/byg/BYGIntegration.java @@ -2,10 +2,9 @@ package ru.betterend.integration.byg; import java.util.List; import java.util.stream.Collectors; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.collection.WeightedList; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.ai.behavior.WeightedList; import net.minecraft.world.level.biome.Biome; import ru.betterend.integration.Integrations; import ru.betterend.integration.ModIntegration; @@ -32,31 +31,31 @@ public class BYGIntegration extends ModIntegration { @Override public void addBiomes() { BYGBiomes.addBiomes(); - + Class biomeClass = this.getClass("corgiaoc.byg.common.world.biome.BYGEndBiome"); List biomes = this.getStaticFieldValue(biomeClass, "BYG_END_BIOMES"); - + if (biomes != null && biomeClass != null) { biomes.forEach((obj) -> { Biome biome = this.getAndExecuteRuntime(biomeClass, obj, "getBiome"); if (biome != null) { - ResourceLocation biomeID = BuiltinRegistries.BIOME.getId(biome); + ResourceLocation biomeID = BuiltinRegistries.BIOME.getKey(biome); EndBiome endBiome = EndBiomes.getBiome(biomeID); Biome edge = this.getAndExecuteRuntime(biomeClass, obj, "getEdge"); if (edge != null) { - ResourceLocation edgeID = BuiltinRegistries.BIOME.getId(edge); + ResourceLocation edgeID = BuiltinRegistries.BIOME.getKey(edge); EndBiomes.LAND_BIOMES.removeMutableBiome(edgeID); EndBiomes.VOID_BIOMES.removeMutableBiome(edgeID); EndBiome edgeBiome = EndBiomes.getBiome(edgeID); endBiome.setEdge(edgeBiome); - } else { + } + else { Boolean isVoid = this.getAndExecuteRuntime(biomeClass, obj, "isVoid"); if (isVoid != null && isVoid.booleanValue()) { EndBiomes.LAND_BIOMES.removeMutableBiome(biomeID); EndBiomes.VOID_BIOMES.addBiomeMutable(endBiome); } - WeightedList subBiomes = this.getAndExecuteRuntime(biomeClass, obj, - "getHills"); + WeightedList subBiomes = this.getAndExecuteRuntime(biomeClass, obj, "getHills"); if (subBiomes != null) { subBiomes.stream().collect(Collectors.toList()).forEach((id) -> { EndBiome subBiome = EndBiomes.getBiome(id); diff --git a/src/main/java/ru/betterend/integration/byg/biomes/EterialGrove.java b/src/main/java/ru/betterend/integration/byg/biomes/EterialGrove.java index 3db0b3ef..42442df7 100644 --- a/src/main/java/ru/betterend/integration/byg/biomes/EterialGrove.java +++ b/src/main/java/ru/betterend/integration/byg/biomes/EterialGrove.java @@ -1,12 +1,11 @@ package ru.betterend.integration.byg.biomes; import java.util.List; - -import net.minecraft.world.entity.SpawnGroup; import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.BiomeEffects; -import net.minecraft.world.biome.SpawnSettings.SpawnEntry; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import ru.betterend.BetterEnd; import ru.betterend.integration.Integrations; import ru.betterend.integration.byg.features.BYGFeatures; @@ -17,30 +16,30 @@ public class EterialGrove extends EndBiome { public EterialGrove() { super(makeDef()); } - + private static BiomeDefinition makeDef() { Biome biome = Integrations.BYG.getBiome("ethereal_islands"); - BiomeEffects effects = biome.getEffects(); - + BiomeSpecialEffects effects = biome.getSpecialEffects(); + BiomeDefinition def = new BiomeDefinition("eterial_grove") .setSurface(biome.getGenerationSettings().getSurfaceBuilder().get()) .addFeature(BYGFeatures.BIG_ETHER_TREE); - + if (BetterEnd.isClient()) { - SoundEvent loop = effects.getLoopSound().get(); - SoundEvent music = effects.getMusic().get().getSound(); - SoundEvent additions = effects.getAdditionsSound().get().getSound(); - SoundEvent mood = effects.getMoodSound().get().getSound(); + SoundEvent loop = effects.getAmbientLoopSoundEvent().get(); + SoundEvent music = effects.getBackgroundMusic().get().getEvent(); + SoundEvent additions = effects.getAmbientAdditionsSettings().get().getSoundEvent(); + SoundEvent mood = effects.getAmbientMoodSettings().get().getSoundEvent(); def.setLoop(loop).setMusic(music).setAdditions(additions).setMood(mood); } - - for (SpawnGroup group : SpawnGroup.values()) { - List list = biome.getSpawnSettings().getSpawnEntry(group); + + for (MobCategory group: MobCategory.values()) { + List list = biome.getMobSettings().getMobs(group); list.forEach((entry) -> { def.addMobSpawn(entry); }); } - + return def; } } diff --git a/src/main/java/ru/betterend/integration/byg/biomes/NightshadeRedwoods.java b/src/main/java/ru/betterend/integration/byg/biomes/NightshadeRedwoods.java index 0567deb4..69122484 100644 --- a/src/main/java/ru/betterend/integration/byg/biomes/NightshadeRedwoods.java +++ b/src/main/java/ru/betterend/integration/byg/biomes/NightshadeRedwoods.java @@ -1,14 +1,13 @@ package ru.betterend.integration.byg.biomes; import java.util.List; - -import net.minecraft.world.entity.SpawnGroup; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.BiomeEffects; -import net.minecraft.world.biome.SpawnSettings.SpawnEntry; -import net.minecraft.world.gen.GenerationStep.Feature; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import ru.betterend.BetterEnd; import ru.betterend.integration.Integrations; import ru.betterend.integration.byg.features.BYGFeatures; @@ -20,39 +19,45 @@ public class NightshadeRedwoods extends EndBiome { public NightshadeRedwoods() { super(makeDef()); } - + private static BiomeDefinition makeDef() { Biome biome = Integrations.BYG.getBiome("nightshade_forest"); - BiomeEffects effects = biome.getEffects(); - - BiomeDefinition def = new BiomeDefinition("nightshade_redwoods").setFogColor(140, 108, 47).setFogDensity(1.5F) - .setWaterAndFogColor(55, 70, 186).setFoliageColor(122, 17, 155) + BiomeSpecialEffects effects = biome.getSpecialEffects(); + + BiomeDefinition def = new BiomeDefinition("nightshade_redwoods") + .setFogColor(140, 108, 47) + .setFogDensity(1.5F) + .setWaterAndFogColor(55, 70, 186) + .setFoliageColor(122, 17, 155) .setParticles(ParticleTypes.REVERSE_PORTAL, 0.002F) - .setSurface(biome.getGenerationSettings().getSurfaceBuilder().get()).setGrassColor(48, 13, 89) - .setPlantsColor(200, 125, 9).addFeature(EndFeatures.END_LAKE_RARE) - .addFeature(BYGFeatures.NIGHTSHADE_REDWOOD_TREE).addFeature(BYGFeatures.NIGHTSHADE_MOSS_WOOD) + .setSurface(biome.getGenerationSettings().getSurfaceBuilder().get()) + .setGrassColor(48, 13, 89) + .setPlantsColor(200, 125, 9) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(BYGFeatures.NIGHTSHADE_REDWOOD_TREE) + .addFeature(BYGFeatures.NIGHTSHADE_MOSS_WOOD) .addFeature(BYGFeatures.NIGHTSHADE_MOSS); - + if (BetterEnd.isClient()) { - SoundEvent loop = effects.getLoopSound().get(); - SoundEvent music = effects.getMusic().get().getSound(); - SoundEvent additions = effects.getAdditionsSound().get().getSound(); - SoundEvent mood = effects.getMoodSound().get().getSound(); + SoundEvent loop = effects.getAmbientLoopSoundEvent().get(); + SoundEvent music = effects.getBackgroundMusic().get().getEvent(); + SoundEvent additions = effects.getAmbientAdditionsSettings().get().getSoundEvent(); + SoundEvent mood = effects.getAmbientMoodSettings().get().getSoundEvent(); def.setLoop(loop).setMusic(music).setAdditions(additions).setMood(mood); } - biome.getGenerationSettings().getFeatures().forEach((list) -> { + biome.getGenerationSettings().features().forEach((list) -> { list.forEach((feature) -> { - def.addFeature(Feature.VEGETAL_DECORATION, feature.get()); + def.addFeature(Decoration.VEGETAL_DECORATION, feature.get()); }); }); - - for (SpawnGroup group : SpawnGroup.values()) { - List list = biome.getSpawnSettings().getSpawnEntry(group); + + for (MobCategory group: MobCategory.values()) { + List list = biome.getMobSettings().getMobs(group); list.forEach((entry) -> { def.addMobSpawn(entry); }); } - + return def; } } diff --git a/src/main/java/ru/betterend/integration/byg/biomes/OldBulbisGardens.java b/src/main/java/ru/betterend/integration/byg/biomes/OldBulbisGardens.java index d8816e4b..469c6609 100644 --- a/src/main/java/ru/betterend/integration/byg/biomes/OldBulbisGardens.java +++ b/src/main/java/ru/betterend/integration/byg/biomes/OldBulbisGardens.java @@ -2,20 +2,19 @@ package ru.betterend.integration.byg.biomes; import java.util.List; import java.util.function.Supplier; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.entity.SpawnGroup; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.data.BuiltinRegistries; import net.minecraft.core.Registry; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.Features; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.BiomeEffects; -import net.minecraft.world.biome.SpawnSettings.SpawnEntry; -import net.minecraft.world.gen.GenerationStep.Feature; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeatures; import ru.betterend.BetterEnd; import ru.betterend.integration.Integrations; import ru.betterend.integration.byg.features.BYGFeatures; @@ -27,60 +26,65 @@ public class OldBulbisGardens extends EndBiome { public OldBulbisGardens() { super(makeDef()); } - + private static BiomeDefinition makeDef() { Biome biome = Integrations.BYG.getBiome("bulbis_gardens"); - BiomeEffects effects = biome.getEffects(); - + BiomeSpecialEffects effects = biome.getSpecialEffects(); + Block ivis = Integrations.BYG.getBlock("ivis_phylium"); Block origin = biome.getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial().getBlock(); - BiomeDefinition def = new BiomeDefinition("old_bulbis_gardens").setFogColor(215, 132, 207).setFogDensity(1.8F) - .setWaterAndFogColor(40, 0, 56).setFoliageColor(122, 17, 155) - .setParticles(ParticleTypes.REVERSE_PORTAL, 0.002F).setSurface(ivis, origin) - .addFeature(EndFeatures.END_LAKE_RARE).addFeature(BYGFeatures.OLD_BULBIS_TREE); - + BiomeDefinition def = new BiomeDefinition("old_bulbis_gardens") + .setFogColor(215, 132, 207) + .setFogDensity(1.8F) + .setWaterAndFogColor(40, 0, 56) + .setFoliageColor(122, 17, 155) + .setParticles(ParticleTypes.REVERSE_PORTAL, 0.002F) + .setSurface(ivis, origin) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(BYGFeatures.OLD_BULBIS_TREE); + if (BetterEnd.isClient()) { - SoundEvent loop = effects.getLoopSound().get(); - SoundEvent music = effects.getMusic().get().getSound(); - SoundEvent additions = effects.getAdditionsSound().get().getSound(); - SoundEvent mood = effects.getMoodSound().get().getSound(); + SoundEvent loop = effects.getAmbientLoopSoundEvent().get(); + SoundEvent music = effects.getBackgroundMusic().get().getEvent(); + SoundEvent additions = effects.getAmbientAdditionsSettings().get().getSoundEvent(); + SoundEvent mood = effects.getAmbientMoodSettings().get().getSoundEvent(); def.setLoop(loop).setMusic(music).setAdditions(additions).setMood(mood); } - - for (SpawnGroup group : SpawnGroup.values()) { - List list = biome.getSpawnSettings().getSpawnEntry(group); + + for (MobCategory group: MobCategory.values()) { + List list = biome.getMobSettings().getMobs(group); list.forEach((entry) -> { def.addMobSpawn(entry); }); } - - List>>> features = biome.getGenerationSettings().getFeatures(); - List>> vegetal = features.get(Feature.VEGETAL_DECORATION.ordinal()); + + List>>> features = biome.getGenerationSettings().features(); + List>> vegetal = features.get(Decoration.VEGETAL_DECORATION.ordinal()); if (vegetal.size() > 2) { Supplier> getter; // Trees (first two features) - // I couldn't process them with conditions, so that's why they are hardcoded - // (paulevs) + // I couldn't process them with conditions, so that's why they are hardcoded (paulevs) for (int i = 0; i < 2; i++) { getter = vegetal.get(i); ConfiguredFeature feature = getter.get(); ResourceLocation id = BetterEnd.makeID("obg_feature_" + i); - feature = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, - feature.decorate(ConfiguredFeatures.Decorators.SQUARE_HEIGHTMAP).repeatRandomly(1)); - def.addFeature(Feature.VEGETAL_DECORATION, feature); + feature = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, feature.decorated(Features.Decorators.HEIGHTMAP_SQUARE).countRandom(1)); + def.addFeature(Decoration.VEGETAL_DECORATION, feature); } // Grasses and other features for (int i = 2; i < vegetal.size(); i++) { getter = vegetal.get(i); ConfiguredFeature feature = getter.get(); - def.addFeature(Feature.VEGETAL_DECORATION, feature); + def.addFeature(Decoration.VEGETAL_DECORATION, feature); } } - - def.addFeature(EndFeatures.PURPLE_POLYPORE).addFeature(BYGFeatures.IVIS_MOSS_WOOD) - .addFeature(BYGFeatures.IVIS_MOSS).addFeature(BYGFeatures.IVIS_VINE) - .addFeature(BYGFeatures.IVIS_SPROUT); - + + def.addFeature(EndFeatures.PURPLE_POLYPORE) + .addFeature(BYGFeatures.IVIS_MOSS_WOOD) + .addFeature(BYGFeatures.IVIS_MOSS) + .addFeature(BYGFeatures.IVIS_VINE) + .addFeature(BYGFeatures.IVIS_SPROUT); + return def; } } diff --git a/src/main/java/ru/betterend/integration/byg/features/BigEtherTreeFeature.java b/src/main/java/ru/betterend/integration/byg/features/BigEtherTreeFeature.java index 9e9d790f..ee76db67 100644 --- a/src/main/java/ru/betterend/integration/byg/features/BigEtherTreeFeature.java +++ b/src/main/java/ru/betterend/integration/byg/features/BigEtherTreeFeature.java @@ -2,16 +2,14 @@ package ru.betterend.integration.byg.features; import java.util.List; import java.util.Random; - -import com.google.common.base.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.base.Function; +import com.mojang.math.Vector3f; import ru.betterend.integration.Integrations; import ru.betterend.registry.EndTags; import ru.betterend.util.MHelper; @@ -23,7 +21,7 @@ public class BigEtherTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlockState log = Integrations.BYG.getDefaultState("ether_log"); @@ -33,7 +31,7 @@ public class BigEtherTreeFeature extends DefaultFeature { return log; }; Function replace = (state) -> { - return state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) + return state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().isReplaceable(); }; @@ -51,7 +49,7 @@ public class BigEtherTreeFeature extends DefaultFeature { List branch = SplineHelper.makeSpline(0, 0, 0, length, 0, 0, points < 2 ? 2 : points); SplineHelper.powerOffset(branch, length, 2F); int rotCount = MHelper.randRange(5, 7, random); - // float startRad = Mth.lerp(splinePos, 2.3F, 0.8F) * 0.8F; + // float startRad = MathHelper.lerp(splinePos, 2.3F, 0.8F) * 0.8F; Vector3f start = SplineHelper.getPos(trunk, splinePos * (trunk.size() - 1)); for (int j = 0; j < rotCount; j++) { float angle = startAngle + (float) j / rotCount * MHelper.PI2; @@ -65,7 +63,7 @@ public class BigEtherTreeFeature extends DefaultFeature { } sdf.setReplaceFunction((state) -> { - return state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) + return state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().isReplaceable(); }).addPostProcess((info) -> { if (info.getState().equals(log) && (!info.getStateUp().equals(log) || !info.getStateDown().equals(log))) { @@ -77,7 +75,7 @@ public class BigEtherTreeFeature extends DefaultFeature { return true; } - // private void makeLeavesSphere(WorldGenLevel world, BlockPos pos, + // private void makeLeavesSphere(StructureWorldAccess world, BlockPos pos, // BlockState leaves, Function ignore) { // // } diff --git a/src/main/java/ru/betterend/integration/byg/features/GreatNightshadeTreeFeature.java b/src/main/java/ru/betterend/integration/byg/features/GreatNightshadeTreeFeature.java index 91501993..fc0b8bf4 100644 --- a/src/main/java/ru/betterend/integration/byg/features/GreatNightshadeTreeFeature.java +++ b/src/main/java/ru/betterend/integration/byg/features/GreatNightshadeTreeFeature.java @@ -2,21 +2,19 @@ package ru.betterend.integration.byg.features; import java.util.List; import java.util.Random; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.integration.Integrations; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -37,20 +35,20 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlockState log = Integrations.BYG.getDefaultState("nightshade_log"); BlockState wood = Integrations.BYG.getDefaultState("nightshade_wood"); - BlockState leaves = Integrations.BYG.getDefaultState("nightshade_leaves").with(LeavesBlock.DISTANCE, 1); + BlockState leaves = Integrations.BYG.getDefaultState("nightshade_leaves").setValue(LeavesBlock.DISTANCE, 1); BlockState leaves_flower = Integrations.BYG.getDefaultState("flowering_nightshade_leaves") - .with(LeavesBlock.DISTANCE, 1); + .setValue(LeavesBlock.DISTANCE, 1); Function splinePlacer = (bpos) -> { return log; }; Function replace = (state) -> { - return state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) + return state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().isReplaceable(); }; Function post = (info) -> { @@ -78,7 +76,7 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { for (int i = 0; i < count; i++) { float scale = (float) (count - i) / count * 15; Vector3f offset = SplineHelper.getPos(trunk, (float) i / count * delta + start); - if (offset.getY() > max) { + if (offset.y() > max) { break; } List branch = SplineHelper.copySpline(BRANCH); @@ -98,13 +96,13 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { sdf.setReplaceFunction(replace).addPostProcess(post).fillRecursive(world, pos); Vector3f last = SplineHelper.getPos(trunk, trunk.size() - 1.75F); for (int y = 0; y < 8; y++) { - BlockPos p = pos.offset(last.getX() + 0.5, last.getY() + y, last.getZ() + 0.5); + BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5); BlocksHelper.setWithoutUpdate(world, p, y == 4 ? wood : log); } for (int y = 0; y < 16; y++) { - BlockPos p = pos.offset(last.getX() + 0.5, last.getY() + y, last.getZ() + 0.5); - if (world.isAir(p)) { + BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5); + if (world.isEmptyBlock(p)) { BlocksHelper.setWithoutUpdate(world, p, leaves); } float radius = (1 - y / 16F) * 3F; @@ -115,8 +113,8 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { for (int z = -rad; z <= rad; z++) { int z2 = z * z; if (x2 + z2 < radius - random.nextFloat() * rad) { - BlockPos lp = p.add(x, 0, z); - if (world.isAir(lp)) { + BlockPos lp = p.offset(x, 0, z); + if (world.isEmptyBlock(lp)) { BlocksHelper.setWithoutUpdate(world, lp, leaves); } } @@ -142,7 +140,7 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -154,7 +152,7 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { }; Function leavesPost2 = (info) -> { if (info.getState().getBlock() instanceof LeavesBlock) { - int distance = info.getState().get(LeavesBlock.DISTANCE); + int distance = info.getState().getValue(LeavesBlock.DISTANCE); if (distance > MHelper.randRange(2, 4, random)) { return Blocks.AIR.defaultBlockState(); } @@ -168,7 +166,7 @@ public class GreatNightshadeTreeFeature extends DefaultFeature { } } if (random.nextInt(8) == 0) { - return leaves_flower.with(LeavesBlock.DISTANCE, distance); + return leaves_flower.setValue(LeavesBlock.DISTANCE, distance); } } return info.getState(); diff --git a/src/main/java/ru/betterend/integration/byg/features/NightshadeRedwoodTreeFeature.java b/src/main/java/ru/betterend/integration/byg/features/NightshadeRedwoodTreeFeature.java index 069e0f9b..f4e03327 100644 --- a/src/main/java/ru/betterend/integration/byg/features/NightshadeRedwoodTreeFeature.java +++ b/src/main/java/ru/betterend/integration/byg/features/NightshadeRedwoodTreeFeature.java @@ -2,21 +2,19 @@ package ru.betterend.integration.byg.features; import java.util.List; import java.util.Random; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.integration.Integrations; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -37,7 +35,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlockState log = Integrations.BYG.getDefaultState("nightshade_log"); @@ -49,7 +47,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { return log; }; Function replace = (state) -> { - return state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) + return state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().isReplaceable(); }; Function post = (info) -> { @@ -78,7 +76,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { for (int i = 0; i < count; i++) { float scale = (float) (count - i) / count * 15; Vector3f offset = SplineHelper.getPos(trunk, (float) i / count * delta + start); - if (offset.getY() > max) { + if (offset.y() > max) { break; } List branch = SplineHelper.copySpline(BRANCH); @@ -97,13 +95,13 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { sdf.setReplaceFunction(replace).addPostProcess(post).fillRecursive(world, pos); Vector3f last = SplineHelper.getPos(trunk, trunk.size() - 1.35F); for (int y = 0; y < 8; y++) { - BlockPos p = pos.offset(last.getX() + 0.5, last.getY() + y, last.getZ() + 0.5); + BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5); BlocksHelper.setWithoutUpdate(world, p, y == 4 ? wood : log); } for (int y = 0; y < 16; y++) { - BlockPos p = pos.offset(last.getX() + 0.5, last.getY() + y, last.getZ() + 0.5); - if (world.isAir(p)) { + BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5); + if (world.isEmptyBlock(p)) { BlocksHelper.setWithoutUpdate(world, p, leaves); } float radius = (1 - y / 16F) * 3F; @@ -114,8 +112,8 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { for (int z = -rad; z <= rad; z++) { int z2 = z * z; if (x2 + z2 < radius - random.nextFloat() * rad) { - BlockPos lp = p.add(x, 0, z); - if (world.isAir(lp)) { + BlockPos lp = p.offset(x, 0, z); + if (world.isEmptyBlock(lp)) { BlocksHelper.setWithoutUpdate(world, lp, leaves); } } @@ -141,7 +139,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -153,7 +151,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { }; Function leavesPost2 = (info) -> { if (info.getState().getBlock() instanceof LeavesBlock) { - int distance = info.getState().get(LeavesBlock.DISTANCE); + int distance = info.getState().getValue(LeavesBlock.DISTANCE); if (distance > MHelper.randRange(2, 4, random)) { return Blocks.AIR.defaultBlockState(); } @@ -167,7 +165,7 @@ public class NightshadeRedwoodTreeFeature extends DefaultFeature { } } if (random.nextInt(8) == 0) { - return leaves_flower.with(LeavesBlock.DISTANCE, distance); + return leaves_flower.setValue(LeavesBlock.DISTANCE, distance); } } return info.getState(); diff --git a/src/main/java/ru/betterend/integration/byg/features/OldBulbisTreeFeature.java b/src/main/java/ru/betterend/integration/byg/features/OldBulbisTreeFeature.java index 0252921e..e7ed034a 100644 --- a/src/main/java/ru/betterend/integration/byg/features/OldBulbisTreeFeature.java +++ b/src/main/java/ru/betterend/integration/byg/features/OldBulbisTreeFeature.java @@ -3,19 +3,17 @@ package ru.betterend.integration.byg.features; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.AABB; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.integration.Integrations; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndTags; @@ -38,9 +36,9 @@ public class OldBulbisTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; - if (!world.getBlockState(pos.down(4)).getBlock().isIn(EndTags.GEN_TERRAIN)) + if (!world.getBlockState(pos.below(4)).getBlock().is(EndTags.GEN_TERRAIN)) return false; BlockState stem = Integrations.BYG.getDefaultState("bulbis_stem"); @@ -50,7 +48,7 @@ public class OldBulbisTreeFeature extends DefaultFeature { BlockState glow = Integrations.BYG.getDefaultState("purple_shroomlight"); Function replacement = (state) -> { - if (state.equals(stem) || state.equals(wood) || state.isIn(EndTags.END_GROUND) + if (state.equals(stem) || state.equals(wood) || state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) { return true; } @@ -67,7 +65,7 @@ public class OldBulbisTreeFeature extends DefaultFeature { SDF sdf = null; int x1 = ((pos.getX() >> 4) << 4) - 16; int z1 = ((pos.getZ() >> 4) << 4) - 16; - Box limits = new Box(x1, pos.getY() - 5, z1, x1 + 47, pos.getY() + size * 2, z1 + 47); + AABB limits = new AABB(x1, pos.getY() - 5, z1, x1 + 47, pos.getY() + size * 2, z1 + 47); for (int i = 0; i < count; i++) { float angle = (float) i / (float) count * MHelper.PI2 + MHelper.randRange(0, var, random) + start; List spline = SplineHelper.copySpline(SPLINE); @@ -140,12 +138,12 @@ public class OldBulbisTreeFeature extends DefaultFeature { List side = SplineHelper.copySpline(SIDE); SplineHelper.rotateSpline(side, angle); SplineHelper.scale(side, scale * radius); - BlockPos p = pos.offset(point.getX() + 0.5F, point.getY() + 0.5F, point.getZ() + 0.5F); + BlockPos p = pos.offset(point.x() + 0.5F, point.y() + 0.5F, point.z() + 0.5F); SplineHelper.fillSplineForce(side, world, wood, p, replacement); } } - sphere.fillArea(world, pos, new Box(pos.up((int) offsetY)).expand(radius * 1.3F)); + sphere.fillArea(world, pos, new AABB(pos.above((int) offsetY)).inflate(radius * 1.3F)); } private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, Random random, BlockState wood, @@ -159,7 +157,7 @@ public class OldBulbisTreeFeature extends DefaultFeature { SplineHelper.rotateSpline(branch, angle); SplineHelper.scale(branch, scale); Vector3f last = branch.get(branch.size() - 1); - if (world.getBlockState(pos.offset(last.getX(), last.getY(), last.getZ())).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(EndTags.GEN_TERRAIN)) { SplineHelper.fillSpline(branch, world, wood, pos, replacement); } } diff --git a/src/main/java/ru/betterend/integration/rei/REIAlloyingCategory.java b/src/main/java/ru/betterend/integration/rei/REIAlloyingCategory.java index fa83d526..285f0be4 100644 --- a/src/main/java/ru/betterend/integration/rei/REIAlloyingCategory.java +++ b/src/main/java/ru/betterend/integration/rei/REIAlloyingCategory.java @@ -6,7 +6,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; import com.google.common.collect.Lists; - +import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -16,9 +16,8 @@ import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; import me.shedaniel.rei.gui.widget.Widget; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.TranslatableText; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import ru.betterend.recipe.builders.AlloyingRecipe; import ru.betterend.registry.EndBlocks; @@ -33,14 +32,14 @@ public class REIAlloyingCategory implements TransferRecipeCategory setupDisplay(REIAlloyingDisplay display, Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - 41, bounds.y + 10); @@ -49,49 +48,39 @@ public class REIAlloyingCategory implements TransferRecipeCategory widgets = Lists.newArrayList(); widgets.add(Widgets.createRecipeBase(bounds)); widgets.add(Widgets.createResultSlotBackground(new Point(startPoint.x + 61, startPoint.y + 9))); - widgets.add( - Widgets.createBurningFire(new Point(startPoint.x - 9, startPoint.y + 20)).animationDurationMS(10000)); - widgets.add(Widgets - .createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), new TranslatableText( - "category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))) - .noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); - widgets.add( - Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime)); + widgets.add(Widgets.createBurningFire(new Point(startPoint.x - 9, startPoint.y + 20)).animationDurationMS(10000)); + widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), + new TranslatableComponent("category.rei.cooking.time&xp", df.format(display.getXp()), df.format(smeltTime / 20D))).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); + widgets.add(Widgets.createArrow(new Point(startPoint.x + 24, startPoint.y + 8)).animationDurationTicks(smeltTime)); List> inputEntries = display.getInputEntries(); - widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(inputEntries.get(0)) - .markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x - 20, startPoint.y + 1)).entries(inputEntries.get(0)).markInput()); if (inputEntries.size() > 1) { - widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(inputEntries.get(1)) - .markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(inputEntries.get(1)).markInput()); } else { - widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(Lists.newArrayList()) - .markInput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 1, startPoint.y + 1)).entries(Lists.newArrayList()).markInput()); } - widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)) - .entries(display.getResultingEntries().get(0)).disableBackground().markOutput()); + widgets.add(Widgets.createSlot(new Point(startPoint.x + 61, startPoint.y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput()); return widgets; } @Override - public void renderRedSlots(MatrixStack matrices, List widgets, Rectangle bounds, REIAlloyingDisplay display, + public void renderRedSlots(PoseStack matrices, List widgets, Rectangle bounds, REIAlloyingDisplay display, IntList redSlots) { Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 27); - matrices.push(); + matrices.pushPose(); matrices.translate(0, 0, 400); if (redSlots.contains(0)) { - DrawableHelper.fill(matrices, startPoint.x - 20, startPoint.y + 1, startPoint.x - 20 + 16, - startPoint.y + 1 + 16, 1090453504); - DrawableHelper.fill(matrices, startPoint.x + 1, startPoint.y + 1, startPoint.x + 1 + 16, - startPoint.y + 1 + 16, 1090453504); + GuiComponent.fill(matrices, startPoint.x - 20, startPoint.y + 1, startPoint.x - 20 + 16, startPoint.y + 1 + 16, 1090453504); + GuiComponent.fill(matrices, startPoint.x + 1, startPoint.y + 1, startPoint.x + 1 + 16, startPoint.y + 1 + 16, 1090453504); } - matrices.pop(); + matrices.popPose(); } - + @Override public @NotNull RecipeEntry getSimpleRenderer(REIAlloyingDisplay recipe) { return SimpleRecipeEntry.from(recipe.getInputEntries(), recipe.getResultingEntries()); } - + @Override public int getDisplayHeight() { return 49; diff --git a/src/main/java/ru/betterend/integration/rei/REIAlloyingDisplay.java b/src/main/java/ru/betterend/integration/rei/REIAlloyingDisplay.java index 4e3f5f22..5937c021 100644 --- a/src/main/java/ru/betterend/integration/rei/REIAlloyingDisplay.java +++ b/src/main/java/ru/betterend/integration/rei/REIAlloyingDisplay.java @@ -10,56 +10,56 @@ import org.jetbrains.annotations.NotNull; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.TransferRecipeDisplay; import me.shedaniel.rei.server.ContainerInfo; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.Item; import net.minecraft.world.item.crafting.BlastingRecipe; import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Formatting; -import net.minecraft.resources.ResourceLocation; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; import ru.betterend.recipe.builders.AlloyingRecipe; public class REIAlloyingDisplay implements TransferRecipeDisplay { private static List fuel; - + private Recipe recipe; private List> input; private List output; private float xp; private double smeltTime; - + public REIAlloyingDisplay(AlloyingRecipe recipe) { this.recipe = recipe; - this.input = EntryStack.ofIngredients(recipe.getPreviewInputs()); - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.input = EntryStack.ofIngredients(recipe.getIngredients()); + this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem())); this.xp = recipe.getExperience(); this.smeltTime = recipe.getSmeltTime(); } - + public REIAlloyingDisplay(BlastingRecipe recipe) { this.recipe = recipe; - this.input = EntryStack.ofIngredients(recipe.getPreviewInputs()); - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.input = EntryStack.ofIngredients(recipe.getIngredients()); + this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem())); this.xp = recipe.getExperience(); - this.smeltTime = recipe.getCookTime(); + this.smeltTime = recipe.getCookingTime(); } - + public static List getFuel() { return fuel; } - + @Override public @NotNull Optional getRecipeLocation() { return Optional.ofNullable(recipe).map(Recipe::getId); } - + @Override public @NotNull List> getInputEntries() { return this.input; } - + @Override public @NotNull List> getResultingEntries() { return Collections.singletonList(output); @@ -69,20 +69,20 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay { public @NotNull ResourceLocation getRecipeCategory() { return AlloyingRecipe.ID; } - + @Override public @NotNull List> getRequiredEntries() { return this.input; } - + public float getXp() { return this.xp; } - + public double getSmeltTime() { return this.smeltTime; } - + public Optional> getOptionalRecipe() { return Optional.ofNullable(recipe); } @@ -98,17 +98,14 @@ public class REIAlloyingDisplay implements TransferRecipeDisplay { } @Override - public List> getOrganisedInputEntries(ContainerInfo containerInfo, - ScreenHandler container) { + public List> getOrganisedInputEntries(ContainerInfo containerInfo, AbstractContainerMenu container) { return this.input; } - + static { - fuel = EndStoneSmelterBlockEntity.availableFuels().keySet().stream().map(Item::getDefaultStack) - .map(EntryStack::create) - .map(e -> e.setting(EntryStack.Properties.TOOLTIP_APPEND_EXTRA, - stack -> Collections.singletonList( - new TranslatableText("category.rei.smelting.fuel").formatted(Formatting.YELLOW)))) - .collect(Collectors.toList()); + fuel = EndStoneSmelterBlockEntity.availableFuels().keySet().stream() + .map(Item::getDefaultInstance).map(EntryStack::create) + .map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableComponent("category.rei.smelting.fuel") + .withStyle(ChatFormatting.YELLOW)))).collect(Collectors.toList()); } } diff --git a/src/main/java/ru/betterend/integration/rei/REIAlloyingFuelCategory.java b/src/main/java/ru/betterend/integration/rei/REIAlloyingFuelCategory.java index 7b5b8195..10c7564c 100644 --- a/src/main/java/ru/betterend/integration/rei/REIAlloyingFuelCategory.java +++ b/src/main/java/ru/betterend/integration/rei/REIAlloyingFuelCategory.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.google.common.collect.Lists; - +import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.EntryStack; @@ -18,11 +18,10 @@ import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.widget.Widget; import net.minecraft.client.Minecraft; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.world.item.Items; -import net.minecraft.text.TranslatableText; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Items; public class REIAlloyingFuelCategory implements RecipeCategory { private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); @@ -34,7 +33,7 @@ public class REIAlloyingFuelCategory implements RecipeCategory widgets = Lists.newArrayList(); widgets.add(Widgets.createRecipeBase(bounds)); - widgets.add(Widgets - .createLabel(new Point(bounds.x + 26, bounds.getMaxY() - 15), - new TranslatableText("category.rei.fuel.time", burnTime)) + widgets.add(Widgets.createLabel(new Point(bounds.x + 26, bounds.getMaxY() - 15), new TranslatableComponent("category.rei.fuel.time", burnTime)) .color(0xFF404040, 0xFFBBBBBB).noShadow().leftAligned()); - widgets.add(Widgets.createBurningFire(new Point(bounds.x + 6, startPoint.y + 1)) - .animationDurationTicks(recipeDisplay.getFuelTime())); - widgets.add(Widgets.createSlot(new Point(bounds.x + 6, startPoint.y + 18)) - .entries(recipeDisplay.getInputEntries().get(0)).markInput()); + widgets.add(Widgets.createBurningFire(new Point(bounds.x + 6, startPoint.y + 1)).animationDurationTicks(recipeDisplay.getFuelTime())); + widgets.add(Widgets.createSlot(new Point(bounds.x + 6, startPoint.y + 18)).entries(recipeDisplay.getInputEntries().get(0)).markInput()); return widgets; } @Override public @NotNull RecipeEntry getSimpleRenderer(REIAlloyingFuelDisplay recipe) { - Slot slot = Widgets.createSlot(new Point(0, 0)).entries(recipe.getInputEntries().get(0)).disableBackground() - .disableHighlight(); + Slot slot = Widgets.createSlot(new Point(0, 0)).entries(recipe.getInputEntries().get(0)).disableBackground().disableHighlight(); String burnItems = DECIMAL_FORMAT.format(recipe.getFuelTime() / 200d); return new RecipeEntry() { - private TranslatableText text = new TranslatableText("category.rei.fuel.time_short.items", burnItems); + private TranslatableComponent text = new TranslatableComponent("category.rei.fuel.time_short.items", burnItems); @Override public int getHeight() { @@ -86,12 +80,11 @@ public class REIAlloyingFuelCategory implements RecipeCategory @Override public @NotNull String getCategoryName() { - return LangUtil.translate(Blocks.ANVIL.getTranslationKey()); + return LangUtil.translate(Blocks.ANVIL.getDescriptionId()); } - + @Override public @NotNull EntryStack getLogo() { return REIPlugin.ANVILS[0]; } - + @Override public @NotNull List setupDisplay(REIAnvilDisplay display, Rectangle bounds) { Point startPoint = new Point(bounds.getCenterX() - 41, bounds.y + 10); @@ -65,40 +64,34 @@ public class REIAnvilCategory implements TransferRecipeCategory }).collect(Collectors.toList()); materials.forEach(entryStack -> entryStack.setAmount(display.getInputCount())); widgets.add(Widgets.createArrow(new Point(x + 24, y + 4))); - widgets.add(Widgets - .createLabel(new Point(bounds.x + bounds.width - 7, bounds.y + bounds.height - 15), - new TranslatableText("category.rei.damage.amount&dmg", display.getDamage())) - .noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); + widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 7, bounds.y + bounds.height - 15), + new TranslatableComponent("category.rei.damage.amount&dmg", display.getDamage())).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); widgets.add(Widgets.createSlot(new Point(x - 20, y + 4)).entries(materials).markInput()); widgets.add(Widgets.createSlot(new Point(x + 1, y + 4)).entries(inputEntries.get(0)).markInput()); - widgets.add(Widgets.createSlot(new Point(x + 61, y + 5)).entries(display.getResultingEntries().get(0)) - .disableBackground().markOutput()); + widgets.add(Widgets.createSlot(new Point(x + 61, y + 5)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput()); widgets.add(Widgets.createSlot(new Point(x - 9, y + 25)).entries(anvils)); return widgets; } @Override - public void renderRedSlots(MatrixStack matrices, List widgets, Rectangle bounds, REIAnvilDisplay display, + public void renderRedSlots(PoseStack matrices, List widgets, Rectangle bounds, REIAnvilDisplay display, IntList redSlots) { Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 27); - matrices.push(); + matrices.pushPose(); matrices.translate(0, 0, 400); if (redSlots.contains(0)) { - DrawableHelper.fill(matrices, startPoint.x - 20, startPoint.y + 3, startPoint.x - 20 + 16, - startPoint.y + 3 + 16, 1090453504); - DrawableHelper.fill(matrices, startPoint.x + 1, startPoint.y + 3, startPoint.x + 1 + 16, - startPoint.y + 3 + 16, 1090453504); + GuiComponent.fill(matrices, startPoint.x - 20, startPoint.y + 3, startPoint.x - 20 + 16, startPoint.y + 3 + 16, 1090453504); + GuiComponent.fill(matrices, startPoint.x + 1, startPoint.y + 3, startPoint.x + 1 + 16, startPoint.y + 3 + 16, 1090453504); } - matrices.pop(); + matrices.popPose(); } - + @Override public @NotNull RecipeEntry getSimpleRenderer(REIAnvilDisplay recipe) { - return SimpleRecipeEntry.from(Collections.singletonList(recipe.getInputEntries().get(0)), - recipe.getResultingEntries()); + return SimpleRecipeEntry.from(Collections.singletonList(recipe.getInputEntries().get(0)), recipe.getResultingEntries()); } - + @Override public int getDisplayHeight() { return 60; diff --git a/src/main/java/ru/betterend/integration/rei/REIAnvilDisplay.java b/src/main/java/ru/betterend/integration/rei/REIAnvilDisplay.java index 2da35b4d..3ca2f929 100644 --- a/src/main/java/ru/betterend/integration/rei/REIAnvilDisplay.java +++ b/src/main/java/ru/betterend/integration/rei/REIAnvilDisplay.java @@ -9,23 +9,23 @@ import org.jetbrains.annotations.NotNull; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.TransferRecipeDisplay; import me.shedaniel.rei.server.ContainerInfo; -import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.screen.ScreenHandler; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.crafting.Recipe; import ru.betterend.recipe.builders.AnvilRecipe; public class REIAnvilDisplay implements TransferRecipeDisplay { - + private final AnvilRecipe recipe; private final List> input; private final List output; - + public REIAnvilDisplay(AnvilRecipe recipe) { this.recipe = recipe; - this.input = EntryStack.ofIngredients(recipe.getPreviewInputs()); - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.input = EntryStack.ofIngredients(recipe.getIngredients()); + this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem())); } - + public int getDamage() { return recipe.getDamage(); } @@ -37,7 +37,7 @@ public class REIAnvilDisplay implements TransferRecipeDisplay { public int getAnvilLevel() { return recipe.getAnvilLevel(); } - + @Override public @NotNull Optional getRecipeLocation() { return Optional.ofNullable(recipe).map(Recipe::getId); @@ -47,7 +47,7 @@ public class REIAnvilDisplay implements TransferRecipeDisplay { public @NotNull List> getInputEntries() { return this.input; } - + @Override public @NotNull List> getResultingEntries() { return Collections.singletonList(output); @@ -57,7 +57,7 @@ public class REIAnvilDisplay implements TransferRecipeDisplay { public @NotNull ResourceLocation getRecipeCategory() { return REIPlugin.SMITHING; } - + @Override public @NotNull List> getRequiredEntries() { return input; @@ -74,8 +74,8 @@ public class REIAnvilDisplay implements TransferRecipeDisplay { } @Override - public List> getOrganisedInputEntries(ContainerInfo containerInfo, - ScreenHandler container) { + public List> getOrganisedInputEntries(ContainerInfo containerInfo, + AbstractContainerMenu container) { return input; } } diff --git a/src/main/java/ru/betterend/integration/rei/REIInfusionCategory.java b/src/main/java/ru/betterend/integration/rei/REIInfusionCategory.java index d7ea7884..210d838f 100644 --- a/src/main/java/ru/betterend/integration/rei/REIInfusionCategory.java +++ b/src/main/java/ru/betterend/integration/rei/REIInfusionCategory.java @@ -5,7 +5,7 @@ import java.util.List; import org.jetbrains.annotations.NotNull; import com.google.common.collect.Lists; - +import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -15,8 +15,7 @@ import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; import me.shedaniel.rei.gui.widget.Widget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.TranslatableText; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import ru.betterend.BetterEnd; import ru.betterend.recipe.builders.InfusionRecipe; @@ -24,7 +23,7 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.util.LangUtil; public class REIInfusionCategory implements TransferRecipeCategory { - + private final static ResourceLocation BACKGROUND = BetterEnd.makeID("textures/gui/rei_infusion.png"); @Override @@ -34,19 +33,19 @@ public class REIInfusionCategory implements TransferRecipeCategory setupDisplay(REIInfusionDisplay display, Rectangle bounds) { Point centerPoint = new Point(bounds.getCenterX() - 34, bounds.getCenterY() - 2); @@ -56,36 +55,24 @@ public class REIInfusionCategory implements TransferRecipeCategory> outputEntries = display.getResultingEntries(); widgets.add(Widgets.createTexturedWidget(BACKGROUND, bounds.x, bounds.y, 0, 0, 150, 104, 150, 104)); widgets.add(Widgets.createSlot(centerPoint).entries(inputEntries.get(0)).disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x, centerPoint.y - 28)).entries(inputEntries.get(1)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x + 28, centerPoint.y)).entries(inputEntries.get(3)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x, centerPoint.y + 28)).entries(inputEntries.get(5)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x - 28, centerPoint.y)).entries(inputEntries.get(7)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x + 24, centerPoint.y - 24)).entries(inputEntries.get(2)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x + 24, centerPoint.y + 24)).entries(inputEntries.get(4)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x - 24, centerPoint.y + 24)).entries(inputEntries.get(6)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x - 24, centerPoint.y - 24)).entries(inputEntries.get(8)) - .disableBackground().markInput()); - widgets.add(Widgets.createSlot(new Point(centerPoint.x + 80, centerPoint.y)).entries(outputEntries.get(0)) - .disableBackground().markOutput()); - widgets.add(Widgets - .createLabel(new Point(bounds.getMaxX() - 5, bounds.y + 6), - new TranslatableText("category.rei.infusion.time&val", display.getInfusionTime())) + widgets.add(Widgets.createSlot(new Point(centerPoint.x, centerPoint.y - 28)).entries(inputEntries.get(1)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x + 28, centerPoint.y)).entries(inputEntries.get(3)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x, centerPoint.y + 28)).entries(inputEntries.get(5)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x - 28, centerPoint.y)).entries(inputEntries.get(7)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x + 24, centerPoint.y - 24)).entries(inputEntries.get(2)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x + 24, centerPoint.y + 24)).entries(inputEntries.get(4)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x - 24, centerPoint.y + 24)).entries(inputEntries.get(6)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x - 24, centerPoint.y - 24)).entries(inputEntries.get(8)).disableBackground().markInput()); + widgets.add(Widgets.createSlot(new Point(centerPoint.x + 80, centerPoint.y)).entries(outputEntries.get(0)).disableBackground().markOutput()); + widgets.add(Widgets.createLabel(new Point(bounds.getMaxX() - 5, bounds.y + 6), new TranslatableComponent("category.rei.infusion.time&val", display.getInfusionTime())) .noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); return widgets; } @Override - public void renderRedSlots(MatrixStack matrices, List widgets, Rectangle bounds, REIInfusionDisplay display, - IntList redSlots) { - } - + public void renderRedSlots(PoseStack matrices, List widgets, Rectangle bounds, + REIInfusionDisplay display, IntList redSlots) {} + @Override public int getDisplayHeight() { return 104; diff --git a/src/main/java/ru/betterend/integration/rei/REIInfusionDisplay.java b/src/main/java/ru/betterend/integration/rei/REIInfusionDisplay.java index 86313c99..d8411bc9 100644 --- a/src/main/java/ru/betterend/integration/rei/REIInfusionDisplay.java +++ b/src/main/java/ru/betterend/integration/rei/REIInfusionDisplay.java @@ -11,34 +11,34 @@ import com.google.common.collect.Lists; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.TransferRecipeDisplay; import me.shedaniel.rei.server.ContainerInfo; -import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.screen.ScreenHandler; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.crafting.Recipe; import ru.betterend.recipe.builders.AlloyingRecipe; import ru.betterend.recipe.builders.InfusionRecipe; public class REIInfusionDisplay implements TransferRecipeDisplay { - + private final InfusionRecipe recipe; private final List> input; private final List output; private final int time; - + public REIInfusionDisplay(InfusionRecipe recipe) { this.recipe = recipe; this.input = Lists.newArrayList(); - this.output = Collections.singletonList(EntryStack.create(recipe.getOutput())); + this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem())); this.time = recipe.getInfusionTime(); - - recipe.getPreviewInputs().forEach(ingredient -> { + + recipe.getIngredients().forEach(ingredient -> { input.add(EntryStack.ofIngredient(ingredient)); }); } - + public int getInfusionTime() { return this.time; } - + @Override public @NotNull Optional getRecipeLocation() { return Optional.ofNullable(recipe).map(Recipe::getId); @@ -48,7 +48,7 @@ public class REIInfusionDisplay implements TransferRecipeDisplay { public @NotNull List> getInputEntries() { return this.input; } - + @Override public @NotNull List> getResultingEntries() { return Collections.singletonList(output); @@ -58,7 +58,7 @@ public class REIInfusionDisplay implements TransferRecipeDisplay { public @NotNull ResourceLocation getRecipeCategory() { return AlloyingRecipe.ID; } - + @Override public @NotNull List> getRequiredEntries() { return this.input; @@ -75,8 +75,7 @@ public class REIInfusionDisplay implements TransferRecipeDisplay { } @Override - public List> getOrganisedInputEntries(ContainerInfo containerInfo, - ScreenHandler container) { + public List> getOrganisedInputEntries(ContainerInfo containerInfo, AbstractContainerMenu container) { return this.input; } } diff --git a/src/main/java/ru/betterend/integration/rei/REIPlugin.java b/src/main/java/ru/betterend/integration/rei/REIPlugin.java index 3232fd8e..8ac01152 100644 --- a/src/main/java/ru/betterend/integration/rei/REIPlugin.java +++ b/src/main/java/ru/betterend/integration/rei/REIPlugin.java @@ -12,10 +12,10 @@ import me.shedaniel.rei.plugin.DefaultPlugin; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.content.registry.FuelRegistryImpl; -import net.minecraft.world.level.block.Blocks; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.crafting.BlastingRecipe; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Blocks; import ru.betterend.BetterEnd; import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.blocks.basis.EndFurnaceBlock; @@ -43,9 +43,9 @@ public class REIPlugin implements REIPluginV0 { public ResourceLocation getPluginIdentifier() { return PLUGIN_ID; } - + @Override - public void registerRecipeDisplays(RecipeHelper recipeHelper) { + public void registerRecipeDisplays(RecipeHelper recipeHelper) { recipeHelper.registerRecipes(ALLOYING, AlloyingRecipe.class, REIAlloyingDisplay::new); recipeHelper.registerRecipes(ALLOYING, BlastingRecipe.class, REIAlloyingDisplay::new); recipeHelper.registerRecipes(SMITHING, AnvilRecipe.class, REIAnvilDisplay::new); @@ -56,7 +56,7 @@ public class REIPlugin implements REIPluginV0 { } }); } - + @Override public void registerOthers(RecipeHelper recipeHelper) { recipeHelper.registerWorkingStations(ALLOYING_FUEL, END_STONE_SMELTER); @@ -68,12 +68,15 @@ public class REIPlugin implements REIPluginV0 { recipeHelper.registerWorkingStations(DefaultPlugin.SMELTING, FURNACES); recipeHelper.registerWorkingStations(DefaultPlugin.FUEL, FURNACES); - } - + } + @Override public void registerPluginCategories(RecipeHelper recipeHelper) { - recipeHelper.registerCategories(new REIAlloyingFuelCategory(), new REIAlloyingCategory(), - new REIInfusionCategory(), new REIAnvilCategory()); + recipeHelper.registerCategories( + new REIAlloyingFuelCategory(), + new REIAlloyingCategory(), + new REIInfusionCategory(), + new REIAnvilCategory()); } static { diff --git a/src/main/java/ru/betterend/interfaces/IBiomeList.java b/src/main/java/ru/betterend/interfaces/IBiomeList.java index 4dbbfde4..e7546aa6 100644 --- a/src/main/java/ru/betterend/interfaces/IBiomeList.java +++ b/src/main/java/ru/betterend/interfaces/IBiomeList.java @@ -1,7 +1,6 @@ package ru.betterend.interfaces; import java.util.List; - import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; diff --git a/src/main/java/ru/betterend/interfaces/IColorProvider.java b/src/main/java/ru/betterend/interfaces/IColorProvider.java index 2c0100da..f8b5ba51 100644 --- a/src/main/java/ru/betterend/interfaces/IColorProvider.java +++ b/src/main/java/ru/betterend/interfaces/IColorProvider.java @@ -4,6 +4,7 @@ import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.item.ItemColor; public interface IColorProvider { - BlockColor getBlockProvider(); + BlockColor getProvider(); + ItemColor getItemProvider(); } diff --git a/src/main/java/ru/betterend/interfaces/IRenderTypeable.java b/src/main/java/ru/betterend/interfaces/IRenderTypeable.java index 96f961ba..1a5c029c 100644 --- a/src/main/java/ru/betterend/interfaces/IRenderTypeable.java +++ b/src/main/java/ru/betterend/interfaces/IRenderTypeable.java @@ -4,5 +4,5 @@ import ru.betterend.client.render.ERenderLayer; public interface IRenderTypeable { - ERenderLayer getRenderLayer(); + public ERenderLayer getRenderLayer(); } diff --git a/src/main/java/ru/betterend/interfaces/TeleportingEntity.java b/src/main/java/ru/betterend/interfaces/TeleportingEntity.java index f339e736..29a6c466 100644 --- a/src/main/java/ru/betterend/interfaces/TeleportingEntity.java +++ b/src/main/java/ru/betterend/interfaces/TeleportingEntity.java @@ -4,8 +4,6 @@ import net.minecraft.core.BlockPos; public interface TeleportingEntity { void beSetExitPos(BlockPos pos); - void beResetExitPos(); - boolean beCanTeleport(); } diff --git a/src/main/java/ru/betterend/item/DrinkItem.java b/src/main/java/ru/betterend/item/DrinkItem.java index 8969fb96..50e4ad1a 100644 --- a/src/main/java/ru/betterend/item/DrinkItem.java +++ b/src/main/java/ru/betterend/item/DrinkItem.java @@ -1,16 +1,16 @@ package ru.betterend.item; -import net.minecraft.advancement.criterion.Criteria; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.ItemUsage; +import net.minecraft.world.item.ItemUtils; import net.minecraft.world.item.Items; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.stat.Stats; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.UseAction; +import net.minecraft.world.item.UseAnim; import net.minecraft.world.level.Level; public class DrinkItem extends PatternedItem { @@ -19,34 +19,34 @@ public class DrinkItem extends PatternedItem { } @Override - public int getMaxUseTime(ItemStack stack) { + public int getUseDuration(ItemStack stack) { return 32; } @Override - public UseAction getUseAction(ItemStack stack) { - return UseAction.DRINK; + public UseAnim getUseAnimation(ItemStack stack) { + return UseAnim.DRINK; } @Override - public TypedActionResult use(Level world, Player user, Hand hand) { - return ItemUsage.consumeHeldItem(world, user, hand); + public InteractionResultHolder use(Level world, Player user, InteractionHand hand) { + return ItemUtils.useDrink(world, user, hand); } @Override - public ItemStack finishUsing(ItemStack stack, Level world, LivingEntity user) { + public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) { if (user instanceof ServerPlayer) { ServerPlayer serverPlayerEntity = (ServerPlayer) user; - Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack); - serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this)); + CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayerEntity, stack); + serverPlayerEntity.awardStat(Stats.ITEM_USED.get(this)); } - if (user instanceof Player && !((Player) user).abilities.creativeMode) { - stack.decrement(1); + if (user instanceof Player && !((Player) user).abilities.instabuild) { + stack.shrink(1); } if (!world.isClientSide) { - user.clearMobEffects(); + user.removeAllEffects(); } return stack.isEmpty() ? new ItemStack(Items.GLASS_BOTTLE) : stack; diff --git a/src/main/java/ru/betterend/item/EnchantedPetalItem.java b/src/main/java/ru/betterend/item/EnchantedPetalItem.java index c34d07d2..27d04935 100644 --- a/src/main/java/ru/betterend/item/EnchantedPetalItem.java +++ b/src/main/java/ru/betterend/item/EnchantedPetalItem.java @@ -11,10 +11,10 @@ public class EnchantedPetalItem extends PatternedItem { } @Override - public boolean hasGlint(ItemStack stack) { + public boolean isFoil(ItemStack stack) { return true; } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_GENERATED, "item/hydralux_petal"); diff --git a/src/main/java/ru/betterend/item/EndArmorItem.java b/src/main/java/ru/betterend/item/EndArmorItem.java index 3c56b9b6..4c98eb68 100644 --- a/src/main/java/ru/betterend/item/EndArmorItem.java +++ b/src/main/java/ru/betterend/item/EndArmorItem.java @@ -1,17 +1,15 @@ package ru.betterend.item; import java.util.UUID; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.entity.attribute.Attributes; +import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.Item; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; import ru.betterend.mixin.common.ArmorItemAccessor; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; @@ -24,8 +22,7 @@ public class EndArmorItem extends ArmorItem implements Patterned { } /** Ensures knockback resistance is actually applied */ - private static void addKnockbackResistance(ArmorItemAccessor accessor, EquipmentSlot slot, - double knockbackResistance) { + private static void addKnockbackResistance(ArmorItemAccessor accessor, EquipmentSlot slot, double knockbackResistance) { if (knockbackResistance == 0) { return; } @@ -37,13 +34,12 @@ public class EndArmorItem extends ArmorItem implements Patterned { return; } - UUID uuid = accessor.be_getModifiers()[slot.getEntitySlotId()]; + UUID uuid = accessor.be_getModifiers()[slot.getIndex()]; // Rebuild attributeModifiers to include knockback resistance ImmutableMultimap.Builder builder = ImmutableMultimap.builder(); builder.putAll(attributeModifiers); - builder.put(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(uuid, "Armor knockback resistance", - knockbackResistance, AttributeModifier.Operation.ADDITION)); + builder.put(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(uuid, "Armor knockback resistance", knockbackResistance, AttributeModifier.Operation.ADDITION)); accessor.be_setAttributeModifiers(builder.build()); } diff --git a/src/main/java/ru/betterend/item/EndSpawnEggItem.java b/src/main/java/ru/betterend/item/EndSpawnEggItem.java index 419136ec..cf2d2e35 100644 --- a/src/main/java/ru/betterend/item/EndSpawnEggItem.java +++ b/src/main/java/ru/betterend/item/EndSpawnEggItem.java @@ -9,7 +9,7 @@ public class EndSpawnEggItem extends SpawnEggItem implements Patterned { public EndSpawnEggItem(EntityType type, int primaryColor, int secondaryColor, Properties settings) { super(type, primaryColor, secondaryColor, settings); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_SPAWN_EGG, name); diff --git a/src/main/java/ru/betterend/item/GuideBookItem.java b/src/main/java/ru/betterend/item/GuideBookItem.java index bb137c11..e60d441c 100644 --- a/src/main/java/ru/betterend/item/GuideBookItem.java +++ b/src/main/java/ru/betterend/item/GuideBookItem.java @@ -1,17 +1,16 @@ package ru.betterend.item; import java.util.List; - -import net.minecraft.client.item.TooltipContext; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Hand; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.TypedActionResult; +import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.Level; import ru.betterend.BetterEnd; import ru.betterend.registry.EndItems; @@ -19,28 +18,26 @@ import ru.betterend.util.LangUtil; import vazkii.patchouli.api.PatchouliAPI; public class GuideBookItem extends PatternedItem { - public final static ResourceLocation BOOK_ID = BetterEnd.makeID("guidebook"); - public static final Item GUIDE_BOOK = EndItems.registerItem(BOOK_ID, new GuideBookItem()); - - public static void register() { - } - - public GuideBookItem() { - super(EndItems.makeItemSettings().stacksTo(1)); - } - + public final static ResourceLocation BOOK_ID = BetterEnd.makeID("guidebook"); + public static final Item GUIDE_BOOK = EndItems.registerItem(BOOK_ID, new GuideBookItem()); + + public static void register() {} + + public GuideBookItem() { + super(EndItems.makeItemSettings().stacksTo(1)); + } + @Override - public TypedActionResult use(Level world, Player user, Hand hand) { - if (!world.isClientSide && user instanceof ServerPlayer) { + public InteractionResultHolder use(Level world, Player user, InteractionHand hand) { + if (!world.isClientSide && user instanceof ServerPlayer) { PatchouliAPI.get().openBookGUI((ServerPlayer) user, BOOK_ID); - return TypedActionResult.success(user.getStackInHand(hand)); + return InteractionResultHolder.success(user.getItemInHand(hand)); } - return TypedActionResult.consume(user.getStackInHand(hand)); + return InteractionResultHolder.consume(user.getItemInHand(hand)); } @Override - public void appendTooltip(ItemStack stack, Level world, List tooltip, TooltipContext context) { - tooltip.add( - LangUtil.getText("book.betterend", "subtitle").formatted(Formatting.DARK_PURPLE, Formatting.ITALIC)); + public void appendHoverText(ItemStack stack, Level world, List tooltip, TooltipFlag context) { + tooltip.add(LangUtil.getText("book.betterend", "subtitle").withStyle(ChatFormatting.DARK_PURPLE, ChatFormatting.ITALIC)); } } diff --git a/src/main/java/ru/betterend/item/PatternedDiscItem.java b/src/main/java/ru/betterend/item/PatternedDiscItem.java index 0abf6154..44a32123 100644 --- a/src/main/java/ru/betterend/item/PatternedDiscItem.java +++ b/src/main/java/ru/betterend/item/PatternedDiscItem.java @@ -1,13 +1,12 @@ package ru.betterend.item; -import net.minecraft.world.item.Item; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.RecordItem; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; public class PatternedDiscItem extends RecordItem implements Patterned { - public PatternedDiscItem(int comparatorOutput, SoundEvent sound, Item.Properties settings) { + public PatternedDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) { super(comparatorOutput, sound, settings); } diff --git a/src/main/java/ru/betterend/item/PatternedItem.java b/src/main/java/ru/betterend/item/PatternedItem.java index de970bb6..c25d9c6d 100644 --- a/src/main/java/ru/betterend/item/PatternedItem.java +++ b/src/main/java/ru/betterend/item/PatternedItem.java @@ -8,7 +8,7 @@ public class PatternedItem extends Item implements Patterned { public PatternedItem(Properties settings) { super(settings); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_GENERATED, name); diff --git a/src/main/java/ru/betterend/item/material/EndArmorMaterial.java b/src/main/java/ru/betterend/item/material/EndArmorMaterial.java index 78bb7352..13358a76 100644 --- a/src/main/java/ru/betterend/item/material/EndArmorMaterial.java +++ b/src/main/java/ru/betterend/item/material/EndArmorMaterial.java @@ -4,25 +4,26 @@ import java.util.function.Supplier; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.util.LazyLoadedValue; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.crafting.Ingredient; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public enum EndArmorMaterial implements ArmorMaterial { - THALLASIUM("thallasium", 17, new int[] { 1, 4, 5, 2 }, 12, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> { + THALLASIUM("thallasium", 17, new int[] { 1, 4, 5, 2 }, 12, SoundEvents.ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> { return Ingredient.of(EndBlocks.THALLASIUM.ingot); - }), TERMINITE("terminite", 26, new int[] { 3, 6, 7, 3 }, 14, SoundEvents.ITEM_ARMOR_EQUIP_IRON, 1.0F, 0.05F, () -> { + }), + TERMINITE("terminite", 26, new int[] { 3, 6, 7, 3 }, 14, SoundEvents.ARMOR_EQUIP_IRON, 1.0F, 0.05F, () -> { return Ingredient.of(EndBlocks.TERMINITE.ingot); }), - AETERNIUM("aeternium", 40, new int[] { 4, 7, 9, 4 }, 18, SoundEvents.ITEM_ARMOR_EQUIP_NETHERITE, 3.5F, 0.2F, () -> { + AETERNIUM("aeternium", 40, new int[] { 4, 7, 9, 4 }, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.5F, 0.2F, () -> { return Ingredient.of(EndItems.AETERNIUM_INGOT); }), - CRYSTALITE("crystalite", 30, new int[] { 3, 6, 8, 3 }, 24, SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 1.2F, 0.1F, () -> { + CRYSTALITE("crystalite", 30, new int[] { 3, 6, 8, 3 }, 24, SoundEvents.ARMOR_EQUIP_DIAMOND, 1.2F, 0.1F, () -> { return Ingredient.of(EndBlocks.TERMINITE.ingot); }); @@ -35,10 +36,11 @@ public enum EndArmorMaterial implements ArmorMaterial { private final float toughness; private final float knockbackResistance; private final LazyLoadedValue repairIngredient; - + private EndArmorMaterial(String name, int durabilityMultiplier, int[] protectionAmounts, int enchantability, - SoundEvent equipSound, float toughness, float knockbackResistance, Supplier repairIngredient) { - + SoundEvent equipSound, float toughness, float knockbackResistance, + Supplier repairIngredient) { + this.name = name; this.durabilityMultiplier = durabilityMultiplier; this.protectionAmounts = protectionAmounts; @@ -50,17 +52,17 @@ public enum EndArmorMaterial implements ArmorMaterial { } @Override - public int getDurability(EquipmentSlot slot) { - return BASE_DURABILITY[slot.getEntitySlotId()] * this.durabilityMultiplier; + public int getDurabilityForSlot(EquipmentSlot slot) { + return BASE_DURABILITY[slot.getIndex()] * this.durabilityMultiplier; } @Override - public int getProtectionAmount(EquipmentSlot slot) { - return this.protectionAmounts[slot.getEntitySlotId()]; + public int getDefenseForSlot(EquipmentSlot slot) { + return this.protectionAmounts[slot.getIndex()]; } @Override - public int getEnchantability() { + public int getEnchantmentValue() { return this.enchantability; } diff --git a/src/main/java/ru/betterend/item/material/EndToolMaterial.java b/src/main/java/ru/betterend/item/material/EndToolMaterial.java index 151e683e..b132224c 100644 --- a/src/main/java/ru/betterend/item/material/EndToolMaterial.java +++ b/src/main/java/ru/betterend/item/material/EndToolMaterial.java @@ -1,7 +1,6 @@ package ru.betterend.item.material; import java.util.function.Supplier; - import net.minecraft.util.LazyLoadedValue; import net.minecraft.world.item.Tier; import net.minecraft.world.item.crafting.Ingredient; @@ -11,9 +10,11 @@ import ru.betterend.registry.EndItems; public enum EndToolMaterial implements Tier { THALLASIUM(2, 320, 7.0F, 1.5F, 12, () -> { return Ingredient.of(EndBlocks.THALLASIUM.ingot); - }), TERMINITE(3, 1230, 8.5F, 3.0F, 14, () -> { + }), + TERMINITE(3, 1230, 8.5F, 3.0F, 14, () -> { return Ingredient.of(EndBlocks.TERMINITE.ingot); - }), AETERNIUM(5, 2196, 10.0F, 4.5F, 18, () -> { + }), + AETERNIUM(5, 2196, 10.0F, 4.5F, 18, () -> { return Ingredient.of(EndItems.AETERNIUM_INGOT); }); @@ -23,7 +24,7 @@ public enum EndToolMaterial implements Tier { private final int miningLevel; private final int enchantability; private final LazyLoadedValue repairIngredient; - + private EndToolMaterial(int miningLevel, int durability, float miningSpeed, float attackDamage, int enchantability, Supplier repairIngredient) { @@ -37,27 +38,27 @@ public enum EndToolMaterial implements Tier { @Override public int getUses() { - return durability; + return this.durability; } @Override public float getSpeed() { - return miningSpeed; + return this.miningSpeed; } @Override public float getAttackDamageBonus() { - return attackDamage; + return this.attackDamage; } @Override public int getLevel() { - return miningLevel; + return this.miningLevel; } @Override public int getEnchantmentValue() { - return enchantability; + return this.enchantability; } @Override diff --git a/src/main/java/ru/betterend/item/model/CrystaliteArmorProvider.java b/src/main/java/ru/betterend/item/model/CrystaliteArmorProvider.java index 4073824f..28e02a03 100644 --- a/src/main/java/ru/betterend/item/model/CrystaliteArmorProvider.java +++ b/src/main/java/ru/betterend/item/model/CrystaliteArmorProvider.java @@ -9,75 +9,71 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.rendering.v1.ArmorRenderingRegistry.ModelProvider; import net.fabricmc.fabric.api.client.rendering.v1.ArmorRenderingRegistry.TextureProvider; -import net.minecraft.client.network.AbstractClientPlayerEntity; -import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.resources.ResourceLocation; import ru.betterend.registry.EndItems; @Environment(EnvType.CLIENT) public class CrystaliteArmorProvider implements ModelProvider, TextureProvider { - private final static ResourceLocation FIRST_LAYER = new ResourceLocation( - "textures/models/armor/crystalite_layer_1.png"); - private final static ResourceLocation SECOND_LAYER = new ResourceLocation( - "textures/models/armor/crystalite_layer_2.png"); + private final static ResourceLocation FIRST_LAYER = new ResourceLocation("textures/models/armor/crystalite_layer_1.png"); + private final static ResourceLocation SECOND_LAYER = new ResourceLocation("textures/models/armor/crystalite_layer_2.png"); private final static CrystaliteHelmetModel HELMET_MODEL = new CrystaliteHelmetModel(1.0F); private final static CrystaliteChestplateModel CHEST_MODEL = new CrystaliteChestplateModel(1.0F, false); private final static CrystaliteChestplateModel CHEST_MODEL_SLIM = new CrystaliteChestplateModel(1.0F, true); private final static CrystaliteLeggingsModel LEGGINGS_MODEL = new CrystaliteLeggingsModel(1.0F); private final static CrystaliteBootsModel BOOTS_MODEL = new CrystaliteBootsModel(1.0F); - + @Override public @NotNull ResourceLocation getArmorTexture(LivingEntity entity, ItemStack stack, EquipmentSlot slot, boolean secondLayer, @Nullable String suffix, ResourceLocation defaultTexture) { - if (!isStackValid(stack)) - return defaultTexture; - if (secondLayer) - return SECOND_LAYER; + if (!isStackValid(stack)) return defaultTexture; + if (secondLayer) return SECOND_LAYER; return FIRST_LAYER; } @Override - public @NotNull BipedEntityModel getArmorModel(LivingEntity entity, ItemStack stack, - EquipmentSlot slot, BipedEntityModel defaultModel) { - if (!isStackValid(stack)) - return defaultModel; - switch (slot) { - case HEAD: { - return HELMET_MODEL; - } - case CHEST: { - if (entity instanceof AbstractClientPlayerEntity - && ((AbstractClientPlayerEntity) entity).getModel().equals("slim")) { - CHEST_MODEL_SLIM.setAttributes(defaultModel); - return CHEST_MODEL_SLIM; + public @NotNull HumanoidModel getArmorModel(LivingEntity entity, ItemStack stack, + EquipmentSlot slot, HumanoidModel defaultModel) { + if (!isStackValid(stack)) return defaultModel; + switch(slot) { + case HEAD: { + return HELMET_MODEL; + } + case CHEST: { + if (entity instanceof AbstractClientPlayer && + ((AbstractClientPlayer) entity).getModelName().equals("slim")) { + CHEST_MODEL_SLIM.copyPropertiesTo(defaultModel); + return CHEST_MODEL_SLIM; + } + CHEST_MODEL.copyPropertiesTo(defaultModel); + return CHEST_MODEL; + } + case LEGS: { + return LEGGINGS_MODEL; + } + case FEET: { + BOOTS_MODEL.copyPropertiesTo(defaultModel); + return BOOTS_MODEL; + } + default: { + return defaultModel; } - CHEST_MODEL.setAttributes(defaultModel); - return CHEST_MODEL; - } - case LEGS: { - return LEGGINGS_MODEL; - } - case FEET: { - BOOTS_MODEL.setAttributes(defaultModel); - return BOOTS_MODEL; - } - default: { - return defaultModel; - } } } - + public Iterable getRenderedItems() { - return Lists.newArrayList(EndItems.CRYSTALITE_HELMET, EndItems.CRYSTALITE_CHESTPLATE, - EndItems.CRYSTALITE_LEGGINGS, EndItems.CRYSTALITE_BOOTS); + return Lists.newArrayList(EndItems.CRYSTALITE_HELMET, EndItems.CRYSTALITE_CHESTPLATE, EndItems.CRYSTALITE_LEGGINGS, EndItems.CRYSTALITE_BOOTS); } - + private boolean isStackValid(ItemStack stack) { - return stack.getItem() == EndItems.CRYSTALITE_HELMET || stack.getItem() == EndItems.CRYSTALITE_CHESTPLATE - || stack.getItem() == EndItems.CRYSTALITE_LEGGINGS || stack.getItem() == EndItems.CRYSTALITE_BOOTS; + return stack.getItem() == EndItems.CRYSTALITE_HELMET || + stack.getItem() == EndItems.CRYSTALITE_CHESTPLATE || + stack.getItem() == EndItems.CRYSTALITE_LEGGINGS || + stack.getItem() == EndItems.CRYSTALITE_BOOTS; } } diff --git a/src/main/java/ru/betterend/item/model/CrystaliteBootsModel.java b/src/main/java/ru/betterend/item/model/CrystaliteBootsModel.java index 7b476aa5..82ef8a4b 100644 --- a/src/main/java/ru/betterend/item/model/CrystaliteBootsModel.java +++ b/src/main/java/ru/betterend/item/model/CrystaliteBootsModel.java @@ -1,43 +1,41 @@ package ru.betterend.item.model; import java.util.Collections; - +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.world.entity.LivingEntity; import com.google.common.collect.Lists; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.world.entity.LivingEntity; - -public class CrystaliteBootsModel extends BipedEntityModel { +public class CrystaliteBootsModel extends HumanoidModel { public ModelPart leftBoot; public ModelPart rightBoot; - + public CrystaliteBootsModel(float scale) { - super(RenderLayer::getEntityTranslucent, scale, 0.0F, 64, 48); + super(RenderType::entityTranslucent, scale, 0.0F, 64, 48); this.leftBoot = new ModelPart(this, 0, 32); - this.leftBoot.addCuboid(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.25F); - this.leftBoot.setPivot(1.9F, 12.0F, 0.0F); + this.leftBoot.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.25F); + this.leftBoot.setPos(1.9F, 12.0F, 0.0F); this.rightBoot = new ModelPart(this, 0, 16); - this.rightBoot.addCuboid(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.25F); - this.rightBoot.setPivot(-1.9F, 12.0F, 0.0F); + this.rightBoot.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.25F); + this.rightBoot.setPos(-1.9F, 12.0F, 0.0F); + } + + @Override + public void copyPropertiesTo(HumanoidModel bipedEntityModel) { + super.copyPropertiesTo(bipedEntityModel); + this.leftBoot.copyFrom(leftLeg); + this.rightBoot.copyFrom(rightLeg); } @Override - public void setAttributes(BipedEntityModel bipedEntityModel) { - super.setAttributes(bipedEntityModel); - this.leftBoot.copyPositionAndRotation(leftLeg); - this.rightBoot.copyPositionAndRotation(rightLeg); - } - - @Override - protected Iterable getHeadParts() { + protected Iterable headParts() { return Collections::emptyIterator; } - + @Override - protected Iterable getBodyParts() { + protected Iterable bodyParts() { return Lists.newArrayList(leftBoot, rightBoot); } } diff --git a/src/main/java/ru/betterend/item/model/CrystaliteChestplateModel.java b/src/main/java/ru/betterend/item/model/CrystaliteChestplateModel.java index 51b07d02..f33a27ef 100644 --- a/src/main/java/ru/betterend/item/model/CrystaliteChestplateModel.java +++ b/src/main/java/ru/betterend/item/model/CrystaliteChestplateModel.java @@ -1,74 +1,72 @@ package ru.betterend.item.model; import java.util.Collections; - -import com.google.common.collect.Lists; - -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.util.Arm; +import com.google.common.collect.Lists; +import com.mojang.blaze3d.vertex.PoseStack; -public class CrystaliteChestplateModel extends BipedEntityModel { +public class CrystaliteChestplateModel extends HumanoidModel { public ModelPart leftShoulder; public ModelPart rightShoulder; private boolean thinArms; - + public CrystaliteChestplateModel(float scale, boolean thinArms) { - super(RenderLayer::getEntityTranslucent, scale, 0.0F, 64, 48); + super(RenderType::entityTranslucent, scale, 0.0F, 64, 48); this.thinArms = thinArms; - this.torso = new ModelPart(this, 16, 16); - this.torso.addCuboid(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, scale + 0.25F); - this.torso.setPivot(0.0F, 0.0F, 0.0F); + this.body = new ModelPart(this, 16, 16); + this.body.addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, scale + 0.25F); + this.body.setPos(0.0F, 0.0F, 0.0F); if (thinArms) { this.leftShoulder = new ModelPart(this, 41, 32); - this.leftShoulder.addCuboid(-1.0F, -2.5F, -2.0F, 3.0F, 12.0F, 4.0F, scale + 0.35F); - this.leftShoulder.setPivot(5.0F, 2.5F, 0.0F); + this.leftShoulder.addBox(-1.0F, -2.5F, -2.0F, 3.0F, 12.0F, 4.0F, scale + 0.35F); + this.leftShoulder.setPos(5.0F, 2.5F, 0.0F); this.leftShoulder.mirror = true; this.rightShoulder = new ModelPart(this, 41, 16); - this.rightShoulder.addCuboid(-2.0F, -2.5F, -2.0F, 3.0F, 12.0F, 4.0F, scale + 0.35F); - this.rightShoulder.setPivot(-5.0F, 2.5F, 10.0F); + this.rightShoulder.addBox(-2.0F, -2.5F, -2.0F, 3.0F, 12.0F, 4.0F, scale + 0.35F); + this.rightShoulder.setPos(-5.0F, 2.5F, 10.0F); } else { this.leftShoulder = new ModelPart(this, 40, 32); - this.leftShoulder.addCuboid(-1.0F, -2.5F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.45F); - this.leftShoulder.setPivot(5.0F, 2.0F, 0.0F); + this.leftShoulder.addBox(-1.0F, -2.5F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.45F); + this.leftShoulder.setPos(5.0F, 2.0F, 0.0F); this.leftShoulder.mirror = true; this.rightShoulder = new ModelPart(this, 40, 16); - this.rightShoulder.addCuboid(-3.0F, -2.5F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.45F); - this.rightShoulder.setPivot(-5.0F, 2.0F, 10.0F); + this.rightShoulder.addBox(-3.0F, -2.5F, -2.0F, 4.0F, 12.0F, 4.0F, scale + 0.45F); + this.rightShoulder.setPos(-5.0F, 2.0F, 10.0F); } } - + @Override - public void setAttributes(BipedEntityModel bipedEntityModel) { - super.setAttributes(bipedEntityModel); - this.leftShoulder.copyPositionAndRotation(leftArm); - this.rightShoulder.copyPositionAndRotation(rightArm); + public void copyPropertiesTo(HumanoidModel bipedEntityModel) { + super.copyPropertiesTo(bipedEntityModel); + this.leftShoulder.copyFrom(leftArm); + this.rightShoulder.copyFrom(rightArm); } - + @Override - protected Iterable getHeadParts() { + protected Iterable headParts() { return Collections::emptyIterator; } - + @Override - protected Iterable getBodyParts() { - return Lists.newArrayList(torso, leftShoulder, rightShoulder); + protected Iterable bodyParts() { + return Lists.newArrayList(body, leftShoulder, rightShoulder); } - + @Override - public void setArmAngle(Arm arm, MatrixStack matrices) { + public void translateToHand(HumanoidArm arm, PoseStack matrices) { ModelPart modelPart = this.getArm(arm); if (this.thinArms) { - float f = 0.5F * (float) (arm == Arm.RIGHT ? 1 : -1); - modelPart.pivotX += f; - modelPart.rotate(matrices); - modelPart.pivotX -= f; + float f = 0.5F * (float)(arm == HumanoidArm.RIGHT ? 1 : -1); + modelPart.x += f; + modelPart.translateAndRotate(matrices); + modelPart.x -= f; } else { - modelPart.rotate(matrices); + modelPart.translateAndRotate(matrices); } } } diff --git a/src/main/java/ru/betterend/item/model/CrystaliteHelmetModel.java b/src/main/java/ru/betterend/item/model/CrystaliteHelmetModel.java index fc82b4e7..3513c2f4 100644 --- a/src/main/java/ru/betterend/item/model/CrystaliteHelmetModel.java +++ b/src/main/java/ru/betterend/item/model/CrystaliteHelmetModel.java @@ -6,28 +6,28 @@ import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; import net.minecraft.world.entity.LivingEntity; @Environment(EnvType.CLIENT) -public class CrystaliteHelmetModel extends BipedEntityModel { +public class CrystaliteHelmetModel extends HumanoidModel { public CrystaliteHelmetModel(float scale) { - super(RenderLayer::getEntityTranslucent, scale, 0.0F, 64, 48); - this.helmet = new ModelPart(this, 0, 0); - this.helmet.addCuboid(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, scale + 0.5F); - this.helmet.setPivot(0.0F, 0.0F, 0.0F); + super(RenderType::entityTranslucent, scale, 0.0F, 64, 48); + this.hat = new ModelPart(this, 0, 0); + this.hat.addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, scale + 0.5F); + this.hat.setPos(0.0F, 0.0F, 0.0F); } - + @Override - protected Iterable getHeadParts() { + protected Iterable headParts() { return Collections::emptyIterator; } - + @Override - protected Iterable getBodyParts() { - return Lists.newArrayList(helmet); + protected Iterable bodyParts() { + return Lists.newArrayList(hat); } } diff --git a/src/main/java/ru/betterend/item/model/CrystaliteLeggingsModel.java b/src/main/java/ru/betterend/item/model/CrystaliteLeggingsModel.java index d4bd17c9..acbbd1bb 100644 --- a/src/main/java/ru/betterend/item/model/CrystaliteLeggingsModel.java +++ b/src/main/java/ru/betterend/item/model/CrystaliteLeggingsModel.java @@ -1,36 +1,34 @@ package ru.betterend.item.model; import java.util.Collections; - +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.world.entity.LivingEntity; import com.google.common.collect.Lists; -import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.world.entity.LivingEntity; - -public class CrystaliteLeggingsModel extends BipedEntityModel { +public class CrystaliteLeggingsModel extends HumanoidModel { public CrystaliteLeggingsModel(float scale) { - super(RenderLayer::getEntityTranslucent, scale, 0.0F, 64, 48); - this.torso = new ModelPart(this, 16, 16); - this.torso.addCuboid(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, scale); - this.torso.setPivot(0.0F, 0.0F, 0.0F); + super(RenderType::entityTranslucent, scale, 0.0F, 64, 48); + this.body = new ModelPart(this, 16, 16); + this.body.addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, scale); + this.body.setPos(0.0F, 0.0F, 0.0F); this.leftLeg = new ModelPart(this, 0, 32); - this.leftLeg.addCuboid(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale); - this.leftLeg.setPivot(1.9F, 12.0F, 0.0F); + this.leftLeg.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale); + this.leftLeg.setPos(1.9F, 12.0F, 0.0F); this.rightLeg = new ModelPart(this, 0, 16); - this.rightLeg.addCuboid(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale); - this.rightLeg.setPivot(-1.9F, 12.0F, 0.0F); + this.rightLeg.addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F, scale); + this.rightLeg.setPos(-1.9F, 12.0F, 0.0F); } @Override - protected Iterable getHeadParts() { + protected Iterable headParts() { return Collections::emptyIterator; } - + @Override - protected Iterable getBodyParts() { - return Lists.newArrayList(torso, rightLeg, leftLeg); + protected Iterable bodyParts() { + return Lists.newArrayList(body, rightLeg, leftLeg); } } diff --git a/src/main/java/ru/betterend/item/tool/EndAxeItem.java b/src/main/java/ru/betterend/item/tool/EndAxeItem.java index 047683b5..0720695c 100644 --- a/src/main/java/ru/betterend/item/tool/EndAxeItem.java +++ b/src/main/java/ru/betterend/item/tool/EndAxeItem.java @@ -2,13 +2,13 @@ package ru.betterend.item.tool; import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.tags.Tag; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.AxeItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; -import net.minecraft.tags.Tag; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; @@ -24,7 +24,7 @@ public class EndAxeItem extends AxeItem implements DynamicAttributeTool, Pattern } return 0; } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/item/tool/EndHammerItem.java b/src/main/java/ru/betterend/item/tool/EndHammerItem.java index 8ce0818a..2fe92f82 100644 --- a/src/main/java/ru/betterend/item/tool/EndHammerItem.java +++ b/src/main/java/ru/betterend/item/tool/EndHammerItem.java @@ -9,90 +9,89 @@ import com.google.common.collect.Sets; import io.netty.util.internal.ThreadLocalRandom; import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; +import net.minecraft.core.BlockPos; +import net.minecraft.tags.Tag; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DiggerItem; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; - import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; -import net.minecraft.tags.Tag; -import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; import ru.betterend.registry.EndTags; public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, Patterned { public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(ThreadLocalRandom.current()); - + private final Multimap attributeModifiers; public EndHammerItem(Tier material, float attackDamage, float attackSpeed, double knockback, Properties settings) { super(attackDamage, attackSpeed, material, Sets.newHashSet(), settings); Builder builder = ImmutableMultimap.builder(); - builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", - attackDamage + material.getAttackDamageBonus(), AttributeModifier.Operation.ADDITION)); - builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", - attackSpeed, AttributeModifier.Operation.ADDITION)); - builder.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(ATTACK_KNOCKBACK_MODIFIER_ID, "Weapon modifier", - knockback, AttributeModifier.Operation.ADDITION)); + builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", attackDamage + material.getAttackDamageBonus(), AttributeModifier.Operation.ADDITION)); + builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", attackSpeed, AttributeModifier.Operation.ADDITION)); + builder.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(ATTACK_KNOCKBACK_MODIFIER_ID, "Weapon modifier", knockback, AttributeModifier.Operation.ADDITION)); this.attributeModifiers = builder.build(); } @Override public boolean canAttackBlock(BlockState state, Level world, BlockPos pos, Player miner) { - return state.getMaterial().equals(Material.STONE) || state.getMaterial().equals(Material.GLASS) - || state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) - || state.is(Blocks.REDSTONE_BLOCK); + return state.getMaterial().equals(Material.STONE) || + state.getMaterial().equals(Material.GLASS) || + state.is(Blocks.DIAMOND_BLOCK) || + state.is(Blocks.EMERALD_BLOCK) || + state.is(Blocks.LAPIS_BLOCK) || + state.is(Blocks.REDSTONE_BLOCK); } @Override public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { - stack.hurtAndBreak(1, attacker, (entity -> { + stack.hurtAndBreak(1, attacker, ((entity) -> { entity.broadcastBreakEvent(EquipmentSlot.MAINHAND); })); - + return true; } @Override public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity miner) { if (state.getDestroySpeed(world, pos) != 0.0F) { - stack.hurtAndBreak(1, miner, (entity -> { + stack.hurtAndBreak(1, miner, ((entity) -> { entity.broadcastBreakEvent(EquipmentSlot.MAINHAND); })); } + return true; } @Override public float getDestroySpeed(ItemStack stack, BlockState state) { if (state.getMaterial().equals(Material.GLASS)) { - return getTier().getSpeed() * 2.0F; + return this.getTier().getSpeed() * 2.0F; } if (isCorrectToolForDrops(state)) { float mult = 1.0F; - if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) - || state.is(Blocks.REDSTONE_BLOCK)) { - mult = getTier().getSpeed(); + if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.REDSTONE_BLOCK)) { + mult = this.getTier().getSpeed(); } else { - mult = getTier().getSpeed() / 2.0F; + mult = this.getTier().getSpeed() / 2.0F; } - return Math.max(mult, 1.0F); + return mult > 1.0F ? mult : 1.0F; } return 1.0F; } - + @Override public float getMiningSpeedMultiplier(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { if (tag.equals(EndTags.HAMMERS)) { @@ -100,7 +99,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P } return 1.0F; } - + @Override public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { if (tag.equals(EndTags.HAMMERS)) { @@ -114,20 +113,17 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P if (state.getMaterial().equals(Material.GLASS)) { return true; } - if (!state.is(Blocks.REDSTONE_BLOCK) && !state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.EMERALD_BLOCK) - && !state.is(Blocks.LAPIS_BLOCK) && !state.getMaterial().equals(Material.STONE)) { + if (!state.is(Blocks.REDSTONE_BLOCK) && !state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.EMERALD_BLOCK) && !state.is(Blocks.LAPIS_BLOCK) && !state.getMaterial().equals(Material.STONE)) { return false; } int level = this.getTier().getLevel(); if (state.is(Blocks.IRON_ORE) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.LAPIS_ORE)) { return level >= 1; } - if (state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.DIAMOND_ORE) || state.is(Blocks.EMERALD_ORE) - || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.GOLD_ORE) || state.is(Blocks.REDSTONE_ORE)) { + if (state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.DIAMOND_ORE) || state.is(Blocks.EMERALD_ORE) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.GOLD_ORE) || state.is(Blocks.REDSTONE_ORE)) { return level >= 2; } - if (state.is(Blocks.OBSIDIAN) || state.is(Blocks.CRYING_OBSIDIAN) || state.is(Blocks.RESPAWN_ANCHOR) - || state.is(Blocks.ANCIENT_DEBRIS)) { + if (state.is(Blocks.OBSIDIAN) || state.is(Blocks.CRYING_OBSIDIAN) || state.is(Blocks.RESPAWN_ANCHOR) || state.is(Blocks.ANCIENT_DEBRIS)) { return level >= 3; } return true; @@ -137,7 +133,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P public Multimap getDefaultAttributeModifiers(EquipmentSlot slot) { return slot == EquipmentSlot.MAINHAND ? this.attributeModifiers : super.getDefaultAttributeModifiers(slot); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/item/tool/EndHoeItem.java b/src/main/java/ru/betterend/item/tool/EndHoeItem.java index ca920b52..07fa387e 100644 --- a/src/main/java/ru/betterend/item/tool/EndHoeItem.java +++ b/src/main/java/ru/betterend/item/tool/EndHoeItem.java @@ -9,7 +9,7 @@ public class EndHoeItem extends HoeItem implements Patterned { public EndHoeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/item/tool/EndPickaxeItem.java b/src/main/java/ru/betterend/item/tool/EndPickaxeItem.java index 4fa85f5e..a7aac37c 100644 --- a/src/main/java/ru/betterend/item/tool/EndPickaxeItem.java +++ b/src/main/java/ru/betterend/item/tool/EndPickaxeItem.java @@ -5,13 +5,13 @@ import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; import net.minecraft.tags.Tag; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.PickaxeItem; import net.minecraft.world.item.Tier; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; @@ -19,7 +19,7 @@ public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, public EndPickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - + @Override public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { if (tag.equals(FabricToolTags.PICKAXES)) { @@ -27,18 +27,16 @@ public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, } return 0; } - + @Override public float getDestroySpeed(ItemStack stack, BlockState state) { - if (this.getTier().getLevel() > 2 - && state.getMaterial().equals(Blocks.END_STONE.defaultBlockState().getMaterial())) { + if (this.getTier().getLevel() > 2 && state.getMaterial().equals(Blocks.END_STONE.defaultBlockState().getMaterial())) { return this.speed * 3; } Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); - return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed - : super.getDestroySpeed(stack, state); + return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? this.speed : super.getDestroySpeed(stack, state); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/item/tool/EndShovelItem.java b/src/main/java/ru/betterend/item/tool/EndShovelItem.java index 4d36aa49..5a59a2bc 100644 --- a/src/main/java/ru/betterend/item/tool/EndShovelItem.java +++ b/src/main/java/ru/betterend/item/tool/EndShovelItem.java @@ -4,13 +4,13 @@ import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.tags.Tag; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.Tier; -import net.minecraft.tags.Tag; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.patterns.Patterned; import ru.betterend.patterns.Patterns; @@ -18,7 +18,7 @@ public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, P public EndShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - + @Override public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { if (tag.equals(FabricToolTags.SHOVELS)) { @@ -26,14 +26,13 @@ public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, P } return 0; } - + @Override public float getDestroySpeed(ItemStack stack, BlockState state) { Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); - return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed - : super.getDestroySpeed(stack, state); + return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? this.speed : super.getDestroySpeed(stack, state); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/item/tool/EndSwordItem.java b/src/main/java/ru/betterend/item/tool/EndSwordItem.java index 679ae06c..43aa6761 100644 --- a/src/main/java/ru/betterend/item/tool/EndSwordItem.java +++ b/src/main/java/ru/betterend/item/tool/EndSwordItem.java @@ -10,7 +10,7 @@ public class EndSwordItem extends SwordItem implements DynamicAttributeTool, Pat public EndSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - + @Override public String getModelPattern(String name) { return Patterns.createJson(Patterns.ITEM_HANDHELD, name); diff --git a/src/main/java/ru/betterend/mixin/client/AbstractSoundInstanceAccessor.java b/src/main/java/ru/betterend/mixin/client/AbstractSoundInstanceAccessor.java index c925808e..9c94ed93 100644 --- a/src/main/java/ru/betterend/mixin/client/AbstractSoundInstanceAccessor.java +++ b/src/main/java/ru/betterend/mixin/client/AbstractSoundInstanceAccessor.java @@ -1,10 +1,9 @@ package ru.betterend.mixin.client; +import net.minecraft.client.resources.sounds.AbstractSoundInstance; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import net.minecraft.client.sound.AbstractSoundInstance; - @Mixin(AbstractSoundInstance.class) public interface AbstractSoundInstanceAccessor { @Accessor("volume") diff --git a/src/main/java/ru/betterend/mixin/client/AnvilScreenMixin.java b/src/main/java/ru/betterend/mixin/client/AnvilScreenMixin.java index a37d7cee..1bbed601 100644 --- a/src/main/java/ru/betterend/mixin/client/AnvilScreenMixin.java +++ b/src/main/java/ru/betterend/mixin/client/AnvilScreenMixin.java @@ -1,7 +1,18 @@ package ru.betterend.mixin.client; import java.util.List; - +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.inventory.AnvilScreen; +import net.minecraft.client.gui.screens.inventory.ItemCombinerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -9,32 +20,19 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.google.common.collect.Lists; - -import net.minecraft.client.gui.screen.ingame.AnvilScreen; -import net.minecraft.client.gui.screen.ingame.ForgingScreen; -import net.minecraft.client.gui.widget.AbstractButtonWidget; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.world.entity.player.PlayerInventory; -import net.minecraft.world.item.ItemStack; -import net.minecraft.screen.AnvilScreenHandler; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.resources.ResourceLocation; +import com.mojang.blaze3d.vertex.PoseStack; import ru.betterend.interfaces.AnvilScreenHandlerExtended; @Mixin(AnvilScreen.class) -public class AnvilScreenMixin extends ForgingScreen { +public class AnvilScreenMixin extends ItemCombinerScreen { @Shadow - private TextFieldWidget nameField; - - private final List be_buttons = Lists.newArrayList(); + private EditBox nameField; + + private final List be_buttons = Lists.newArrayList(); private AnvilScreenHandlerExtended anvilHandler; - - public AnvilScreenMixin(AnvilScreenHandler handler, PlayerInventory playerInventory, Text title, + + public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title, ResourceLocation texture) { super(handler, playerInventory, title, texture); } @@ -42,22 +40,22 @@ public class AnvilScreenMixin extends ForgingScreen { @Inject(method = "setup", at = @At("TAIL")) protected void be_setup(CallbackInfo info) { this.be_buttons.clear(); - int x = (width - backgroundWidth) / 2; - int y = (height - backgroundHeight) / 2; - this.anvilHandler = (AnvilScreenHandlerExtended) this.handler; - this.be_buttons.add(new ButtonWidget(x + 8, y + 45, 15, 20, new LiteralText("<"), (b) -> be_previousRecipe())); - this.be_buttons.add(new ButtonWidget(x + 154, y + 45, 15, 20, new LiteralText(">"), (b) -> be_nextRecipe())); + int x = (width - imageWidth) / 2; + int y = (height - imageHeight) / 2; + this.anvilHandler = (AnvilScreenHandlerExtended) this.menu; + this.be_buttons.add(new Button(x + 8, y + 45, 15, 20, new TextComponent("<"), (b) -> be_previousRecipe())); + this.be_buttons.add(new Button(x + 154, y + 45, 15, 20, new TextComponent(">"), (b) -> be_nextRecipe())); } - + @Inject(method = "renderForeground", at = @At("TAIL")) - protected void be_renderForeground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) { + protected void be_renderForeground(PoseStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) { this.be_buttons.forEach(button -> { button.render(matrices, mouseX, mouseY, delta); }); } - + @Inject(method = "onSlotUpdate", at = @At("HEAD"), cancellable = true) - public void be_onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack, CallbackInfo info) { + public void be_onSlotUpdate(AbstractContainerMenu handler, int slotId, ItemStack stack, CallbackInfo info) { AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler; if (anvilHandler.be_getCurrentRecipe() != null) { if (anvilHandler.be_getRecipes().size() > 1) { @@ -65,29 +63,29 @@ public class AnvilScreenMixin extends ForgingScreen { } else { this.be_buttons.forEach(button -> button.visible = false); } - this.nameField.setText(""); + this.nameField.setValue(""); info.cancel(); } else { this.be_buttons.forEach(button -> button.visible = false); } } - + private void be_nextRecipe() { this.anvilHandler.be_nextRecipe(); } - + private void be_previousRecipe() { this.anvilHandler.be_previousRecipe(); } - + @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (client != null) { - for (AbstractButtonWidget elem : be_buttons) { + if (minecraft != null) { + for (AbstractWidget elem : be_buttons) { if (elem.visible && elem.mouseClicked(mouseX, mouseY, button)) { - if (client.interactionManager != null) { + if (minecraft.gameMode != null) { int i = be_buttons.indexOf(elem); - this.client.interactionManager.clickButton(handler.syncId, i); + this.minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i); return true; } } diff --git a/src/main/java/ru/betterend/mixin/client/BackgroundRendererMixin.java b/src/main/java/ru/betterend/mixin/client/BackgroundRendererMixin.java index e85b8ef2..993c4b51 100644 --- a/src/main/java/ru/betterend/mixin/client/BackgroundRendererMixin.java +++ b/src/main/java/ru/betterend/mixin/client/BackgroundRendererMixin.java @@ -8,54 +8,51 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; - -import net.minecraft.client.render.BackgroundRenderer; -import net.minecraft.client.render.Camera; +import net.minecraft.Util; +import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; +import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.fluid.FluidState; -import net.minecraft.util.Util; -import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.Category; +import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.world.level.material.FluidState; import ru.betterend.client.ClientOptions; import ru.betterend.registry.EndBiomes; import ru.betterend.util.BackgroundInfo; import ru.betterend.world.biome.EndBiome; -@Mixin(BackgroundRenderer.class) +@Mixin(FogRenderer.class) public class BackgroundRendererMixin { private static float lastFogDensity; private static float fogDensity; private static float lerp; private static long time; - + @Shadow private static float red; @Shadow private static float green; @Shadow private static float blue; - + @Inject(method = "render", at = @At("RETURN")) - private static void be_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, - CallbackInfo info) { - long l = Util.getMeasuringTimeMs() - time; + private static void be_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) { + long l = Util.getMillis() - time; time += l; lerp += l * 0.001F; - if (lerp > 1) - lerp = 1; - - FluidState fluidState = camera.getSubmergedFluidState(); + if (lerp > 1) lerp = 1; + + FluidState fluidState = camera.getFluidInCamera(); if (fluidState.isEmpty() && world.dimension().equals(Level.END)) { - Entity entity = camera.getFocusedEntity(); + Entity entity = camera.getEntity(); boolean skip = false; if (entity instanceof LivingEntity) { - MobEffectInstance effect = ((LivingEntity) entity).getMobEffect(MobEffects.NIGHT_VISION); + MobEffectInstance effect = ((LivingEntity) entity).getEffect(MobEffects.NIGHT_VISION); skip = effect != null && effect.getDuration() > 0; } if (!skip) { @@ -64,21 +61,20 @@ public class BackgroundRendererMixin { blue *= 4; } } - + BackgroundInfo.red = red; BackgroundInfo.green = green; BackgroundInfo.blue = blue; } - + @Inject(method = "applyFog", at = @At("HEAD"), cancellable = true) - private static void be_fogDensity(Camera camera, BackgroundRenderer.FogType fogType, float viewDistance, - boolean thickFog, CallbackInfo info) { - Entity entity = camera.getFocusedEntity(); - Biome biome = entity.world.getBiome(entity.getBlockPos()); - FluidState fluidState = camera.getSubmergedFluidState(); - if (ClientOptions.useFogDensity() && biome.getCategory() == Category.THEEND && fluidState.isEmpty()) { + private static void be_fogDensity(Camera camera, FogRenderer.FogMode fogType, float viewDistance, boolean thickFog, CallbackInfo info) { + Entity entity = camera.getEntity(); + Biome biome = entity.level.getBiome(entity.blockPosition()); + FluidState fluidState = camera.getFluidInCamera(); + if (ClientOptions.useFogDensity() && biome.getBiomeCategory() == BiomeCategory.THEEND && fluidState.isEmpty()) { EndBiome endBiome = EndBiomes.getRenderBiome(biome); - + if (fogDensity == 0) { fogDensity = endBiome.getFogDensity(); lastFogDensity = fogDensity; @@ -88,32 +84,34 @@ public class BackgroundRendererMixin { fogDensity = endBiome.getFogDensity(); lerp = 0; } - + float fog = Mth.lerp(lerp, lastFogDensity, fogDensity); BackgroundInfo.fog = fog; float start = viewDistance * 0.75F / fog; float end = viewDistance / fog; - + if (entity instanceof LivingEntity) { LivingEntity le = (LivingEntity) entity; - MobEffectInstance effect = le.getMobEffect(MobEffects.BLINDNESS); + MobEffectInstance effect = le.getEffect(MobEffects.BLINDNESS); if (effect != null) { int duration = effect.getDuration(); if (duration > 20) { start = 0; end *= 0.03F; BackgroundInfo.blindness = 1; - } else { + } + else { float delta = (float) duration / 20F; BackgroundInfo.blindness = delta; start = Mth.lerp(delta, start, 0); end = Mth.lerp(delta, end, end * 0.03F); } - } else { + } + else { BackgroundInfo.blindness = 0; } } - + RenderSystem.fogStart(start); RenderSystem.fogEnd(end); RenderSystem.fogMode(GlStateManager.FogMode.LINEAR); diff --git a/src/main/java/ru/betterend/mixin/client/BiomeColorsMixin.java b/src/main/java/ru/betterend/mixin/client/BiomeColorsMixin.java index 1a897f04..4d18dda8 100644 --- a/src/main/java/ru/betterend/mixin/client/BiomeColorsMixin.java +++ b/src/main/java/ru/betterend/mixin/client/BiomeColorsMixin.java @@ -9,11 +9,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; -import net.minecraft.client.color.world.BiomeColors; +import net.minecraft.client.renderer.BiomeColors; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.BlockRenderView; +import net.minecraft.world.level.BlockAndTintGetter; import ru.betterend.client.ClientOptions; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; @@ -25,11 +25,11 @@ public class BiomeColorsMixin { private static final int STREAM_COLOR = MHelper.color(105, 213, 244); private static final Point[] OFFSETS; private static final boolean HAS_SODIUM; - + @Inject(method = "getWaterColor", at = @At("RETURN"), cancellable = true) - private static void be_getWaterColor(BlockRenderView world, BlockPos pos, CallbackInfoReturnable info) { + private static void be_getWaterColor(BlockAndTintGetter world, BlockPos pos, CallbackInfoReturnable info) { if (ClientOptions.useSulfurWaterColor()) { - BlockRenderView view = HAS_SODIUM ? Minecraft.getInstance().world : world; + BlockAndTintGetter view = HAS_SODIUM ? Minecraft.getInstance().level : world; MutableBlockPos mut = new MutableBlockPos(); mut.setY(pos.getY()); for (int i = 0; i < OFFSETS.length; i++) { @@ -43,10 +43,10 @@ public class BiomeColorsMixin { } } } - + static { HAS_SODIUM = FabricLoader.getInstance().isModLoaded("sodium"); - + OFFSETS = new Point[20]; for (int i = 0; i < 3; i++) { int p = i - 1; @@ -55,13 +55,13 @@ public class BiomeColorsMixin { OFFSETS[i + 6] = new Point(-2, p); OFFSETS[i + 9] = new Point(2, p); } - + for (int i = 0; i < 4; i++) { int inner = i + 16; Direction dir = BlocksHelper.HORIZONTAL[i]; - OFFSETS[inner] = new Point(dir.getOffsetX(), dir.getOffsetZ()); + OFFSETS[inner] = new Point(dir.getStepX(), dir.getStepZ()); dir = BlocksHelper.HORIZONTAL[(i + 1) & 3]; - OFFSETS[i + 12] = new Point(OFFSETS[inner].x + dir.getOffsetX(), OFFSETS[inner].y + dir.getOffsetZ()); + OFFSETS[i + 12] = new Point(OFFSETS[inner].x + dir.getStepX(), OFFSETS[inner].y + dir.getStepZ()); } } } diff --git a/src/main/java/ru/betterend/mixin/client/ClientPlayNetworkHandlerMixin.java b/src/main/java/ru/betterend/mixin/client/ClientPlayNetworkHandlerMixin.java index 32e0fd75..9fd6850c 100644 --- a/src/main/java/ru/betterend/mixin/client/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/ru/betterend/mixin/client/ClientPlayNetworkHandlerMixin.java @@ -1,22 +1,22 @@ package ru.betterend.mixin.client; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.PacketUtils; +import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket; +import net.minecraft.world.level.block.entity.BlockEntity; 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.CallbackInfo; - -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.client.Minecraft; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.network.NetworkThreadUtils; -import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket; import ru.betterend.blocks.entities.ESignBlockEntity; import ru.betterend.client.gui.BlockSignEditScreen; -@Mixin(ClientPlayNetworkHandler.class) -public class ClientPlayNetworkHandlerMixin { +@Mixin(ClientPacketListener.class) +public class ClientPlayNetworkHandlerMixin +{ @Shadow private Minecraft client; @@ -24,12 +24,12 @@ public class ClientPlayNetworkHandlerMixin { private ClientLevel world; @Inject(method = "onSignEditorOpen", at = @At(value = "HEAD"), cancellable = true) - public void be_openSignEditor(SignEditorOpenS2CPacket packet, CallbackInfo info) { - NetworkThreadUtils.forceMainThread(packet, ClientPlayNetworkHandler.class.cast(this), client); + public void be_openSignEditor(ClientboundOpenSignEditorPacket packet, CallbackInfo info) { + PacketUtils.ensureRunningOnSameThread(packet, ClientPacketListener.class.cast(this), client); BlockEntity blockEntity = world.getBlockEntity(packet.getPos()); if (blockEntity instanceof ESignBlockEntity) { ESignBlockEntity sign = (ESignBlockEntity) blockEntity; - client.openScreen(new BlockSignEditScreen(sign)); + client.setScreen(new BlockSignEditScreen(sign)); info.cancel(); } } diff --git a/src/main/java/ru/betterend/mixin/client/ClientRecipeBookMixin.java b/src/main/java/ru/betterend/mixin/client/ClientRecipeBookMixin.java index 90797794..873da6b2 100644 --- a/src/main/java/ru/betterend/mixin/client/ClientRecipeBookMixin.java +++ b/src/main/java/ru/betterend/mixin/client/ClientRecipeBookMixin.java @@ -1,24 +1,23 @@ package ru.betterend.mixin.client; +import net.minecraft.client.ClientRecipeBook; +import net.minecraft.client.RecipeBookCategories; +import net.minecraft.world.item.crafting.Recipe; 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 net.minecraft.client.recipebook.ClientRecipeBook; -import net.minecraft.client.recipebook.RecipeBookGroup; -import net.minecraft.world.item.crafting.Recipe; import ru.betterend.interfaces.BetterEndRecipe; import ru.betterend.recipe.builders.AlloyingRecipe; @Mixin(ClientRecipeBook.class) public abstract class ClientRecipeBookMixin { @Inject(method = "getGroupForRecipe", at = @At("HEAD"), cancellable = true) - private static void be_getGroupForRecipe(Recipe recipe, CallbackInfoReturnable cinfo) { + private static void be_getGroupForRecipe(Recipe recipe, CallbackInfoReturnable cinfo) { if (recipe instanceof AlloyingRecipe) { - cinfo.setReturnValue(RecipeBookGroup.BLAST_FURNACE_MISC); + cinfo.setReturnValue(RecipeBookCategories.BLAST_FURNACE_MISC); } else if (recipe instanceof BetterEndRecipe) { - cinfo.setReturnValue(RecipeBookGroup.UNKNOWN); + cinfo.setReturnValue(RecipeBookCategories.UNKNOWN); } } } diff --git a/src/main/java/ru/betterend/mixin/client/ContextGsonAccessor.java b/src/main/java/ru/betterend/mixin/client/ContextGsonAccessor.java index d635bdbc..300486c2 100644 --- a/src/main/java/ru/betterend/mixin/client/ContextGsonAccessor.java +++ b/src/main/java/ru/betterend/mixin/client/ContextGsonAccessor.java @@ -4,10 +4,9 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import com.google.gson.Gson; +import net.minecraft.client.renderer.block.model.BlockModelDefinition; -import net.minecraft.client.render.model.json.ModelVariantMap; - -@Mixin(ModelVariantMap.DeserializationContext.class) +@Mixin(BlockModelDefinition.Context.class) public interface ContextGsonAccessor { @Accessor public Gson getGson(); diff --git a/src/main/java/ru/betterend/mixin/client/EnchantingTableBlockMixin.java b/src/main/java/ru/betterend/mixin/client/EnchantingTableBlockMixin.java index dbc78fec..55ce721d 100644 --- a/src/main/java/ru/betterend/mixin/client/EnchantingTableBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/client/EnchantingTableBlockMixin.java @@ -1,27 +1,25 @@ package ru.betterend.mixin.client; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EnchantmentTableBlock; +import net.minecraft.world.level.block.state.BlockState; 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 net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.EnchantingTableBlock; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; import ru.betterend.registry.EndTags; -@Mixin(EnchantingTableBlock.class) +@Mixin(EnchantmentTableBlock.class) public abstract class EnchantingTableBlockMixin extends Block { public EnchantingTableBlockMixin(Properties settings) { super(settings); } - @Inject(method = "animateTick", at = @At(value = "TAIL")) + @Inject(method = "randomDisplayTick", at = @At(value = "TAIL")) private void be_onRandomDisplayTick(BlockState state, Level world, BlockPos pos, Random random, CallbackInfo info) { for (int px = -2; px <= 2; ++px) { for (int pz = -2; pz <= 2; ++pz) { @@ -31,13 +29,11 @@ public abstract class EnchantingTableBlockMixin extends Block { if (random.nextInt(16) == 0) { for (int py = 0; py <= 1; ++py) { BlockPos blockPos = pos.offset(px, py, pz); - if (world.getBlockState(blockPos).isIn(EndTags.BOOKSHELVES)) { - if (!world.isAir(pos.offset(px / 2, 0, pz / 2))) { + if (world.getBlockState(blockPos).is(EndTags.BOOKSHELVES)) { + if (!world.isEmptyBlock(pos.offset(px / 2, 0, pz / 2))) { break; } - world.addParticle(ParticleTypes.ENCHANT, pos.getX() + 0.5, pos.getY() + 2.0, - pos.getZ() + 0.5, px + random.nextFloat() - 0.5, py - random.nextFloat() - 1.0, - pz + random.nextFloat() - 0.5); + world.addParticle(ParticleTypes.ENCHANT, pos.getX() + 0.5, pos.getY() + 2.0, pos.getZ() + 0.5, px + random.nextFloat() - 0.5, py - random.nextFloat() - 1.0, pz + random.nextFloat() - 0.5); } } } diff --git a/src/main/java/ru/betterend/mixin/client/MinecraftClientMixin.java b/src/main/java/ru/betterend/mixin/client/MinecraftClientMixin.java index d6a6a9b4..06ac5e6a 100644 --- a/src/main/java/ru/betterend/mixin/client/MinecraftClientMixin.java +++ b/src/main/java/ru/betterend/mixin/client/MinecraftClientMixin.java @@ -7,19 +7,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - import net.minecraft.client.Minecraft; -import net.minecraft.client.RunArgs; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; -import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.gui.screen.CreditsScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.sound.MusicType; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.WinScreen; +import net.minecraft.client.main.GameConfig; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.sound.MusicSound; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.Registry; +import net.minecraft.sounds.Music; +import net.minecraft.sounds.Musics; import net.minecraft.world.level.Level; import ru.betterend.interfaces.IColorProvider; import ru.betterend.util.MHelper; @@ -27,18 +26,18 @@ import ru.betterend.util.MHelper; @Mixin(Minecraft.class) public class MinecraftClientMixin { @Shadow - public ClientPlayerEntity player; - + public LocalPlayer player; + @Shadow public Screen currentScreen; - + @Shadow @Final - public InGameHud inGameHud; - + public Gui inGameHud; + @Shadow public ClientLevel world; - + @Shadow @Final private BlockColors blockColors; @@ -46,28 +45,27 @@ public class MinecraftClientMixin { @Shadow @Final private ItemColors itemColors; - + @Inject(method = "*", at = @At("TAIL")) - private void be_onInit(RunArgs args, CallbackInfo info) { + private void be_onInit(GameConfig args, CallbackInfo info) { Registry.BLOCK.forEach(block -> { if (block instanceof IColorProvider) { IColorProvider provider = (IColorProvider) block; - blockColors.registerColorProvider(provider.getBlockProvider(), block); + blockColors.register(provider.getProvider(), block); itemColors.register(provider.getItemProvider(), block.asItem()); } }); } - + @Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true) - private void be_getEndMusic(CallbackInfoReturnable info) { - if (!(this.currentScreen instanceof CreditsScreen) && this.player != null) { - if (this.player.world.dimension() == Level.END) { - if (this.inGameHud.getBossBarHud().shouldPlayDragonMusic() - && MHelper.lengthSqr(this.player.getX(), this.player.getZ()) < 250000) { - info.setReturnValue(MusicType.DRAGON); - } else { - MusicSound sound = (MusicSound) this.world.getBiomeAccess().method_27344(this.player.getBlockPos()) - .getMusic().orElse(MusicType.END); + private void be_getEndMusic(CallbackInfoReturnable info) { + if (!(this.currentScreen instanceof WinScreen) && this.player != null) { + if (this.player.level.dimension() == Level.END) { + if (this.inGameHud.getBossOverlay().shouldPlayMusic() && MHelper.lengthSqr(this.player.getX(), this.player.getZ()) < 250000) { + info.setReturnValue(Musics.END_BOSS); + } + else { + Music sound = (Music) this.world.getBiomeManager().getNoiseBiomeAtPosition(this.player.blockPosition()).getBackgroundMusic().orElse(Musics.END); info.setReturnValue(sound); } info.cancel(); diff --git a/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java b/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java index 5e4ed077..687e9475 100644 --- a/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java +++ b/src/main/java/ru/betterend/mixin/client/ModelLoaderMixin.java @@ -4,7 +4,14 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.Optional; - +import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -12,40 +19,31 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.level.block.Block; -import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.render.model.json.JsonUnbakedModel; -import net.minecraft.world.item.Item; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.patterns.Patterned; import ru.betterend.world.generator.GeneratorOptions; -@Mixin(ModelLoader.class) +@Mixin(ModelBakery.class) public class ModelLoaderMixin { @Final @Shadow private ResourceManager resourceManager; - + @Inject(method = "loadModelFromJson", at = @At("HEAD"), cancellable = true) - private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable info) { + private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable info) { if (id.getNamespace().equals(BetterEnd.MOD_ID)) { ResourceLocation modelId = new ResourceLocation(id.getNamespace(), "models/" + id.getPath() + ".json"); - JsonUnbakedModel model; + BlockModel model; try (Resource resource = this.resourceManager.getResource(modelId)) { Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8); - model = JsonUnbakedModel.deserialize(reader); - model.id = id.toString(); + model = BlockModel.fromStream(reader); + model.name = id.toString(); info.setReturnValue(model); } catch (Exception ex) { String data[] = id.getPath().split("/"); if (data.length > 1) { ResourceLocation itemId = new ResourceLocation(id.getNamespace(), data[1]); - Optional block = Registry.BLOCK.getOrEmpty(itemId); + Optional block = Registry.BLOCK.getOptional(itemId); if (block.isPresent()) { if (block.get() instanceof Patterned) { Patterned patterned = (Patterned) block.get(); @@ -53,7 +51,7 @@ public class ModelLoaderMixin { info.setReturnValue(model); } } else { - Optional item = Registry.ITEM.getOrEmpty(itemId); + Optional item = Registry.ITEM.getOptional(itemId); if (item.isPresent() && item.get() instanceof Patterned) { Patterned patterned = (Patterned) item.get(); model = this.be_getModel(data, id, patterned); @@ -64,8 +62,8 @@ public class ModelLoaderMixin { } } } - - private JsonUnbakedModel be_getModel(String data[], ResourceLocation id, Patterned patterned) { + + private BlockModel be_getModel(String data[], ResourceLocation id, Patterned patterned) { String pattern; if (id.getPath().contains("item")) { pattern = patterned.getModelPattern(id.getPath()); @@ -76,17 +74,15 @@ public class ModelLoaderMixin { pattern = patterned.getModelPattern(data[1]); } } - JsonUnbakedModel model = JsonUnbakedModel.deserialize(pattern); - model.id = id.toString(); - + BlockModel model = BlockModel.fromString(pattern); + model.name = id.toString(); + return model; } - + @ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE")) public ResourceLocation be_SwitchModel(ResourceLocation id) { - if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") - && id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus") - && !id.getPath().contains("custom_")) { + if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus") && !id.getPath().contains("custom_")) { id = new ResourceLocation(id.getPath().replace("chorus", "custom_chorus")); } return id; diff --git a/src/main/java/ru/betterend/mixin/client/ModelVariantMapMixin.java b/src/main/java/ru/betterend/mixin/client/ModelVariantMapMixin.java index 1754ac85..60c4e394 100644 --- a/src/main/java/ru/betterend/mixin/client/ModelVariantMapMixin.java +++ b/src/main/java/ru/betterend/mixin/client/ModelVariantMapMixin.java @@ -2,30 +2,27 @@ package ru.betterend.mixin.client; import java.io.Reader; import java.io.StringReader; - +import net.minecraft.client.renderer.block.model.BlockModelDefinition; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.level.block.Block; 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 com.google.gson.Gson; - -import net.minecraft.world.level.block.Block; -import net.minecraft.client.render.model.json.ModelVariantMap; -import net.minecraft.util.JsonHelper; import ru.betterend.patterns.BlockPatterned; -@Mixin(ModelVariantMap.class) +@Mixin(BlockModelDefinition.class) public abstract class ModelVariantMapMixin { - + @Inject(method = "deserialize", at = @At("HEAD"), cancellable = true) - private static void be_deserializeBlockState(ModelVariantMap.DeserializationContext context, Reader reader, - CallbackInfoReturnable info) { - Block block = context.getStateFactory().defaultBlockState().getBlock(); + private static void be_deserializeBlockState(BlockModelDefinition.Context context, Reader reader, CallbackInfoReturnable info) { + Block block = context.getDefinition().any().getBlock(); if (block instanceof BlockPatterned) { String pattern = ((BlockPatterned) block).getStatesPattern(reader); Gson gson = ContextGsonAccessor.class.cast(context).getGson(); - ModelVariantMap map = JsonHelper.deserialize(gson, new StringReader(pattern), ModelVariantMap.class); + BlockModelDefinition map = GsonHelper.fromJson(gson, new StringReader(pattern), BlockModelDefinition.class); info.setReturnValue(map); } } diff --git a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java index f65bce48..d28a8e45 100644 --- a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java +++ b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java @@ -1,47 +1,45 @@ package ru.betterend.mixin.client; import java.util.Random; - +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.sounds.AbstractSoundInstance; +import net.minecraft.client.resources.sounds.SoundInstance; +import net.minecraft.client.sounds.MusicManager; +import net.minecraft.sounds.Music; +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; 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.CallbackInfo; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.sound.AbstractSoundInstance; -import net.minecraft.client.sound.MusicTracker; -import net.minecraft.client.sound.SoundInstance; -import net.minecraft.sound.MusicSound; -import net.minecraft.util.Mth; -import net.minecraft.world.level.Level; import ru.betterend.client.ClientOptions; -@Mixin(MusicTracker.class) +@Mixin(MusicManager.class) public class MusicTrackerMixin { @Shadow @Final private Minecraft client; - + @Shadow @Final private Random random; - + @Shadow private SoundInstance current; - + @Shadow private int timeUntilNextSong; - + private static float volume = 1; private static float srcVolume = 0; private static long time; - + @Inject(method = "tick", at = @At("HEAD"), cancellable = true) public void be_onTick(CallbackInfo info) { if (ClientOptions.blendBiomeMusic()) { - MusicSound musicSound = client.getMusicType(); + Music musicSound = client.getSituationalMusic(); if (be_checkNullSound(musicSound) && volume > 0 && be_isInEnd() && be_shouldChangeSound(musicSound)) { if (volume > 0) { if (srcVolume < 0) { @@ -50,7 +48,7 @@ public class MusicTrackerMixin { if (current instanceof AbstractSoundInstance) { ((AbstractSoundInstanceAccessor) current).setVolume(volume); } - client.getSoundManager().updateSoundVolume(current.getCategory(), current.getVolume() * volume); + client.getSoundManager().updateSourceVolume(current.getSource(), current.getVolume() * volume); long t = System.currentTimeMillis(); if (volume == 1 && time == 0) { time = t; @@ -74,26 +72,25 @@ public class MusicTrackerMixin { this.play(musicSound); } info.cancel(); - } else { + } + else { volume = 1; } } } - + private boolean be_isInEnd() { - return client.world != null && client.world.dimension().equals(Level.END); + return client.level != null && client.level.dimension().equals(Level.END); } - - private boolean be_shouldChangeSound(MusicSound musicSound) { - return current != null && !musicSound.getSound().getId().equals(this.current.getId()) - && musicSound.shouldReplaceCurrentMusic(); + + private boolean be_shouldChangeSound(Music musicSound) { + return current != null && !musicSound.getEvent().getLocation().equals(this.current.getLocation()) && musicSound.replaceCurrentMusic(); } - - private boolean be_checkNullSound(MusicSound musicSound) { - return musicSound != null && musicSound.getSound() != null; + + private boolean be_checkNullSound(Music musicSound) { + return musicSound != null && musicSound.getEvent() != null; } - + @Shadow - public void play(MusicSound type) { - } + public void play(Music type) {} } diff --git a/src/main/java/ru/betterend/mixin/client/NamespaceResourceManagerMixin.java b/src/main/java/ru/betterend/mixin/client/NamespaceResourceManagerMixin.java index 12a23843..0320e2fb 100644 --- a/src/main/java/ru/betterend/mixin/client/NamespaceResourceManagerMixin.java +++ b/src/main/java/ru/betterend/mixin/client/NamespaceResourceManagerMixin.java @@ -1,7 +1,11 @@ package ru.betterend.mixin.client; import java.util.List; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.FallbackResourceManager; +import net.minecraft.server.packs.resources.Resource; +import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -10,22 +14,19 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.Block; -import net.minecraft.resource.NamespaceResourceManager; -import net.minecraft.resource.Resource; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.patterns.BlockPatterned; -@Mixin(NamespaceResourceManager.class) +@Mixin(FallbackResourceManager.class) public abstract class NamespaceResourceManagerMixin { - + @Shadow public abstract Resource getResource(ResourceLocation id); - - @Inject(method = "getAllResources", cancellable = true, at = @At(value = "NEW", target = "java/io/FileNotFoundException", shift = Shift.BEFORE)) + + @Inject(method = "getAllResources", cancellable = true, at = @At( + value = "NEW", + target = "java/io/FileNotFoundException", + shift = Shift.BEFORE)) public void be_getStatesPattern(ResourceLocation id, CallbackInfoReturnable> info) { if (id.getNamespace().equals(BetterEnd.MOD_ID)) { String[] data = id.getPath().split("/"); diff --git a/src/main/java/ru/betterend/mixin/client/WorldRendererMixin.java b/src/main/java/ru/betterend/mixin/client/WorldRendererMixin.java index 760409ea..fd02404f 100644 --- a/src/main/java/ru/betterend/mixin/client/WorldRendererMixin.java +++ b/src/main/java/ru/betterend/mixin/client/WorldRendererMixin.java @@ -11,37 +11,36 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.mojang.blaze3d.systems.RenderSystem; - +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexBuffer; +import com.mojang.blaze3d.vertex.VertexFormat; +import com.mojang.math.Quaternion; +import com.mojang.math.Vector3f; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; -import net.minecraft.client.gl.VertexBuffer; -import net.minecraft.client.render.BackgroundRenderer; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferBuilderStorage; -import net.minecraft.client.render.SkyProperties; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import net.minecraft.client.render.VertexFormats; -import net.minecraft.client.render.WorldRenderer; -import net.minecraft.client.texture.TextureManager; -import net.minecraft.client.util.math.MatrixStack; -import com.mojang.math.Vector3f; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.DimensionSpecialEffects; +import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.RenderBuffers; +import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.Quaternion; import ru.betterend.BetterEnd; import ru.betterend.client.ClientOptions; import ru.betterend.util.BackgroundInfo; import ru.betterend.util.MHelper; -@Mixin(WorldRenderer.class) +@Mixin(LevelRenderer.class) public class WorldRendererMixin { private static final ResourceLocation NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png"); private static final ResourceLocation NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png"); private static final ResourceLocation HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png"); private static final ResourceLocation STARS = BetterEnd.makeID("textures/sky/stars.png"); private static final ResourceLocation FOG = BetterEnd.makeID("textures/sky/fog.png"); - + private static VertexBuffer stars1; private static VertexBuffer stars2; private static VertexBuffer stars3; @@ -60,23 +59,23 @@ public class WorldRendererMixin { private static float blind02; private static float blind06; private static boolean directOpenGL = false; - + @Shadow @Final private Minecraft client; - + @Shadow @Final private TextureManager textureManager; - + @Shadow private ClientLevel world; - + @Shadow private int ticks; - + @Inject(method = "*", at = @At("TAIL")) - private void be_onInit(Minecraft client, BufferBuilderStorage bufferBuilders, CallbackInfo info) { + private void be_onInit(Minecraft client, RenderBuffers bufferBuilders, CallbackInfo info) { be_initStars(); Random random = new Random(131); axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat()); @@ -87,110 +86,107 @@ public class WorldRendererMixin { axis2.normalize(); axis3.normalize(); axis4.normalize(); - - directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric") - || FabricLoader.getInstance().isModLoaded("immersive_portals"); + + directOpenGL = FabricLoader.getInstance().isModLoaded("optifabric") || FabricLoader.getInstance().isModLoaded("immersive_portals"); } - + @Inject(method = "renderSky", at = @At("HEAD"), cancellable = true) - private void be_renderBetterEndSky(MatrixStack matrices, float tickDelta, CallbackInfo info) { - if (ClientOptions.isCustomSky() && client.world.getSkyProperties().getSkyType() == SkyProperties.SkyType.END) { + private void be_renderBetterEndSky(PoseStack matrices, float tickDelta, CallbackInfo info) { + if (ClientOptions.isCustomSky() && client.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) { time = (ticks % 360000) * 0.000017453292F; time2 = time * 2; time3 = time * 3; - - BackgroundRenderer.setFogBlack(); + + FogRenderer.levelFogColor(); RenderSystem.enableTexture(); - + if (directOpenGL) { GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glAlphaFunc(516, 0.0F); GL11.glEnable(GL11.GL_BLEND); RenderSystem.depthMask(false); - } else { + } + else { RenderSystem.enableAlphaTest(); RenderSystem.alphaFunc(516, 0.0F); RenderSystem.enableBlend(); } - + float blindA = 1F - BackgroundInfo.blindness; blind02 = blindA * 0.2F; blind06 = blindA * 0.6F; - + if (blindA > 0) { - matrices.push(); - matrices.multiply(new Quaternion(0, time, 0, false)); - textureManager.bindTexture(HORIZON); - be_renderBuffer(matrices, horizon, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, 0.7F * blindA); - matrices.pop(); - - matrices.push(); - matrices.multiply(new Quaternion(0, -time, 0, false)); - textureManager.bindTexture(NEBULA_1); - be_renderBuffer(matrices, nebulas1, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind02); - matrices.pop(); - - matrices.push(); - matrices.multiply(new Quaternion(0, time2, 0, false)); - textureManager.bindTexture(NEBULA_2); - be_renderBuffer(matrices, nebulas2, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind02); - matrices.pop(); - - textureManager.bindTexture(STARS); - - matrices.push(); - matrices.multiply(axis3.getRadialQuaternion(time)); - be_renderBuffer(matrices, stars3, VertexFormats.POSITION_TEXTURE, 0.77F, 0.31F, 0.73F, blind06); - matrices.pop(); - - matrices.push(); - matrices.multiply(axis4.getRadialQuaternion(time2)); - be_renderBuffer(matrices, stars4, VertexFormats.POSITION_TEXTURE, 1F, 1F, 1F, blind06); - matrices.pop(); + matrices.pushPose(); + matrices.mulPose(new Quaternion(0, time, 0, false)); + textureManager.bind(HORIZON); + be_renderBuffer(matrices, horizon, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, 0.7F * blindA); + matrices.popPose(); + + matrices.pushPose(); + matrices.mulPose(new Quaternion(0, -time, 0, false)); + textureManager.bind(NEBULA_1); + be_renderBuffer(matrices, nebulas1, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02); + matrices.popPose(); + + matrices.pushPose(); + matrices.mulPose(new Quaternion(0, time2, 0, false)); + textureManager.bind(NEBULA_2); + be_renderBuffer(matrices, nebulas2, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind02); + matrices.popPose(); + + textureManager.bind(STARS); + + matrices.pushPose(); + matrices.mulPose(axis3.rotation(time)); + be_renderBuffer(matrices, stars3, DefaultVertexFormat.POSITION_TEX, 0.77F, 0.31F, 0.73F, blind06); + matrices.popPose(); + + matrices.pushPose(); + matrices.mulPose(axis4.rotation(time2)); + be_renderBuffer(matrices, stars4, DefaultVertexFormat.POSITION_TEX, 1F, 1F, 1F, blind06); + matrices.popPose(); } - + float a = (BackgroundInfo.fog - 1F); if (a > 0) { - if (a > 1) - a = 1; - textureManager.bindTexture(FOG); - be_renderBuffer(matrices, fog, VertexFormats.POSITION_TEXTURE, BackgroundInfo.red, BackgroundInfo.green, - BackgroundInfo.blue, a); + if (a > 1) a = 1; + textureManager.bind(FOG); + be_renderBuffer(matrices, fog, DefaultVertexFormat.POSITION_TEX, BackgroundInfo.red, BackgroundInfo.green, BackgroundInfo.blue, a); } RenderSystem.disableTexture(); - + if (blindA > 0) { - matrices.push(); - matrices.multiply(axis1.getRadialQuaternion(time3)); - be_renderBuffer(matrices, stars1, VertexFormats.POSITION, 1, 1, 1, blind06); - matrices.pop(); - - matrices.push(); - matrices.multiply(axis2.getRadialQuaternion(time2)); - be_renderBuffer(matrices, stars2, VertexFormats.POSITION, 0.95F, 0.64F, 0.93F, blind06); - matrices.pop(); + matrices.pushPose(); + matrices.mulPose(axis1.rotation(time3)); + be_renderBuffer(matrices, stars1, DefaultVertexFormat.POSITION, 1, 1, 1, blind06); + matrices.popPose(); + + matrices.pushPose(); + matrices.mulPose(axis2.rotation(time2)); + be_renderBuffer(matrices, stars2, DefaultVertexFormat.POSITION, 0.95F, 0.64F, 0.93F, blind06); + matrices.popPose(); } - + RenderSystem.enableTexture(); RenderSystem.depthMask(true); - + info.cancel(); } } - - private void be_renderBuffer(MatrixStack matrices, VertexBuffer buffer, VertexFormat format, float r, float g, - float b, float a) { + + private void be_renderBuffer(PoseStack matrices, VertexBuffer buffer, VertexFormat format, float r, float g, float b, float a) { RenderSystem.color4f(r, g, b, a); buffer.bind(); - format.startDrawing(0L); - buffer.draw(matrices.peek().getModel(), 7); - VertexBuffer.unbind(); - format.endDrawing(); + format.setupBufferState(0L); + buffer.draw(matrices.last().pose(), 7); + VertexBuffer.unbind(); + format.clearBufferState(); } private void be_initStars() { - BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + BufferBuilder buffer = Tesselator.getInstance().getBuilder(); stars1 = be_buildBufferStars(buffer, stars1, 0.1, 0.30, 3500, 41315); stars2 = be_buildBufferStars(buffer, stars2, 0.1, 0.35, 2000, 35151); stars3 = be_buildBufferUVStars(buffer, stars3, 0.4, 1.2, 1000, 61354); @@ -200,78 +196,75 @@ public class WorldRendererMixin { horizon = be_buildBufferHorizon(buffer, horizon); fog = be_buildBufferFog(buffer, fog); } - - private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, - double maxSize, int count, long seed) { + + private VertexBuffer be_buildBufferStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) { buffer.close(); } - buffer = new VertexBuffer(VertexFormats.POSITION); + buffer = new VertexBuffer(DefaultVertexFormat.POSITION); be_makeStars(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end(); buffer.upload(bufferBuilder); return buffer; } - - private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, - double maxSize, int count, long seed) { + + private VertexBuffer be_buildBufferUVStars(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) { buffer.close(); } - buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE); + buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); be_makeUVStars(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end(); buffer.upload(bufferBuilder); return buffer; } - - private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, - double maxSize, int count, long seed) { + + private VertexBuffer be_buildBufferFarFog(BufferBuilder bufferBuilder, VertexBuffer buffer, double minSize, double maxSize, int count, long seed) { if (buffer != null) { buffer.close(); } - buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE); + buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); be_makeFarFog(bufferBuilder, minSize, maxSize, count, seed); bufferBuilder.end(); buffer.upload(bufferBuilder); return buffer; } - + private VertexBuffer be_buildBufferHorizon(BufferBuilder bufferBuilder, VertexBuffer buffer) { if (buffer != null) { buffer.close(); } - buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE); + buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); be_makeCylinder(bufferBuilder, 16, 50, 100); bufferBuilder.end(); buffer.upload(bufferBuilder); return buffer; } - + private VertexBuffer be_buildBufferFog(BufferBuilder bufferBuilder, VertexBuffer buffer) { if (buffer != null) { buffer.close(); } - buffer = new VertexBuffer(VertexFormats.POSITION_TEXTURE); + buffer = new VertexBuffer(DefaultVertexFormat.POSITION_TEX); be_makeCylinder(bufferBuilder, 16, 50, 70); bufferBuilder.end(); buffer.upload(bufferBuilder); return buffer; } - + private void be_makeStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed); - buffer.begin(7, VertexFormats.POSITION); + buffer.begin(7, DefaultVertexFormat.POSITION); for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0; @@ -306,15 +299,15 @@ public class WorldRendererMixin { double ae = 0.0 * q - aa * r; double af = ae * n - ab * o; double ah = ab * n + ae * o; - buffer.vertex(j + af, k + ad, l + ah).next(); + buffer.vertex(j + af, k + ad, l + ah).endVertex(); } } } } - + private void be_makeUVStars(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed); - buffer.begin(7, VertexFormats.POSITION_TEXTURE); + buffer.begin(7, DefaultVertexFormat.POSITION_TEX); for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0; @@ -353,16 +346,16 @@ public class WorldRendererMixin { double ah = ab * n + ae * o; float texU = (pos >> 1) & 1; float texV = (((pos + 1) >> 1) & 1) / 4F + minV; - pos++; - buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next(); + pos ++; + buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex(); } } } } - + private void be_makeFarFog(BufferBuilder buffer, double minSize, double maxSize, int count, long seed) { Random random = new Random(seed); - buffer.begin(7, VertexFormats.POSITION_TEXTURE); + buffer.begin(7, DefaultVertexFormat.POSITION_TEX); for (int i = 0; i < count; ++i) { double posX = random.nextDouble() * 2.0 - 1.0; @@ -404,30 +397,30 @@ public class WorldRendererMixin { double ah = ab * n + ae * o; float texU = (pos >> 1) & 1; float texV = ((pos + 1) >> 1) & 1; - pos++; - buffer.vertex(j + af, k + ad, l + ah).texture(texU, texV).next(); + pos ++; + buffer.vertex(j + af, k + ad, l + ah).uv(texU, texV).endVertex(); } } } } - + private void be_makeCylinder(BufferBuilder buffer, int segments, double height, double radius) { - buffer.begin(7, VertexFormats.POSITION_TEXTURE); - for (int i = 0; i < segments; i++) { + buffer.begin(7, DefaultVertexFormat.POSITION_TEX); + for (int i = 0; i < segments; i ++) { double a1 = (double) i * Math.PI * 2.0 / (double) segments; double a2 = (double) (i + 1) * Math.PI * 2.0 / (double) segments; double px1 = Math.sin(a1) * radius; double pz1 = Math.cos(a1) * radius; double px2 = Math.sin(a2) * radius; double pz2 = Math.cos(a2) * radius; - + float u0 = (float) i / (float) segments; float u1 = (float) (i + 1) / (float) segments; - - buffer.vertex(px1, -height, pz1).texture(u0, 0).next(); - buffer.vertex(px1, height, pz1).texture(u0, 1).next(); - buffer.vertex(px2, height, pz2).texture(u1, 1).next(); - buffer.vertex(px2, -height, pz2).texture(u1, 0).next(); + + buffer.vertex(px1, -height, pz1).uv(u0, 0).endVertex(); + buffer.vertex(px1, height, pz1).uv(u0, 1).endVertex(); + buffer.vertex(px2, height, pz2).uv(u1, 1).endVertex(); + buffer.vertex(px2, -height, pz2).uv(u1, 0).endVertex(); } } } diff --git a/src/main/java/ru/betterend/mixin/common/AbstractBlockMixin.java b/src/main/java/ru/betterend/mixin/common/AbstractBlockMixin.java index 6f4f77bb..c7f32c8d 100644 --- a/src/main/java/ru/betterend/mixin/common/AbstractBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/AbstractBlockMixin.java @@ -1,33 +1,30 @@ package ru.betterend.mixin.common; import java.util.List; - +import net.minecraft.util.Mth; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; 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 com.google.common.collect.Lists; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.Enchantments; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.storage.loot.LootContext; -import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.minecraft.util.Mth; import ru.betterend.item.tool.EndHammerItem; import ru.betterend.util.MHelper; -@Mixin(AbstractBlock.class) +@Mixin(BlockBehaviour.class) public abstract class AbstractBlockMixin { - - @Inject(method = "getDrops", at = @At("HEAD"), cancellable = true) - public void be_getDroppedStacks(BlockState state, LootContext.Builder builder, - CallbackInfoReturnable> info) { + + @Inject(method = "getDroppedStacks", at = @At("HEAD"), cancellable = true) + public void be_getDroppedStacks(BlockState state, LootContext.Builder builder, CallbackInfoReturnable> info) { if (state.is(Blocks.GLOWSTONE)) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); if (tool != null && tool.getItem() instanceof EndHammerItem) { diff --git a/src/main/java/ru/betterend/mixin/common/AnvilBlockMixin.java b/src/main/java/ru/betterend/mixin/common/AnvilBlockMixin.java index 28c29eb4..19b4f081 100644 --- a/src/main/java/ru/betterend/mixin/common/AnvilBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/AnvilBlockMixin.java @@ -1,13 +1,12 @@ package ru.betterend.mixin.common; -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 net.minecraft.world.level.block.AnvilBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.IntegerProperty; +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 ru.betterend.blocks.basis.EndAnvilBlock; @Mixin(AnvilBlock.class) @@ -15,10 +14,10 @@ public class AnvilBlockMixin { @Inject(method = "getLandingState", at = @At("HEAD"), cancellable = true) private static void be_getLandingState(BlockState fallingState, CallbackInfoReturnable info) { if (fallingState.getBlock() instanceof EndAnvilBlock) { - IntegerProperty destructionProperty = ((EndAnvilBlock) fallingState.getBlock()).getDESTRUCTION(); - int destruction = fallingState.get(destructionProperty); + IntegerProperty destructionProperty = ((EndAnvilBlock) fallingState.getBlock()).getDestructionProperty(); + int destruction = fallingState.getValue(destructionProperty); try { - BlockState state = fallingState.with(destructionProperty, destruction + 1); + BlockState state = fallingState.setValue(destructionProperty, destruction + 1); info.setReturnValue(state); info.cancel(); } catch (Exception ex) { diff --git a/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java b/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java index 9f393acc..28ad1cf7 100644 --- a/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/AnvilScreenHandlerMixin.java @@ -3,103 +3,100 @@ package ru.betterend.mixin.common; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; - +import net.minecraft.tags.BlockTags; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.DataSlot; +import net.minecraft.world.inventory.ItemCombinerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.level.block.AnvilBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; 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.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.level.block.AnvilBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.player.PlayerInventory; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.RecipeManager; -import net.minecraft.screen.AnvilScreenHandler; -import net.minecraft.screen.ForgingScreenHandler; -import net.minecraft.screen.Property; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.tags.BlockTags; import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.interfaces.AnvilScreenHandlerExtended; import ru.betterend.recipe.builders.AnvilRecipe; -@Mixin(AnvilScreenHandler.class) -public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler implements AnvilScreenHandlerExtended { +@Mixin(AnvilMenu.class) +public abstract class AnvilScreenHandlerMixin extends ItemCombinerMenu implements AnvilScreenHandlerExtended { private List be_recipes = Collections.emptyList(); private AnvilRecipe be_currentRecipe; - private Property anvilLevel; + private DataSlot anvilLevel; - public AnvilScreenHandlerMixin(int syncId, PlayerInventory playerInventory) { - super(ScreenHandlerType.ANVIL, syncId, playerInventory, ScreenHandlerContext.EMPTY); + public AnvilScreenHandlerMixin(int syncId, Inventory playerInventory) { + super(MenuType.ANVIL, syncId, playerInventory, ContainerLevelAccess.NULL); } - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/screen/ScreenHandlerContext;)V", at = @At("TAIL")) - public void be_initAnvilLevel(int syncId, PlayerInventory inventory, ScreenHandlerContext context, - CallbackInfo info) { - if (context != ScreenHandlerContext.EMPTY) { - int anvLevel = context.run((world, blockPos) -> { + @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/screen/ScreenHandlerContext;)V", + at = @At("TAIL")) + public void be_initAnvilLevel(int syncId, Inventory inventory, ContainerLevelAccess context, CallbackInfo info) { + if (context != ContainerLevelAccess.NULL) { + int anvLevel = context.evaluate((world, blockPos) -> { Block anvilBlock = world.getBlockState(blockPos).getBlock(); if (anvilBlock instanceof EndAnvilBlock) { return ((EndAnvilBlock) anvilBlock).getCraftingLevel(); } return 1; }, 1); - Property anvilLevel = Property.create(); + DataSlot anvilLevel = DataSlot.standalone(); anvilLevel.set(anvLevel); - this.anvilLevel = addProperty(anvilLevel); + this.anvilLevel = addDataSlot(anvilLevel); } } - + @Shadow - public abstract void updateResult(); - + public abstract void createResult(); + @Inject(method = "canTakeOutput", at = @At("HEAD"), cancellable = true) protected void be_canTakeOutput(Player player, boolean present, CallbackInfoReturnable info) { if (be_currentRecipe != null) { - info.setReturnValue(be_currentRecipe.checkHammerDurability(input, player)); + info.setReturnValue(be_currentRecipe.checkHammerDurability(inputSlots, player)); } } - + @Inject(method = "onTakeOutput", at = @At("HEAD"), cancellable = true) protected void be_onTakeOutput(Player player, ItemStack stack, CallbackInfoReturnable info) { if (be_currentRecipe != null) { - this.input.getStack(0).decrement(be_currentRecipe.getInputCount()); - stack = be_currentRecipe.craft(input, player); - this.onContentChanged(input); - this.context.run((world, blockPos) -> { + this.inputSlots.getItem(0).shrink(be_currentRecipe.getInputCount()); + stack = be_currentRecipe.craft(inputSlots, player); + this.slotsChanged(inputSlots); + this.access.execute((world, blockPos) -> { BlockState anvilState = world.getBlockState(blockPos); - if (!player.abilities.creativeMode && anvilState.isIn(BlockTags.ANVIL) - && player.getRandom().nextFloat() < 0.12F) { - BlockState landingState = AnvilBlock.getLandingState(anvilState); + if (!player.abilities.instabuild && anvilState.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) { + BlockState landingState = AnvilBlock.damage(anvilState); if (landingState == null) { world.removeBlock(blockPos, false); - world.syncWorldEvent(1029, blockPos, 0); + world.levelEvent(1029, blockPos, 0); } else { - world.setBlockAndUpdate(blockPos, landingState, 2); - world.syncWorldEvent(1030, blockPos, 0); + world.setBlock(blockPos, landingState, 2); + world.levelEvent(1030, blockPos, 0); } } else { - world.syncWorldEvent(1030, blockPos, 0); + world.levelEvent(1030, blockPos, 0); } }); info.setReturnValue(stack); } } - + @Inject(method = "updateResult", at = @At("HEAD"), cancellable = true) public void be_updateOutput(CallbackInfo info) { - RecipeManager recipeManager = this.player.world.getRecipeManager(); - be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world); + RecipeManager recipeManager = this.player.level.getRecipeManager(); + be_recipes = recipeManager.getRecipesFor(AnvilRecipe.TYPE, inputSlots, player.level); if (be_recipes.size() > 0) { int anvilLevel = this.anvilLevel.get(); - be_recipes = be_recipes.stream().filter(recipe -> anvilLevel >= recipe.getAnvilLevel()) - .collect(Collectors.toList()); + be_recipes = be_recipes.stream().filter(recipe -> + anvilLevel >= recipe.getAnvilLevel()).collect(Collectors.toList()); if (be_recipes.size() > 0) { if (be_currentRecipe == null || !be_recipes.contains(be_currentRecipe)) { be_currentRecipe = be_recipes.get(0); @@ -111,16 +108,16 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple } } } - + @Inject(method = "setNewItemName", at = @At("HEAD"), cancellable = true) public void be_setNewItemName(String string, CallbackInfo info) { if (be_currentRecipe != null) { info.cancel(); } } - + @Override - public boolean onButtonClick(Player player, int id) { + public boolean clickMenuButton(Player player, int id) { if (id == 0) { this.be_previousRecipe(); return true; @@ -128,27 +125,26 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple this.be_nextRecipe(); return true; } - return super.onButtonClick(player, id); + return super.clickMenuButton(player, id); } - + private void be_updateResult() { - if (be_currentRecipe == null) - return; - this.output.setStack(0, be_currentRecipe.craft(input)); - this.sendContentUpdates(); + if (be_currentRecipe == null) return; + this.resultSlots.setItem(0, be_currentRecipe.assemble(inputSlots)); + this.broadcastChanges(); } - + @Override public void be_updateCurrentRecipe(AnvilRecipe recipe) { this.be_currentRecipe = recipe; this.be_updateResult(); } - + @Override public AnvilRecipe be_getCurrentRecipe() { return this.be_currentRecipe; } - + @Override public List be_getRecipes() { return this.be_recipes; diff --git a/src/main/java/ru/betterend/mixin/common/ArmorItemAccessor.java b/src/main/java/ru/betterend/mixin/common/ArmorItemAccessor.java index 3f55c6ef..ce903a6e 100644 --- a/src/main/java/ru/betterend/mixin/common/ArmorItemAccessor.java +++ b/src/main/java/ru/betterend/mixin/common/ArmorItemAccessor.java @@ -1,16 +1,14 @@ package ru.betterend.mixin.common; import java.util.UUID; - +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.item.ArmorItem; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import com.google.common.collect.Multimap; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.item.ArmorItem; - @Mixin(ArmorItem.class) public interface ArmorItemAccessor { @Accessor("MODIFIERS") diff --git a/src/main/java/ru/betterend/mixin/common/BiomeArrayMixin.java b/src/main/java/ru/betterend/mixin/common/BiomeArrayMixin.java index 409ca5b6..13da34e7 100644 --- a/src/main/java/ru/betterend/mixin/common/BiomeArrayMixin.java +++ b/src/main/java/ru/betterend/mixin/common/BiomeArrayMixin.java @@ -1,16 +1,15 @@ package ru.betterend.mixin.common; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.source.BiomeArray; +import net.minecraft.world.level.chunk.ChunkBiomeContainer; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import ru.betterend.interfaces.IBiomeArray; -@Mixin(BiomeArray.class) +@Mixin(ChunkBiomeContainer.class) public class BiomeArrayMixin implements IBiomeArray { @Final @Shadow diff --git a/src/main/java/ru/betterend/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/betterend/mixin/common/BoneMealItemMixin.java index 0eff76c9..aaf77045 100644 --- a/src/main/java/ru/betterend/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/betterend/mixin/common/BoneMealItemMixin.java @@ -1,23 +1,21 @@ package ru.betterend.mixin.common; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BoneMealItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; 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 net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.BoneMealItem; -import net.minecraft.world.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome.Category; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -31,14 +29,14 @@ public class BoneMealItemMixin { private static final MutableBlockPos POS = new MutableBlockPos(); @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - private void be_onUse(ItemUsageContext context, CallbackInfoReturnable info) { + private void be_onUse(UseOnContext context, CallbackInfoReturnable info) { Level world = context.getLevel(); - BlockPos blockPos = context.getBlockPos(); + BlockPos blockPos = context.getClickedPos(); if (!world.isClientSide) { - BlockPos offseted = blockPos.offset(context.getSide()); - boolean endBiome = world.getBiome(offseted).getCategory() == Category.THEEND; - - if (world.getBlockState(blockPos).isIn(EndTags.END_GROUND)) { + BlockPos offseted = blockPos.relative(context.getClickedFace()); + boolean endBiome = world.getBiome(offseted).getBiomeCategory() == BiomeCategory.THEEND; + + if (world.getBlockState(blockPos).is(EndTags.END_GROUND)) { boolean consume = false; if (world.getBlockState(blockPos).is(Blocks.END_STONE)) { BlockState nylium = beGetNylium(world, blockPos); @@ -46,32 +44,35 @@ public class BoneMealItemMixin { BlocksHelper.setWithoutUpdate(world, blockPos, nylium); consume = true; } - } else { + } + else { if (!world.getFluidState(offseted).isEmpty() && endBiome) { if (world.getBlockState(offseted).getBlock().equals(Blocks.WATER)) { consume = beGrowWaterGrass(world, blockPos); } - } else { + } + else { consume = beGrowGrass(world, blockPos); } } if (consume) { if (!context.getPlayer().isCreative()) { - context.getStack().decrement(1); + context.getItemInHand().shrink(1); } - world.syncWorldEvent(2005, blockPos, 0); - info.setReturnValue(ActionResult.SUCCESS); + world.levelEvent(2005, blockPos, 0); + info.setReturnValue(InteractionResult.SUCCESS); info.cancel(); } - } else if (!world.getFluidState(offseted).isEmpty() && endBiome) { + } + else if (!world.getFluidState(offseted).isEmpty() && endBiome) { if (world.getBlockState(offseted).getBlock().equals(Blocks.WATER)) { - info.setReturnValue(ActionResult.FAIL); + info.setReturnValue(InteractionResult.FAIL); info.cancel(); } } } } - + private boolean beGrowGrass(Level world, BlockPos pos) { int y1 = pos.getY() + 3; int y2 = pos.getY() - 3; @@ -84,7 +85,7 @@ public class BoneMealItemMixin { for (int y = y1; y >= y2; y--) { POS.setY(y); BlockPos down = POS.below(); - if (world.isAir(POS) && !world.isAir(down)) { + if (world.isEmptyBlock(POS) && !world.isEmptyBlock(down)) { BlockState grass = beGetGrassState(world, down); if (grass != null) { BlocksHelper.setWithoutUpdate(world, POS, grass); @@ -96,7 +97,7 @@ public class BoneMealItemMixin { } return result; } - + private boolean beGrowWaterGrass(Level world, BlockPos pos) { int y1 = pos.getY() + 3; int y2 = pos.getY() - 3; @@ -109,7 +110,7 @@ public class BoneMealItemMixin { for (int y = y1; y >= y2; y--) { POS.setY(y); BlockPos down = POS.below(); - if (world.getBlockState(POS).is(Blocks.WATER) && world.getBlockState(down).isIn(EndTags.END_GROUND)) { + if (world.getBlockState(POS).is(Blocks.WATER) && world.getBlockState(down).is(EndTags.END_GROUND)) { BlockState grass = beGetWaterGrassState(world, down); if (grass != null) { BlocksHelper.setWithoutUpdate(world, POS, grass); @@ -121,26 +122,26 @@ public class BoneMealItemMixin { } return result; } - + private BlockState beGetGrassState(Level world, BlockPos pos) { BlockState state = world.getBlockState(pos); Block block = state.getBlock(); block = BonemealUtil.getGrass(EndBiomes.getBiomeID(world.getBiome(pos)), block, world.getRandom()); return block == null ? null : block.defaultBlockState(); } - + private BlockState beGetWaterGrassState(Level world, BlockPos pos) { EndBiome biome = EndBiomes.getFromBiome(world.getBiome(pos)); if (world.random.nextInt(16) == 0) { return EndBlocks.CHARNIA_RED.defaultBlockState(); - } else if (biome == EndBiomes.FOGGY_MUSHROOMLAND || biome == EndBiomes.MEGALAKE - || biome == EndBiomes.MEGALAKE_GROVE) { - return world.random.nextBoolean() ? EndBlocks.CHARNIA_LIGHT_BLUE.defaultBlockState() - : EndBlocks.CHARNIA_LIGHT_BLUE.defaultBlockState(); - } else if (biome == EndBiomes.AMBER_LAND) { - return world.random.nextBoolean() ? EndBlocks.CHARNIA_ORANGE.defaultBlockState() - : EndBlocks.CHARNIA_RED.defaultBlockState(); - } else if (biome == EndBiomes.CHORUS_FOREST || biome == EndBiomes.SHADOW_FOREST) { + } + else if (biome == EndBiomes.FOGGY_MUSHROOMLAND || biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) { + return world.random.nextBoolean() ? EndBlocks.CHARNIA_LIGHT_BLUE.defaultBlockState() : EndBlocks.CHARNIA_LIGHT_BLUE.defaultBlockState(); + } + else if (biome == EndBiomes.AMBER_LAND) { + return world.random.nextBoolean() ? EndBlocks.CHARNIA_ORANGE.defaultBlockState() : EndBlocks.CHARNIA_RED.defaultBlockState(); + } + else if (biome == EndBiomes.CHORUS_FOREST || biome == EndBiomes.SHADOW_FOREST) { return EndBlocks.CHARNIA_PURPLE.defaultBlockState(); } return null; diff --git a/src/main/java/ru/betterend/mixin/common/BrewingAccessor.java b/src/main/java/ru/betterend/mixin/common/BrewingAccessor.java index b198c6c1..0093c018 100644 --- a/src/main/java/ru/betterend/mixin/common/BrewingAccessor.java +++ b/src/main/java/ru/betterend/mixin/common/BrewingAccessor.java @@ -1,13 +1,12 @@ package ru.betterend.mixin.common; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - import net.minecraft.world.item.Item; import net.minecraft.world.item.alchemy.Potion; -import net.minecraft.world.item.crafting.BrewingRecipeRegistry; +import net.minecraft.world.item.alchemy.PotionBrewing; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; -@Mixin(BrewingRecipeRegistry.class) +@Mixin(PotionBrewing.class) public interface BrewingAccessor { @Invoker static void callRegisterPotionRecipe(Potion input, Item item, Potion output) { diff --git a/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java index ac47da86..570963f9 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusFlowerBlockMixin.java @@ -1,7 +1,21 @@ package ru.betterend.mixin.common; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChorusFlowerBlock; +import net.minecraft.world.level.block.ChorusPlantBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -10,22 +24,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ChorusFlowerBlock; -import net.minecraft.world.level.block.ChorusPlantBlock; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.state.property.Properties; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -33,83 +31,78 @@ import ru.betterend.world.generator.GeneratorOptions; @Mixin(value = ChorusFlowerBlock.class, priority = 100) public abstract class ChorusFlowerBlockMixin extends Block { - private static final VoxelShape SHAPE_FULL = Block.createCuboidShape(0, 0, 0, 16, 16, 16); - private static final VoxelShape SHAPE_HALF = Block.createCuboidShape(0, 0, 0, 16, 4, 16); - - public ChorusFlowerBlockMixin(net.minecraft.world.level.block.state.BlockBehaviour.Properties settings) { + private static final VoxelShape SHAPE_FULL = Block.box(0, 0, 0, 16, 16, 16); + private static final VoxelShape SHAPE_HALF = Block.box(0, 0, 0, 16, 4, 16); + + public ChorusFlowerBlockMixin(Properties settings) { super(settings); } @Shadow @Final private ChorusPlantBlock plantBlock; - + @Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true) - private void beCanPlace(BlockState state, WorldView world, BlockPos pos, CallbackInfoReturnable info) { + private void beCanPlace(BlockState state, LevelReader world, BlockPos pos, CallbackInfoReturnable info) { if (world.getBlockState(pos.below()).is(EndBlocks.CHORUS_NYLIUM)) { info.setReturnValue(true); info.cancel(); } } - + @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) private void beOnTick(BlockState state, ServerLevel world, BlockPos pos, Random random, CallbackInfo info) { - if (world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { - BlockPos up = pos.up(); - if (world.isAir(up) && up.getY() < 256) { + if (world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { + BlockPos up = pos.above(); + if (world.isEmptyBlock(up) && up.getY() < 256) { int i = state.getValue(ChorusFlowerBlock.AGE); if (i < 5) { this.grow(world, up, i + 1); if (GeneratorOptions.changeChorusPlant()) { - BlocksHelper.setWithoutUpdate(world, pos, - plantBlock.defaultBlockState().with(ChorusPlantBlock.UP, true) - .with(ChorusPlantBlock.DOWN, true).with(BlocksHelper.ROOTS, true)); - } else { - BlocksHelper.setWithoutUpdate(world, pos, plantBlock.defaultBlockState() - .with(ChorusPlantBlock.UP, true).with(ChorusPlantBlock.DOWN, true)); + BlocksHelper.setWithoutUpdate(world, pos, plantBlock.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true).setValue(BlocksHelper.ROOTS, true)); + } + else { + BlocksHelper.setWithoutUpdate(world, pos, plantBlock.defaultBlockState().setValue(ChorusPlantBlock.UP, true).setValue(ChorusPlantBlock.DOWN, true)); } info.cancel(); } } } } - + @Inject(method = "generate", at = @At("RETURN"), cancellable = true) private static void beOnGenerate(LevelAccessor world, BlockPos pos, Random random, int size, CallbackInfo info) { BlockState state = world.getBlockState(pos); if (GeneratorOptions.changeChorusPlant() && state.is(Blocks.CHORUS_PLANT)) { - BlocksHelper.setWithoutUpdate(world, pos, state.with(BlocksHelper.ROOTS, true)); + BlocksHelper.setWithoutUpdate(world, pos, state.setValue(BlocksHelper.ROOTS, true)); } } - + @Shadow - private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { - return false; - } - + private static boolean isSurroundedByAir(LevelReader world, BlockPos pos, @Nullable Direction exceptDirection) { return false; } + @Shadow - private void grow(Level world, BlockPos pos, int age) { - } - + private void grow(Level world, BlockPos pos, int age) {} + @Shadow - private void die(Level world, BlockPos pos) { - } - + private void die(Level world, BlockPos pos) {} + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { if (GeneratorOptions.changeChorusPlant()) { return state.getValue(ChorusFlowerBlock.AGE) == 5 ? SHAPE_HALF : SHAPE_FULL; - } else { - return super.getOutlineShape(state, world, pos, context); + } + else { + return super.getShape(state, world, pos, context); } } @Inject(method = "die", at = @At("HEAD"), cancellable = true) private void beOnDie(Level world, BlockPos pos, CallbackInfo info) { BlockState down = world.getBlockState(pos.below()); - if (down.is(Blocks.CHORUS_PLANT) || down.isIn(EndTags.GEN_TERRAIN)) { - world.setBlockAndUpdate(pos, this.defaultBlockState().with(Properties.AGE_5, 5), 2); - world.syncWorldEvent(1034, pos, 0); + if (down.is(Blocks.CHORUS_PLANT) || down.is(EndTags.GEN_TERRAIN)) { + world.setBlock(pos, this.defaultBlockState().setValue(BlockStateProperties.AGE_5, 5), 2); + world.levelEvent(1034, pos, 0); } info.cancel(); } diff --git a/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java index 99535afb..8b5e0fd7 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusPlantBlockMixin.java @@ -1,25 +1,24 @@ package ru.betterend.mixin.common; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChorusPlantBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; 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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ChorusPlantBlock; -import net.minecraft.world.item.ItemPlacementContext; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.state.property.Properties; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.WorldView; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -27,69 +26,72 @@ import ru.betterend.world.generator.GeneratorOptions; @Mixin(value = ChorusPlantBlock.class, priority = 100) public abstract class ChorusPlantBlockMixin extends Block { - public ChorusPlantBlockMixin(net.minecraft.world.level.block.state.BlockBehaviour.Properties settings) { + public ChorusPlantBlockMixin(Properties settings) { super(settings); } @Inject(method = "*", at = @At("TAIL")) - private void beOnInit(AbstractBlock.Properties settings, CallbackInfo info) { + private void beOnInit(BlockBehaviour.Properties settings, CallbackInfo info) { if (GeneratorOptions.changeChorusPlant()) { - this.setDefaultState(this.defaultBlockState().with(BlocksHelper.ROOTS, false)); + this.registerDefaultState(this.defaultBlockState().setValue(BlocksHelper.ROOTS, false)); } } - - @Inject(method = "createBlockStateDefinition", at = @At("TAIL")) + + @Inject(method = "appendProperties", at = @At("TAIL")) private void beAddProperties(StateDefinition.Builder builder, CallbackInfo info) { GeneratorOptions.init(); if (GeneratorOptions.changeChorusPlant()) { builder.add(BlocksHelper.ROOTS); } } - + @Inject(method = "withConnectionProperties", at = @At("RETURN"), cancellable = true) - private void beConnectionProperties(BlockView world, BlockPos pos, CallbackInfoReturnable info) { + private void beConnectionProperties(BlockGetter world, BlockPos pos, CallbackInfoReturnable info) { BlockState plant = info.getReturnValue(); if (plant.is(Blocks.CHORUS_PLANT)) { - if (world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + if (world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.with(Properties.DOWN, true).with(BlocksHelper.ROOTS, true)); - } else { - info.setReturnValue(plant.with(Properties.DOWN, true)); + info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true).setValue(BlocksHelper.ROOTS, true)); + } + else { + info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); } info.cancel(); - } else { + } + else { if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.with(BlocksHelper.ROOTS, false)); + info.setReturnValue(plant.setValue(BlocksHelper.ROOTS, false)); } info.cancel(); } } } - + @Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true) - private void beCanPlace(BlockState state, WorldView world, BlockPos pos, CallbackInfoReturnable info) { + private void beCanPlace(BlockState state, LevelReader world, BlockPos pos, CallbackInfoReturnable info) { BlockState down = world.getBlockState(pos.below()); if (down.is(EndBlocks.CHORUS_NYLIUM) || down.is(Blocks.END_STONE)) { info.setReturnValue(true); info.cancel(); } } - - @Inject(method = "updateShape", at = @At("RETURN"), cancellable = true) - private void beStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, - LevelAccessor world, BlockPos pos, BlockPos posFrom, CallbackInfoReturnable info) { + + @Inject(method = "getStateForNeighborUpdate", at = @At("RETURN"), cancellable = true) + private void beStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom, CallbackInfoReturnable info) { BlockState plant = info.getReturnValue(); if (plant.is(Blocks.CHORUS_PLANT)) { - if (world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + if (world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { if (GeneratorOptions.changeChorusPlant()) { - plant = plant.with(Properties.DOWN, true).with(BlocksHelper.ROOTS, true); - } else { - plant = plant.with(Properties.DOWN, true); + plant = plant.setValue(BlockStateProperties.DOWN, true).setValue(BlocksHelper.ROOTS, true); + } + else { + plant = plant.setValue(BlockStateProperties.DOWN, true); } info.cancel(); - } else { + } + else { if (GeneratorOptions.changeChorusPlant()) { - plant = plant.with(BlocksHelper.ROOTS, false); + plant = plant.setValue(BlocksHelper.ROOTS, false); } info.cancel(); } @@ -97,18 +99,18 @@ public abstract class ChorusPlantBlockMixin extends Block { info.cancel(); } } - + @Inject(method = "getPlacementState", at = @At("RETURN"), cancellable = true) - private void beGetPlacementState(ItemPlacementContext ctx, CallbackInfoReturnable info) { - BlockPos pos = ctx.getBlockPos(); + private void beGetPlacementState(BlockPlaceContext ctx, CallbackInfoReturnable info) { + BlockPos pos = ctx.getClickedPos(); Level world = ctx.getLevel(); BlockState plant = info.getReturnValue(); - if (ctx.canPlace() && plant.is(Blocks.CHORUS_PLANT) - && world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + if (ctx.canPlace() && plant.is(Blocks.CHORUS_PLANT) && world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { if (GeneratorOptions.changeChorusPlant()) { - info.setReturnValue(plant.with(BlocksHelper.ROOTS, true).with(Properties.DOWN, true)); - } else { - info.setReturnValue(plant.with(Properties.DOWN, true)); + info.setReturnValue(plant.setValue(BlocksHelper.ROOTS, true).setValue(BlockStateProperties.DOWN, true)); + } + else { + info.setReturnValue(plant.setValue(BlockStateProperties.DOWN, true)); } info.cancel(); } diff --git a/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java b/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java index 7c1e2638..fee8e1f9 100644 --- a/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ChorusPlantFeatureMixin.java @@ -1,21 +1,19 @@ package ru.betterend.mixin.common; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChorusFlowerBlock; +import net.minecraft.world.level.block.PipeBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.feature.ChorusPlantFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; 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 net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.ChorusFlowerBlock; -import net.minecraft.world.level.block.ConnectingBlock; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.ChorusPlantFeature; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -24,19 +22,16 @@ import ru.betterend.world.generator.GeneratorOptions; @Mixin(ChorusPlantFeature.class) public class ChorusPlantFeatureMixin { @Inject(method = "generate", at = @At("HEAD"), cancellable = true) - private void be_onGenerate(WorldGenLevel structureWorldAccess, ChunkGenerator chunkGenerator, Random random, - BlockPos blockPos, NoneFeatureConfiguration defaultFeatureConfig, CallbackInfoReturnable info) { - if (structureWorldAccess.isAir(blockPos) - && structureWorldAccess.getBlockState(blockPos.below()).is(EndBlocks.CHORUS_NYLIUM)) { - ChorusFlowerBlock.generate(structureWorldAccess, blockPos, random, MHelper.randRange(8, 16, random)); + private void be_onGenerate(WorldGenLevel structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, NoneFeatureConfiguration defaultFeatureConfig, CallbackInfoReturnable info) { + if (structureWorldAccess.isEmptyBlock(blockPos) && structureWorldAccess.getBlockState(blockPos.below()).is(EndBlocks.CHORUS_NYLIUM)) { + ChorusFlowerBlock.generatePlant(structureWorldAccess, blockPos, random, MHelper.randRange(8, 16, random)); BlockState bottom = structureWorldAccess.getBlockState(blockPos); if (bottom.is(Blocks.CHORUS_PLANT)) { if ((GeneratorOptions.changeChorusPlant())) { - BlocksHelper.setWithoutUpdate(structureWorldAccess, blockPos, - bottom.with(BlocksHelper.ROOTS, true).with(ConnectingBlock.DOWN, true)); - } else { - BlocksHelper.setWithoutUpdate(structureWorldAccess, blockPos, - bottom.with(ConnectingBlock.DOWN, true)); + BlocksHelper.setWithoutUpdate(structureWorldAccess, blockPos, bottom.setValue(BlocksHelper.ROOTS, true).setValue(PipeBlock.DOWN, true)); + } + else { + BlocksHelper.setWithoutUpdate(structureWorldAccess, blockPos, bottom.setValue(PipeBlock.DOWN, true)); } } info.setReturnValue(true); diff --git a/src/main/java/ru/betterend/mixin/common/ComposterBlockAccessor.java b/src/main/java/ru/betterend/mixin/common/ComposterBlockAccessor.java index bf506f0c..9152b3fd 100644 --- a/src/main/java/ru/betterend/mixin/common/ComposterBlockAccessor.java +++ b/src/main/java/ru/betterend/mixin/common/ComposterBlockAccessor.java @@ -1,11 +1,10 @@ package ru.betterend.mixin.common; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.ComposterBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; -import net.minecraft.world.level.block.ComposterBlock; -import net.minecraft.world.level.ItemLike; - @Mixin(ComposterBlock.class) public interface ComposterBlockAccessor { @Invoker diff --git a/src/main/java/ru/betterend/mixin/common/CraftingScreenHandlerMixin.java b/src/main/java/ru/betterend/mixin/common/CraftingScreenHandlerMixin.java index 426ca0c4..6b4f898a 100644 --- a/src/main/java/ru/betterend/mixin/common/CraftingScreenHandlerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/CraftingScreenHandlerMixin.java @@ -1,5 +1,9 @@ package ru.betterend.mixin.common; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.CraftingMenu; +import net.minecraft.world.level.block.CraftingTableBlock; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -7,20 +11,16 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.world.level.block.CraftingTableBlock; -import net.minecraft.world.entity.player.Player; -import net.minecraft.screen.CraftingScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; - -@Mixin(CraftingScreenHandler.class) -public abstract class CraftingScreenHandlerMixin { +@Mixin(CraftingMenu.class) +public abstract class CraftingScreenHandlerMixin +{ @Shadow @Final - private ScreenHandlerContext context; + private ContainerLevelAccess context; @Inject(method = "canUse", at = @At("HEAD"), cancellable = true) private void be_canUse(Player player, CallbackInfoReturnable info) { - if (context.run((world, pos) -> { + if (context.evaluate((world, pos) -> { return world.getBlockState(pos).getBlock() instanceof CraftingTableBlock; }, true)) { info.setReturnValue(true); diff --git a/src/main/java/ru/betterend/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/betterend/mixin/common/DimensionTypeMixin.java index 8a974c38..b25e55cc 100644 --- a/src/main/java/ru/betterend/mixin/common/DimensionTypeMixin.java +++ b/src/main/java/ru/betterend/mixin/common/DimensionTypeMixin.java @@ -1,31 +1,28 @@ package ru.betterend.mixin.common; +import net.minecraft.core.Registry; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; 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 net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import net.minecraft.world.gen.chunk.NoiseChunkGenerator; import ru.betterend.world.generator.BetterEndBiomeSource; import ru.betterend.world.generator.GeneratorOptions; @Mixin(value = DimensionType.class, priority = 100) public class DimensionTypeMixin { @Inject(method = "createEndGenerator", at = @At("HEAD"), cancellable = true) - private static void be_replaceGenerator(Registry biomeRegistry, - Registry chunkGeneratorSettingsRegistry, long seed, - CallbackInfoReturnable info) { - info.setReturnValue(new NoiseChunkGenerator(new BetterEndBiomeSource(biomeRegistry, seed), seed, () -> { - return (ChunkGeneratorSettings) chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.END); + private static void be_replaceGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed, CallbackInfoReturnable info) { + info.setReturnValue(new NoiseBasedChunkGenerator(new BetterEndBiomeSource(biomeRegistry, seed), seed, () -> { + return (NoiseGeneratorSettings) chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END); })); info.cancel(); } - + @Inject(method = "hasEnderDragonFight", at = @At("HEAD"), cancellable = true) private void be_hasEnderDragonFight(CallbackInfoReturnable info) { if (!GeneratorOptions.hasDragonFights()) { diff --git a/src/main/java/ru/betterend/mixin/common/EnchantmentScreenHandlerMixin.java b/src/main/java/ru/betterend/mixin/common/EnchantmentScreenHandlerMixin.java index faba5e67..2b0e27e3 100644 --- a/src/main/java/ru/betterend/mixin/common/EnchantmentScreenHandlerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EnchantmentScreenHandlerMixin.java @@ -2,35 +2,33 @@ package ru.betterend.mixin.common; import java.util.List; import java.util.Random; - +import net.minecraft.core.Registry; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.DataSlot; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.EnchantmentInstance; import org.spongepowered.asm.mixin.Final; 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.CallbackInfo; - -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.item.enchantment.EnchantmentLevelEntry; -import net.minecraft.inventory.Inventory; -import net.minecraft.world.item.ItemStack; -import net.minecraft.screen.EnchantmentScreenHandler; -import net.minecraft.screen.Property; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.ScreenHandlerContext; -import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.core.Registry; import ru.betterend.registry.EndTags; -@Mixin(EnchantmentScreenHandler.class) -public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { +@Mixin(EnchantmentMenu.class) +public abstract class EnchantmentScreenHandlerMixin extends AbstractContainerMenu { @Shadow @Final - private Inventory inventory; + private Container inventory; @Shadow @Final - private ScreenHandlerContext context; + private ContainerLevelAccess context; @Shadow @Final @@ -38,7 +36,7 @@ public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { @Shadow @Final - private Property seed; + private DataSlot seed; @Shadow @Final @@ -52,45 +50,44 @@ public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { @Final public int[] enchantmentLevel; - protected EnchantmentScreenHandlerMixin(ScreenHandlerType type, int syncId) { + protected EnchantmentScreenHandlerMixin(MenuType type, int syncId) { super(type, syncId); } @Inject(method = "onContentChanged", at = @At("HEAD"), cancellable = true) - private void beOnContentChanged(Inventory inventory, CallbackInfo info) { + private void beOnContentChanged(Container inventory, CallbackInfo info) { if (inventory == this.inventory) { - ItemStack itemStack = inventory.getStack(0); + ItemStack itemStack = inventory.getItem(0); if (!itemStack.isEmpty() && itemStack.isEnchantable()) { - this.context.run((world, blockPos) -> { + this.context.execute((world, blockPos) -> { int i = 0; int j; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { - if ((j != 0 || k != 0) && world.isAir(blockPos.add(k, 0, j)) - && world.isAir(blockPos.add(k, 1, j))) { - if (world.getBlockState(blockPos.add(k * 2, 0, j * 2)).isIn(EndTags.BOOKSHELVES)) { + if ((j != 0 || k != 0) && world.isEmptyBlock(blockPos.offset(k, 0, j)) && world.isEmptyBlock(blockPos.offset(k, 1, j))) { + if (world.getBlockState(blockPos.offset(k * 2, 0, j * 2)).is(EndTags.BOOKSHELVES)) { ++i; } - if (world.getBlockState(blockPos.add(k * 2, 1, j * 2)).isIn(EndTags.BOOKSHELVES)) { + if (world.getBlockState(blockPos.offset(k * 2, 1, j * 2)).is(EndTags.BOOKSHELVES)) { ++i; } if (k != 0 && j != 0) { - if (world.getBlockState(blockPos.add(k * 2, 0, j)).isIn(EndTags.BOOKSHELVES)) { + if (world.getBlockState(blockPos.offset(k * 2, 0, j)).is(EndTags.BOOKSHELVES)) { ++i; } - if (world.getBlockState(blockPos.add(k * 2, 1, j)).isIn(EndTags.BOOKSHELVES)) { + if (world.getBlockState(blockPos.offset(k * 2, 1, j)).is(EndTags.BOOKSHELVES)) { ++i; } - if (world.getBlockState(blockPos.add(k, 0, j * 2)).isIn(EndTags.BOOKSHELVES)) { + if (world.getBlockState(blockPos.offset(k, 0, j * 2)).is(EndTags.BOOKSHELVES)) { ++i; } - if (world.getBlockState(blockPos.add(k, 1, j * 2)).isIn(EndTags.BOOKSHELVES)) { + if (world.getBlockState(blockPos.offset(k, 1, j * 2)).is(EndTags.BOOKSHELVES)) { ++i; } } @@ -101,8 +98,7 @@ public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { this.random.setSeed((long) this.seed.get()); for (j = 0; j < 3; ++j) { - this.enchantmentPower[j] = EnchantmentHelper.calculateRequiredExperienceLevel(this.random, j, i, - itemStack); + this.enchantmentPower[j] = EnchantmentHelper.getEnchantmentCost(this.random, j, i, itemStack); this.enchantmentId[j] = -1; this.enchantmentLevel[j] = -1; if (this.enchantmentPower[j] < j + 1) { @@ -112,21 +108,19 @@ public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { for (j = 0; j < 3; ++j) { if (this.enchantmentPower[j] > 0) { - List list = this.generateEnchantments(itemStack, j, - this.enchantmentPower[j]); + List list = this.generateEnchantments(itemStack, j, this.enchantmentPower[j]); if (list != null && !list.isEmpty()) { - EnchantmentLevelEntry enchantmentLevelEntry = (EnchantmentLevelEntry) list - .get(this.random.nextInt(list.size())); - this.enchantmentId[j] = Registry.ENCHANTMENT - .getRawId(enchantmentLevelEntry.enchantment); + EnchantmentInstance enchantmentLevelEntry = (EnchantmentInstance) list.get(this.random.nextInt(list.size())); + this.enchantmentId[j] = Registry.ENCHANTMENT.getId(enchantmentLevelEntry.enchantment); this.enchantmentLevel[j] = enchantmentLevelEntry.level; } } } - this.sendContentUpdates(); + this.broadcastChanges(); }); - } else { + } + else { for (int i = 0; i < 3; ++i) { this.enchantmentPower[i] = 0; this.enchantmentId[i] = -1; @@ -138,7 +132,7 @@ public abstract class EnchantmentScreenHandlerMixin extends ScreenHandler { } @Shadow - private List generateEnchantments(ItemStack stack, int slot, int level) { + private List generateEnchantments(ItemStack stack, int slot, int level) { return null; } } diff --git a/src/main/java/ru/betterend/mixin/common/EndCityFeatureMixin.java b/src/main/java/ru/betterend/mixin/common/EndCityFeatureMixin.java index 6faa563f..55d6b7c5 100644 --- a/src/main/java/ru/betterend/mixin/common/EndCityFeatureMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EndCityFeatureMixin.java @@ -1,41 +1,40 @@ package ru.betterend.mixin.common; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.WorldgenRandom; +import net.minecraft.world.level.levelgen.feature.EndCityFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; 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; - -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.source.BiomeSource; -import net.minecraft.world.gen.ChunkRandom; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.level.levelgen.feature.EndCityFeature; import ru.betterend.world.generator.GeneratorOptions; @Mixin(EndCityFeature.class) public class EndCityFeatureMixin { @Inject(method = "shouldStartAt", at = @At("HEAD"), cancellable = true) - private void be_shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long l, - ChunkRandom chunkRandom, int i, int j, Biome biome, ChunkPos chunkPos, - NoneFeatureConfiguration defaultFeatureConfig, CallbackInfoReturnable info) { + private void be_shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long l, WorldgenRandom chunkRandom, int i, int j, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration defaultFeatureConfig, CallbackInfoReturnable info) { if (GeneratorOptions.useNewGenerator()) { int chance = GeneratorOptions.getEndCityFailChance(); if (chance == 0) { info.setReturnValue(getGenerationHeight(i, j, chunkGenerator) >= 60); info.cancel(); - } else if (chunkRandom.nextInt(chance) == 0) { + } + else if (chunkRandom.nextInt(chance) == 0){ info.setReturnValue(getGenerationHeight(i, j, chunkGenerator) >= 60); info.cancel(); - } else { + } + else { info.setReturnValue(false); info.cancel(); } } } - + @Shadow private static int getGenerationHeight(int chunkX, int chunkZ, ChunkGenerator chunkGenerator) { return 0; diff --git a/src/main/java/ru/betterend/mixin/common/EndPortalFeatureMixin.java b/src/main/java/ru/betterend/mixin/common/EndPortalFeatureMixin.java index 851439bd..6f544079 100644 --- a/src/main/java/ru/betterend/mixin/common/EndPortalFeatureMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EndPortalFeatureMixin.java @@ -1,7 +1,15 @@ package ru.betterend.mixin.common; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.feature.EndPodiumFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,61 +17,50 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.core.BlockPos; -import net.minecraft.world.Heightmap.Type; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.level.levelgen.feature.EndPortalFeature; import ru.betterend.BetterEnd; import ru.betterend.util.StructureHelper; import ru.betterend.util.WorldDataUtil; import ru.betterend.world.generator.GeneratorOptions; -@Mixin(EndPortalFeature.class) +@Mixin(EndPodiumFeature.class) public class EndPortalFeatureMixin { @Final @Shadow private boolean open; - + @Inject(method = "generate", at = @At("HEAD"), cancellable = true) - private void bePortalGenerate(WorldGenLevel world, ChunkGenerator generator, Random random, BlockPos blockPos, - NoneFeatureConfiguration config, CallbackInfoReturnable info) { + private void bePortalGenerate(WorldGenLevel world, ChunkGenerator generator, Random random, BlockPos blockPos, NoneFeatureConfiguration config, CallbackInfoReturnable info) { if (!GeneratorOptions.hasPortal()) { info.setReturnValue(false); info.cancel(); - } else if (GeneratorOptions.replacePortal()) { + } + else if (GeneratorOptions.replacePortal()) { blockPos = be_updatePos(blockPos, world); - Structure structure = StructureHelper - .readStructure(BetterEnd.makeID(open ? "portal/end_portal_active" : "portal/end_portal_inactive")); + StructureTemplate structure = StructureHelper.readStructure(BetterEnd.makeID(open ? "portal/end_portal_active" : "portal/end_portal_inactive")); BlockPos size = structure.getSize(); - blockPos = blockPos.add(-(size.getX() >> 1), -3, -(size.getZ() >> 1)); - structure.place(world, blockPos, new StructurePlacementData(), random); + blockPos = blockPos.offset(-(size.getX() >> 1), -3, -(size.getZ() >> 1)); + structure.placeInWorldChunk(world, blockPos, new StructurePlaceSettings(), random); info.setReturnValue(true); info.cancel(); } } - + @ModifyVariable(method = "generate", ordinal = 0, at = @At("HEAD")) private BlockPos be_setPosOnGround(BlockPos blockPos, WorldGenLevel world) { return be_updatePos(blockPos, world); } - + private BlockPos be_updatePos(BlockPos blockPos, WorldGenLevel world) { if (GeneratorOptions.useNewGenerator()) { BlockPos pos = GeneratorOptions.getPortalPos(); - if (pos.equals(BlockPos.ORIGIN)) { - int y = world.getChunk(blockPos).sampleHeightmap(Type.WORLD_SURFACE, blockPos.getX(), blockPos.getZ()); + if (pos.equals(BlockPos.ZERO)) { + int y = world.getChunk(blockPos).getHeight(Types.WORLD_SURFACE, blockPos.getX(), blockPos.getZ()); if (y < 1) { y = 65; } pos = new BlockPos(pos.getX(), y, pos.getZ()); GeneratorOptions.setPortalPos(pos); - WorldDataUtil.getRootTag().put("portal", NbtHelper.fromBlockPos(pos)); + WorldDataUtil.getRootTag().put("portal", NbtUtils.writeBlockPos(pos)); WorldDataUtil.saveFile(); } return pos; diff --git a/src/main/java/ru/betterend/mixin/common/EndSpikeFeatureMixin.java b/src/main/java/ru/betterend/mixin/common/EndSpikeFeatureMixin.java index 592906c2..10489789 100644 --- a/src/main/java/ru/betterend/mixin/common/EndSpikeFeatureMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EndSpikeFeatureMixin.java @@ -7,82 +7,78 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.PaneBlock; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.decoration.EndCrystalEntity; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructurePlacementData; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Mth; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.IronBarsBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.EndSpikeFeature; -import net.minecraft.world.level.levelgen.feature.EndSpikeFeatureConfig; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.feature.SpikeFeature; +import net.minecraft.world.level.levelgen.feature.configurations.SpikeConfiguration; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import ru.betterend.BetterEnd; import ru.betterend.util.BlocksHelper; import ru.betterend.util.StructureHelper; import ru.betterend.util.WorldDataUtil; import ru.betterend.world.generator.GeneratorOptions; -@Mixin(EndSpikeFeature.class) +@Mixin(SpikeFeature.class) public class EndSpikeFeatureMixin { @Inject(method = "generate", at = @At("HEAD"), cancellable = true) - private void beSpikeGenerate(WorldGenLevel structureWorldAccess, ChunkGenerator chunkGenerator, Random random, - BlockPos blockPos, EndSpikeFeatureConfig endSpikeFeatureConfig, CallbackInfoReturnable info) { + private void beSpikeGenerate(WorldGenLevel structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, SpikeConfiguration endSpikeFeatureConfig, CallbackInfoReturnable info) { if (!GeneratorOptions.hasPillars()) { info.setReturnValue(false); } } @Inject(method = "generateSpike", at = @At("HEAD"), cancellable = true) - private void be_generateSpike(ServerLevelAccessor world, Random random, EndSpikeFeatureConfig config, - EndSpikeFeature.Spike spike, CallbackInfo info) { + private void be_generateSpike(ServerLevelAccessor world, Random random, SpikeConfiguration config, SpikeFeature.EndSpike spike, CallbackInfo info) { int x = spike.getCenterX(); int z = spike.getCenterZ(); int radius = spike.getRadius(); int minY = 0; - + long lx = (long) x; long lz = (long) z; if (lx * lx + lz * lz < 10000) { String pillarID = String.format("%d_%d", x, z); CompoundTag pillar = WorldDataUtil.getCompoundTag("pillars"); boolean haveValue = pillar.contains(pillarID); - minY = haveValue ? pillar.getInt(pillarID) - : world.getChunk(x >> 4, z >> 4).sampleHeightmap(Type.WORLD_SURFACE, x & 15, z); + minY = haveValue ? pillar.getInt(pillarID) : world.getChunk(x >> 4, z >> 4).getHeight(Types.WORLD_SURFACE, x & 15, z); if (!haveValue) { pillar.putInt(pillarID, minY); WorldDataUtil.saveFile(); } - } else { - minY = world.getChunk(x >> 4, z >> 4).sampleHeightmap(Type.WORLD_SURFACE, x & 15, z); } - + else { + minY = world.getChunk(x >> 4, z >> 4).getHeight(Types.WORLD_SURFACE, x & 15, z); + } + int maxY = minY + spike.getHeight() - 64; - + if (GeneratorOptions.replacePillars() && be_radiusInRange(radius)) { radius--; - Structure base = StructureHelper.readStructure(BetterEnd.makeID("pillars/pillar_base_" + radius)); - Structure top = StructureHelper.readStructure( - BetterEnd.makeID("pillars/pillar_top_" + radius + (spike.isGuarded() ? "_cage" : ""))); + StructureTemplate base = StructureHelper.readStructure(BetterEnd.makeID("pillars/pillar_base_" + radius)); + StructureTemplate top = StructureHelper.readStructure(BetterEnd.makeID("pillars/pillar_top_" + radius + (spike.isGuarded() ? "_cage" : ""))); BlockPos side = base.getSize(); BlockPos pos1 = new BlockPos(x - (side.getX() >> 1), minY - 3, z - (side.getZ() >> 1)); minY = pos1.getY() + side.getY(); side = top.getSize(); BlockPos pos2 = new BlockPos(x - (side.getX() >> 1), maxY, z - (side.getZ() >> 1)); maxY = pos2.getY(); - - StructurePlacementData data = new StructurePlacementData(); - base.place(world, pos1, data, random); - top.place(world, pos2, data, random); - + + StructurePlaceSettings data = new StructurePlaceSettings(); + base.placeInWorldChunk(world, pos1, data, random); + top.placeInWorldChunk(world, pos2, data, random); + int r2 = radius * radius + 1; MutableBlockPos mut = new MutableBlockPos(); for (int px = -radius; px <= radius; px++) { @@ -95,10 +91,10 @@ public class EndSpikeFeatureMixin { for (int py = minY; py < maxY; py++) { mut.setY(py); if (world.getBlockState(mut).getMaterial().isReplaceable()) { - if ((px == radius || px == -radius || pz == radius || pz == -radius) - && random.nextInt(24) == 0) { + if ((px == radius || px == -radius || pz == radius || pz == -radius) && random.nextInt(24) == 0) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.CRYING_OBSIDIAN); - } else { + } + else { BlocksHelper.setWithoutUpdate(world, mut, Blocks.OBSIDIAN); } } @@ -106,7 +102,8 @@ public class EndSpikeFeatureMixin { } } } - } else { + } + else { minY -= 15; int r2 = radius * radius + 1; MutableBlockPos mut = new MutableBlockPos(); @@ -130,13 +127,13 @@ public class EndSpikeFeatureMixin { mut.setZ(z); mut.setY(maxY); BlocksHelper.setWithoutUpdate(world, mut, Blocks.BEDROCK); - - EndCrystalEntity crystal = EntityType.END_CRYSTAL.create(world.toServerWorld()); - crystal.setBeamTarget(config.getPos()); + + EndCrystal crystal = EntityType.END_CRYSTAL.create(world.getLevel()); + crystal.setBeamTarget(config.getCrystalBeamTarget()); crystal.setInvulnerable(config.isCrystalInvulnerable()); - crystal.refreshPositionAndAngles(x + 0.5D, maxY + 1, z + 0.5D, random.nextFloat() * 360.0F, 0.0F); - world.spawnEntity(crystal); - + crystal.moveTo(x + 0.5D, maxY + 1, z + 0.5D, random.nextFloat() * 360.0F, 0.0F); + world.addFreshEntity(crystal); + if (spike.isGuarded()) { for (int px = -2; px <= 2; ++px) { boolean bl = Mth.abs(px) == 2; @@ -147,13 +144,8 @@ public class EndSpikeFeatureMixin { if (bl || bl2 || bl3) { boolean bl4 = px == -2 || px == 2 || bl3; boolean bl5 = pz == -2 || pz == 2 || bl3; - BlockState blockState = (BlockState) ((BlockState) ((BlockState) ((BlockState) Blocks.IRON_BARS - .defaultBlockState().with(PaneBlock.NORTH, bl4 && pz != -2)) - .with(PaneBlock.SOUTH, bl4 && pz != 2)).with(PaneBlock.WEST, - bl5 && px != -2)).with(PaneBlock.EAST, bl5 && px != 2); - BlocksHelper.setWithoutUpdate(world, - mut.set(spike.getCenterX() + px, maxY + py, spike.getCenterZ() + pz), - blockState); + BlockState blockState = (BlockState) ((BlockState) ((BlockState) ((BlockState) Blocks.IRON_BARS.defaultBlockState().setValue(IronBarsBlock.NORTH, bl4 && pz != -2)).setValue(IronBarsBlock.SOUTH, bl4 && pz != 2)).setValue(IronBarsBlock.WEST, bl5 && px != -2)).setValue(IronBarsBlock.EAST, bl5 && px != 2); + BlocksHelper.setWithoutUpdate(world, mut.set(spike.getCenterX() + px, maxY + py, spike.getCenterZ() + pz), blockState); } } } @@ -163,7 +155,7 @@ public class EndSpikeFeatureMixin { info.cancel(); } - + private boolean be_radiusInRange(int radius) { return radius > 1 && radius < 6; } diff --git a/src/main/java/ru/betterend/mixin/common/EndermanEntityMixin.java b/src/main/java/ru/betterend/mixin/common/EndermanEntityMixin.java index 6656836e..d962b716 100644 --- a/src/main/java/ru/betterend/mixin/common/EndermanEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EndermanEntityMixin.java @@ -1,24 +1,23 @@ package ru.betterend.mixin.common; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.enchantment.EnchantmentHelper; 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 net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.mob.EndermanEntity; -import net.minecraft.world.entity.player.Player; import ru.betterend.effects.EndEnchantments; -import ru.betterend.effects.EndMobEffects; +import ru.betterend.effects.EndStatusEffects; -@Mixin(EndermanEntity.class) +@Mixin(EnderMan.class) public abstract class EndermanEntityMixin { - + @Inject(method = "isPlayerStaring", at = @At("HEAD"), cancellable = true) private void be_isPlayerStaring(Player player, CallbackInfoReturnable info) { - if (player.isCreative() || player.hasMobEffect(EndMobEffects.END_VEIL) || EnchantmentHelper - .getLevel(EndEnchantments.END_VEIL, player.getEquippedStack(EquipmentSlot.HEAD)) > 0) { + if (player.isCreative() || player.hasEffect(EndStatusEffects.END_VEIL) || + EnchantmentHelper.getItemEnchantmentLevel(EndEnchantments.END_VEIL, player.getItemBySlot(EquipmentSlot.HEAD)) > 0) { info.setReturnValue(false); } } diff --git a/src/main/java/ru/betterend/mixin/common/EntityMixin.java b/src/main/java/ru/betterend/mixin/common/EntityMixin.java index 980b9750..c48e323a 100644 --- a/src/main/java/ru/betterend/mixin/common/EntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/EntityMixin.java @@ -1,19 +1,18 @@ package ru.betterend.mixin.common; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.portal.PortalInfo; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Final; 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; - -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.core.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.TeleportTarget; -import net.minecraft.world.level.Level; import ru.betterend.interfaces.TeleportingEntity; @Mixin(Entity.class) @@ -27,19 +26,19 @@ public abstract class EntityMixin implements TeleportingEntity { public boolean removed; @Shadow public Level world; - + @Final @Shadow public abstract void detach(); - + @Shadow - public abstract Vec3d getVelocity(); - + public abstract Vec3 getVelocity(); + @Shadow public abstract EntityType getType(); - + @Shadow - protected abstract TeleportTarget getTeleportTarget(ServerLevel destination); + protected abstract PortalInfo getTeleportTarget(ServerLevel destination); private BlockPos exitPos; @@ -49,33 +48,31 @@ public abstract class EntityMixin implements TeleportingEntity { this.detach(); this.world.getProfiler().push("changeDimension"); this.world.getProfiler().push("reposition"); - TeleportTarget teleportTarget = this.getTeleportTarget(destination); + PortalInfo teleportTarget = this.getTeleportTarget(destination); if (teleportTarget != null) { - this.world.getProfiler().swap("reloading"); + this.world.getProfiler().popPush("reloading"); Entity entity = this.getType().create(destination); if (entity != null) { - entity.copyFrom(Entity.class.cast(this)); - entity.refreshPositionAndAngles(teleportTarget.position.x, teleportTarget.position.y, - teleportTarget.position.z, teleportTarget.yaw, entity.pitch); - entity.setVelocity(teleportTarget.velocity); - destination.onDimensionChanged(entity); + entity.restoreFrom(Entity.class.cast(this)); + entity.moveTo(teleportTarget.pos.x, teleportTarget.pos.y, teleportTarget.pos.z, teleportTarget.yRot, entity.xRot); + entity.setDeltaMovement(teleportTarget.speed); + destination.addFromAnotherDimension(entity); } this.removed = true; this.world.getProfiler().pop(); - ((ServerLevel) world).resetIdleTimeout(); - destination.resetIdleTimeout(); + ((ServerLevel) world).resetEmptyTime(); + destination.resetEmptyTime(); this.world.getProfiler().pop(); this.beResetExitPos(); info.setReturnValue(entity); } } } - + @Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true) - protected void be_getTeleportTarget(ServerLevel destination, CallbackInfoReturnable info) { + protected void be_getTeleportTarget(ServerLevel destination, CallbackInfoReturnable info) { if (beCanTeleport()) { - info.setReturnValue(new TeleportTarget( - new Vec3d(exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5), getVelocity(), yaw, pitch)); + info.setReturnValue(new PortalInfo(new Vec3(exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5), getVelocity(), yaw, pitch)); } } diff --git a/src/main/java/ru/betterend/mixin/common/GenerationSettingsAccessor.java b/src/main/java/ru/betterend/mixin/common/GenerationSettingsAccessor.java index 1e139594..f368415e 100644 --- a/src/main/java/ru/betterend/mixin/common/GenerationSettingsAccessor.java +++ b/src/main/java/ru/betterend/mixin/common/GenerationSettingsAccessor.java @@ -2,25 +2,23 @@ package ru.betterend.mixin.common; import java.util.List; import java.util.function.Supplier; - +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import net.minecraft.world.biome.GenerationSettings; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; - -@Mixin(GenerationSettings.class) +@Mixin(BiomeGenerationSettings.class) public interface GenerationSettingsAccessor { @Accessor("features") List>>> beGetFeatures(); - + @Accessor("features") void beSetFeatures(List>>> features); - + @Accessor("structureFeatures") List>> beGetStructures(); - + @Accessor("structureFeatures") void beSetStructures(List>> structures); } diff --git a/src/main/java/ru/betterend/mixin/common/HostileEntityMixin.java b/src/main/java/ru/betterend/mixin/common/HostileEntityMixin.java index d32bdb36..9186f9f1 100644 --- a/src/main/java/ru/betterend/mixin/common/HostileEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/HostileEntityMixin.java @@ -2,33 +2,26 @@ package ru.betterend.mixin.common; import java.util.List; import java.util.Random; - +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.phys.AABB; 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 net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.SpawnReason; -import net.minecraft.world.entity.mob.EndermanEntity; -import net.minecraft.world.entity.mob.HostileEntity; -import net.minecraft.core.BlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.level.ServerLevelAccessor; - -@Mixin(HostileEntity.class) +@Mixin(Monster.class) public class HostileEntityMixin { @Inject(method = "canSpawnInDark", at = @At(value = "RETURN"), cancellable = true) - private static void be_endermenCheck(EntityType type, - ServerLevelAccessor serverWorldAccess, SpawnReason spawnReason, BlockPos pos, Random random, - CallbackInfoReturnable info) { + private static void be_endermenCheck(EntityType type, ServerLevelAccessor serverWorldAccess, MobSpawnType spawnReason, BlockPos pos, Random random, CallbackInfoReturnable info) { boolean canSpawn = info.getReturnValue(); - if (canSpawn && spawnReason == SpawnReason.NATURAL && type == EntityType.ENDERMAN) { - Box box = new Box(pos).expand(16); - List entities = serverWorldAccess.getEntitiesByClass(EndermanEntity.class, box, - (entity) -> { - return true; - }); + if (canSpawn && spawnReason == MobSpawnType.NATURAL && type == EntityType.ENDERMAN) { + AABB box = new AABB(pos).inflate(16); + List entities = serverWorldAccess.getEntitiesOfClass(EnderMan.class, box, (entity) -> { return true; }); info.setReturnValue(entities.size() < 6); } } diff --git a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java index d6a23643..8b9cb630 100644 --- a/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/LivingEntityMixin.java @@ -1,32 +1,30 @@ package ru.betterend.mixin.common; import java.util.Collection; - import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.item.Item; 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.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; -import net.minecraft.world.item.Item; - @Mixin(LivingEntity.class) public abstract class LivingEntityMixin { private Entity lastAttacker; - - @Inject(method = "hurt", at = @At("HEAD")) + + @Inject(method = "damage", at = @At("HEAD")) public void be_damage(DamageSource source, float amount, CallbackInfoReturnable info) { this.lastAttacker = source.getEntity(); } - - @ModifyArg(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;knockback(FDD)V")) + + @ModifyArg(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;takeKnockback(FDD)V")) private float be_increaseKnockback(float value, double x, double z) { if (lastAttacker != null && lastAttacker instanceof LivingEntity) { LivingEntity attacker = (LivingEntity) lastAttacker; @@ -34,12 +32,11 @@ public abstract class LivingEntityMixin { } return value; } - + private double be_getKnockback(Item tool) { - if (tool == null) - return 0.0D; + if (tool == null) return 0.0D; Collection modifiers = tool.getDefaultAttributeModifiers(EquipmentSlot.MAINHAND) - .get(Attributes.ATTACK_KNOCKBACK); + .get(Attributes.ATTACK_KNOCKBACK); if (modifiers.size() > 0) { return modifiers.iterator().next().getAmount(); } diff --git a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java index 7b7fbef6..99d7e49c 100644 --- a/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/MinecraftServerMixin.java @@ -13,15 +13,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.resource.ServerResourceManager; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.WorldGenerationProgressListener; -import net.minecraft.server.level.ServerLevel; import net.minecraft.resources.ResourceKey; -import net.minecraft.world.SaveProperties; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerResources; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.progress.ChunkProgressListener; +import net.minecraft.server.players.PlayerList; import net.minecraft.world.level.Level; -import net.minecraft.world.level.ServerWorldProperties; +import net.minecraft.world.level.storage.ServerLevelData; +import net.minecraft.world.level.storage.WorldData; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.registry.EndBiomes; import ru.betterend.world.generator.GeneratorOptions; @@ -29,15 +29,15 @@ import ru.betterend.world.generator.GeneratorOptions; @Mixin(MinecraftServer.class) public class MinecraftServerMixin { @Shadow - private ServerResourceManager serverResourceManager; - + private ServerResources serverResourceManager; + @Final @Shadow private Map, ServerLevel> worlds; - + @Final @Shadow - protected SaveProperties saveProperties; + protected WorldData saveProperties; @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) private void beOnReload(Collection collection, CallbackInfoReturnable> info) { @@ -49,7 +49,7 @@ public class MinecraftServerMixin { beInjectRecipes(); EndBiomes.initRegistry((MinecraftServer) (Object) this); } - + @Inject(method = "getOverworld", at = @At(value = "HEAD"), cancellable = true) private final void beGetOverworld(CallbackInfoReturnable info) { if (GeneratorOptions.swapOverworldToEnd()) { @@ -61,38 +61,34 @@ public class MinecraftServerMixin { info.cancel(); } } - + @Inject(method = "createWorlds", at = @At(value = "TAIL")) - private final void be_CreateWorlds(WorldGenerationProgressListener worldGenerationProgressListener, - CallbackInfo info) { + private final void be_CreateWorlds(ChunkProgressListener worldGenerationProgressListener, CallbackInfo info) { if (GeneratorOptions.swapOverworldToEnd()) { ServerLevel world = worlds.get(Level.END); if (world == null) { world = worlds.get(Level.OVERWORLD); } - this.getPlayerManager().setMainWorld(world); - ServerWorldProperties serverWorldProperties = saveProperties.getMainWorldProperties(); - net.minecraft.world.gen.GeneratorOptions generatorOptions = saveProperties.getGeneratorOptions(); - boolean bl = generatorOptions.isDebugWorld(); - setupSpawn(world, serverWorldProperties, generatorOptions.hasBonusChest(), bl, true); + this.getPlayerManager().setLevel(world); + ServerLevelData serverWorldProperties = saveProperties.overworldData(); + net.minecraft.world.level.levelgen.WorldGenSettings generatorOptions = saveProperties.worldGenSettings(); + boolean bl = generatorOptions.isDebug(); + setupSpawn(world, serverWorldProperties, generatorOptions.generateBonusChest(), bl, true); } } - + @Inject(method = "setupSpawn", at = @At(value = "HEAD"), cancellable = true) - private static void be_SetupSpawn(ServerLevel world, ServerWorldProperties serverWorldProperties, - boolean bonusChest, boolean debugWorld, boolean bl, CallbackInfo info) { + private static void be_SetupSpawn(ServerLevel world, ServerLevelData serverWorldProperties, boolean bonusChest, boolean debugWorld, boolean bl, CallbackInfo info) { if (GeneratorOptions.swapOverworldToEnd() && world.dimension() == Level.OVERWORLD) { info.cancel(); } } - + @Shadow - private static void setupSpawn(ServerLevel world, ServerWorldProperties serverWorldProperties, boolean bonusChest, - boolean debugWorld, boolean bl) { - } - + private static void setupSpawn(ServerLevel world, ServerLevelData serverWorldProperties, boolean bonusChest, boolean debugWorld, boolean bl) {} + @Shadow - public PlayerManager getPlayerManager() { + public PlayerList getPlayerManager() { return null; } diff --git a/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java b/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java index 20934b4b..95c4ccf4 100644 --- a/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java +++ b/src/main/java/ru/betterend/mixin/common/NoiseChunkGeneratorMixin.java @@ -1,47 +1,43 @@ package ru.betterend.mixin.common; import java.util.function.Supplier; - +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.StructureSettings; import org.spongepowered.asm.mixin.Final; 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.CallbackInfo; - -import net.minecraft.world.biome.source.BiomeSource; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import net.minecraft.world.gen.chunk.NoiseChunkGenerator; -import net.minecraft.world.gen.chunk.StructuresConfig; import ru.betterend.world.generator.GeneratorOptions; import ru.betterend.world.generator.TerrainGenerator; -@Mixin(NoiseChunkGenerator.class) +@Mixin(NoiseBasedChunkGenerator.class) public abstract class NoiseChunkGeneratorMixin extends ChunkGenerator { @Final @Shadow - protected Supplier settings; - - public NoiseChunkGeneratorMixin(BiomeSource populationSource, BiomeSource biomeSource, - StructuresConfig structuresConfig, long worldSeed) { + protected Supplier settings; + + public NoiseChunkGeneratorMixin(BiomeSource populationSource, BiomeSource biomeSource, StructureSettings structuresConfig, long worldSeed) { super(populationSource, biomeSource, structuresConfig, worldSeed); } - + @Inject(method = "(Lnet/minecraft/world/biome/source/BiomeSource;Lnet/minecraft/world/biome/source/BiomeSource;JLjava/util/function/Supplier;)V", at = @At("TAIL")) - private void beOnInit(BiomeSource populationSource, BiomeSource biomeSource, long seed, - Supplier settings, CallbackInfo info) { + private void beOnInit(BiomeSource populationSource, BiomeSource biomeSource, long seed, Supplier settings, CallbackInfo info) { TerrainGenerator.initNoise(seed); } - + @Inject(method = "sampleNoiseColumn([DII)V", at = @At("HEAD"), cancellable = true, allow = 2) private void beSampleNoiseColumn(double[] buffer, int x, int z, CallbackInfo info) { - if (GeneratorOptions.useNewGenerator() && settings.get().equals(ChunkGeneratorSettings.END)) { - // System.out.println(TerrainGenerator.canGenerate(x, z)); - // if (TerrainGenerator.canGenerate(x, z)) { - TerrainGenerator.fillTerrainDensity(buffer, x, z, getBiomeSource()); - info.cancel(); - // } + if (GeneratorOptions.useNewGenerator() && settings.get().stable(NoiseGeneratorSettings.END)) { + //System.out.println(TerrainGenerator.canGenerate(x, z)); + //if (TerrainGenerator.canGenerate(x, z)) { + TerrainGenerator.fillTerrainDensity(buffer, x, z, getBiomeSource()); + info.cancel(); + //} } } } diff --git a/src/main/java/ru/betterend/mixin/common/PlayerAdvancementTrackerMixin.java b/src/main/java/ru/betterend/mixin/common/PlayerAdvancementTrackerMixin.java index 035398e3..2900fa3a 100644 --- a/src/main/java/ru/betterend/mixin/common/PlayerAdvancementTrackerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/PlayerAdvancementTrackerMixin.java @@ -2,26 +2,26 @@ package ru.betterend.mixin.common; import net.minecraft.advancements.Advancement; import net.minecraft.server.PlayerAdvancements; +import net.minecraft.server.level.ServerPlayer; 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.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.server.level.ServerPlayer; import ru.betterend.events.PlayerAdvancementsEvents; @Mixin(PlayerAdvancements.class) public abstract class PlayerAdvancementTrackerMixin { - + @Shadow private ServerPlayer owner; - - @Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = Shift.AFTER)) - public void be_onAdvancementComplete(Advancement advancement, String criterionName, - CallbackInfoReturnable info) { - PlayerAdvancementsEvents.PLAYER_ADVANCEMENT_COMPLETE.invoker().onAdvancementComplete(owner, advancement, - criterionName); + + @Inject(method = "grantCriterion", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/advancement/AdvancementRewards;apply(Lnet/minecraft/server/network/ServerPlayerEntity;)V", + shift = Shift.AFTER)) + public void be_onAdvancementComplete(Advancement advancement, String criterionName, CallbackInfoReturnable info) { + PlayerAdvancementsEvents.PLAYER_ADVENCEMENT_COMPLETE.invoker().onAdvancementComplete(owner, advancement, criterionName); } } diff --git a/src/main/java/ru/betterend/mixin/common/PlayerEntityMixin.java b/src/main/java/ru/betterend/mixin/common/PlayerEntityMixin.java index 3363b548..9ffc8d67 100644 --- a/src/main/java/ru/betterend/mixin/common/PlayerEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/PlayerEntityMixin.java @@ -1,18 +1,16 @@ package ru.betterend.mixin.common; import java.util.Optional; - +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; 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 net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.entity.player.Player; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.math.Vec3d; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.registry.EndBlocks; @@ -22,10 +20,9 @@ import ru.betterend.util.MHelper; @Mixin(Player.class) public abstract class PlayerEntityMixin { private static Direction[] HORIZONTAL; - + @Inject(method = "findRespawnPosition", at = @At(value = "HEAD"), cancellable = true) - private static void be_statueRespawn(ServerLevel world, BlockPos pos, float f, boolean bl, boolean bl2, - CallbackInfoReturnable> info) { + private static void be_statueRespawn(ServerLevel world, BlockPos pos, float f, boolean bl, boolean bl2, CallbackInfoReturnable> info) { BlockState blockState = world.getBlockState(pos); if (blockState.is(EndBlocks.RESPAWN_OBELISK)) { info.setReturnValue(beObeliskRespawnPosition(world, pos, blockState)); @@ -33,21 +30,22 @@ public abstract class PlayerEntityMixin { } } - private static Optional beObeliskRespawnPosition(ServerLevel world, BlockPos pos, BlockState state) { + private static Optional beObeliskRespawnPosition(ServerLevel world, BlockPos pos, BlockState state) { if (state.getValue(BlockProperties.TRIPLE_SHAPE) == TripleShape.TOP) { - pos = pos.down(2); - } else if (state.getValue(BlockProperties.TRIPLE_SHAPE) == TripleShape.MIDDLE) { + pos = pos.below(2); + } + else if (state.getValue(BlockProperties.TRIPLE_SHAPE) == TripleShape.MIDDLE) { pos = pos.below(); } if (HORIZONTAL == null) { HORIZONTAL = BlocksHelper.makeHorizontal(); } MHelper.shuffle(HORIZONTAL, world.getRandom()); - for (Direction dir : HORIZONTAL) { + for (Direction dir: HORIZONTAL) { BlockPos p = pos.relative(dir); BlockState state2 = world.getBlockState(p); - if (!state2.getMaterial().blocksMovement() && state2.getCollisionShape(world, pos).isEmpty()) { - return Optional.of(Vec3d.of(p).add(0.5, 0, 0.5)); + if (!state2.getMaterial().blocksMotion() && state2.getCollisionShape(world, pos).isEmpty()) { + return Optional.of(Vec3.atLowerCornerOf(p).add(0.5, 0, 0.5)); } } return Optional.empty(); diff --git a/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java b/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java index 18482905..32b06ec6 100644 --- a/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/PlayerManagerMixin.java @@ -19,46 +19,46 @@ import com.mojang.serialization.DataResult; import com.mojang.serialization.Dynamic; import io.netty.buffer.Unpooled; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; -import net.minecraft.network.ClientConnection; -import net.minecraft.network.MessageType; -import net.minecraft.network.Packet; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; -import net.minecraft.network.packet.s2c.play.DifficultyS2CPacket; -import net.minecraft.network.packet.s2c.play.EntityMobEffectS2CPacket; -import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.network.packet.s2c.play.HeldItemChangeS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; -import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket; -import net.minecraft.network.packet.s2c.play.SynchronizeTagsS2CPacket; -import net.minecraft.scoreboard.ServerScoreboard; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Formatting; -import net.minecraft.util.UserCache; -import net.minecraft.util.Util; -import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.network.Connection; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket; +import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.game.ClientboundLoginPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; +import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket; import net.minecraft.resources.ResourceKey; -import net.minecraft.world.GameRules; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerScoreboard; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.players.GameProfileCache; +import net.minecraft.server.players.PlayerList; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldProperties; -import net.minecraft.world.biome.source.BiomeAccess; +import net.minecraft.world.level.biome.BiomeManager; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelData; import ru.betterend.world.generator.GeneratorOptions; -@Mixin(PlayerManager.class) +@Mixin(PlayerList.class) public class PlayerManagerMixin { @Final @Shadow @@ -70,7 +70,7 @@ public class PlayerManagerMixin { @Final @Shadow - private DynamicRegistryManager.Impl registryManager; + private RegistryAccess.RegistryHolder registryManager; @Shadow private int viewDistance; @@ -84,22 +84,22 @@ public class PlayerManagerMixin { private Map playerMap; @Inject(method = "onPlayerConnect", at = @At(value = "HEAD"), cancellable = true) - public void be_onPlayerConnect(ClientConnection connection, ServerPlayer player, CallbackInfo info) { + public void be_onPlayerConnect(Connection connection, ServerPlayer player, CallbackInfo info) { if (GeneratorOptions.swapOverworldToEnd()) { GameProfile gameProfile = player.getGameProfile(); - UserCache userCache = this.server.getUserCache(); - GameProfile gameProfile2 = userCache.getByUuid(gameProfile.getId()); + GameProfileCache userCache = this.server.getProfileCache(); + GameProfile gameProfile2 = userCache.get(gameProfile.getId()); String string = gameProfile2 == null ? gameProfile.getName() : gameProfile2.getName(); userCache.add(gameProfile); CompoundTag compoundTag = this.loadPlayerData(player); ResourceKey var23; if (compoundTag != null) { - DataResult> var10000 = DimensionType - .method_28521(new Dynamic(NbtOps.INSTANCE, compoundTag.get("Dimension"))); + DataResult> var10000 = DimensionType.parseLegacy(new Dynamic(NbtOps.INSTANCE, compoundTag.get("Dimension"))); Logger var10001 = LOGGER; var10001.getClass(); var23 = (ResourceKey) var10000.resultOrPartial(var10001::error).orElse(Level.END); - } else { + } + else { var23 = Level.END; } @@ -108,128 +108,117 @@ public class PlayerManagerMixin { ServerLevel serverWorld3; if (serverWorld == null) { LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", registryKey); - serverWorld3 = this.server.getOverworld(); - } else { + serverWorld3 = this.server.overworld(); + } + else { serverWorld3 = serverWorld; } - player.setWorld(serverWorld3); - player.interactionManager.setWorld((ServerLevel) player.world); + player.setLevel(serverWorld3); + player.gameMode.setLevel((ServerLevel) player.level); String string2 = "local"; - if (connection.getAddress() != null) { - string2 = connection.getAddress().toString(); + if (connection.getRemoteAddress() != null) { + string2 = connection.getRemoteAddress().toString(); } - LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", player.getName().getString(), string2, - player.getEntityId(), player.getX(), player.getY(), player.getZ()); - WorldProperties worldProperties = serverWorld3.getLevelProperties(); + LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", player.getName().getString(), string2, player.getId(), player.getX(), player.getY(), player.getZ()); + LevelData worldProperties = serverWorld3.getLevelData(); this.setGameMode(player, (ServerPlayer) null, serverWorld3); - ServerPlayNetworkHandler serverPlayNetworkHandler = new ServerPlayNetworkHandler(this.server, connection, - player); + ServerGamePacketListenerImpl serverPlayNetworkHandler = new ServerGamePacketListenerImpl(this.server, connection, player); GameRules gameRules = serverWorld3.getGameRules(); - boolean bl = gameRules.getBoolean(GameRules.DO_IMMEDIATE_RESPAWN); - boolean bl2 = gameRules.getBoolean(GameRules.REDUCED_DEBUG_INFO); - serverPlayNetworkHandler.sendPacket(new GameJoinS2CPacket(player.getEntityId(), - player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), - BiomeAccess.hashSeed(serverWorld3.getSeed()), worldProperties.isHardcore(), - this.server.getWorldRegistryKeys(), this.registryManager, serverWorld3.getDimension(), - serverWorld3.dimension(), this.getMaxPlayerCount(), this.viewDistance, bl2, !bl, - serverWorld3.isDebugWorld(), serverWorld3.isFlat())); - serverPlayNetworkHandler.sendPacket(new CustomPayloadS2CPacket(CustomPayloadS2CPacket.BRAND, - (new PacketByteBuf(Unpooled.buffer())).writeString(this.getServer().getServerModName()))); - serverPlayNetworkHandler.sendPacket( - new DifficultyS2CPacket(worldProperties.getDifficulty(), worldProperties.isDifficultyLocked())); - serverPlayNetworkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities)); - serverPlayNetworkHandler.sendPacket(new HeldItemChangeS2CPacket(player.inventory.selectedSlot)); - serverPlayNetworkHandler - .sendPacket(new SynchronizeRecipesS2CPacket(this.server.getRecipeManager().values())); - serverPlayNetworkHandler.sendPacket(new SynchronizeTagsS2CPacket(this.server.getTagManager())); + boolean bl = gameRules.getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN); + boolean bl2 = gameRules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); + serverPlayNetworkHandler.send(new ClientboundLoginPacket(player.getId(), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), BiomeManager.obfuscateSeed(serverWorld3.getSeed()), + worldProperties.isHardcore(), this.server.levelKeys(), this.registryManager, serverWorld3.dimensionType(), serverWorld3.dimension(), this.getMaxPlayerCount(), this.viewDistance, bl2, !bl, + serverWorld3.isDebug(), serverWorld3.isFlat())); + serverPlayNetworkHandler.send(new ClientboundCustomPayloadPacket(ClientboundCustomPayloadPacket.BRAND, (new FriendlyByteBuf(Unpooled.buffer())).writeUtf(this.getServer().getServerModName()))); + serverPlayNetworkHandler.send(new ClientboundChangeDifficultyPacket(worldProperties.getDifficulty(), worldProperties.isDifficultyLocked())); + serverPlayNetworkHandler.send(new ClientboundPlayerAbilitiesPacket(player.abilities)); + serverPlayNetworkHandler.send(new ClientboundSetCarriedItemPacket(player.inventory.selected)); + serverPlayNetworkHandler.send(new ClientboundUpdateRecipesPacket(this.server.getRecipeManager().getRecipes())); + serverPlayNetworkHandler.send(new ClientboundUpdateTagsPacket(this.server.getTags())); this.sendCommandTree(player); - player.getStatHandler().updateStatSet(); - player.getRecipeBook().sendInitRecipesPacket(player); + player.getStats().markAllDirty(); + player.getRecipeBook().sendInitialRecipeBook(player); this.sendScoreboard(serverWorld3.getScoreboard(), player); - this.server.forcePlayerSampleUpdate(); - TranslatableText mutableText2; + this.server.invalidateStatus(); + TranslatableComponent mutableText2; if (player.getGameProfile().getName().equalsIgnoreCase(string)) { - mutableText2 = new TranslatableText("multiplayer.player.joined", - new Object[] { player.getDisplayName() }); - } else { - mutableText2 = new TranslatableText("multiplayer.player.joined.renamed", - new Object[] { player.getDisplayName(), string }); + mutableText2 = new TranslatableComponent("multiplayer.player.joined", new Object[] { player.getDisplayName() }); + } + else { + mutableText2 = new TranslatableComponent("multiplayer.player.joined.renamed", new Object[] { player.getDisplayName(), string }); } - this.broadcastChatMessage(mutableText2.formatted(Formatting.YELLOW), MessageType.SYSTEM, Util.NIL_UUID); - serverPlayNetworkHandler.requestTeleport(player.getX(), player.getY(), player.getZ(), player.yaw, - player.pitch); + this.broadcastChatMessage(mutableText2.withStyle(ChatFormatting.YELLOW), ChatType.SYSTEM, Util.NIL_UUID); + serverPlayNetworkHandler.teleport(player.getX(), player.getY(), player.getZ(), player.yRot, player.xRot); this.players.add(player); - this.playerMap.put(player.getUuid(), player); - this.sendToAll( - new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, new ServerPlayer[] { player })); + this.playerMap.put(player.getUUID(), player); + this.sendToAll(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, new ServerPlayer[] { player })); for (int i = 0; i < this.players.size(); ++i) { - player.networkHandler.sendPacket(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, - new ServerPlayer[] { (ServerPlayer) this.players.get(i) })); + player.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, new ServerPlayer[] { (ServerPlayer) this.players.get(i) })); } - serverWorld3.onPlayerConnected(player); - this.server.getBossBarManager().onPlayerConnect(player); + serverWorld3.addNewPlayer(player); + this.server.getCustomBossEvents().onPlayerConnect(player); this.sendWorldInfo(player, serverWorld3); - if (!this.server.getResourcePackUrl().isEmpty()) { - player.sendResourcePackUrl(this.server.getResourcePackUrl(), this.server.getResourcePackHash()); + if (!this.server.getResourcePack().isEmpty()) { + player.sendTexturePack(this.server.getResourcePack(), this.server.getResourcePackHash()); } - Iterator var24 = player.getMobEffects().iterator(); + Iterator var24 = player.getActiveEffects().iterator(); while (var24.hasNext()) { MobEffectInstance statusEffectInstance = (MobEffectInstance) var24.next(); - serverPlayNetworkHandler - .sendPacket(new EntityMobEffectS2CPacket(player.getEntityId(), statusEffectInstance)); + serverPlayNetworkHandler.send(new ClientboundUpdateMobEffectPacket(player.getId(), statusEffectInstance)); } if (compoundTag != null && compoundTag.contains("RootVehicle", 10)) { CompoundTag compoundTag2 = compoundTag.getCompound("RootVehicle"); - Entity entity = EntityType.loadEntityWithPassengers(compoundTag2.getCompound("Entity"), serverWorld3, - (vehicle) -> { - return !serverWorld3.tryLoadEntity(vehicle) ? null : vehicle; - }); + Entity entity = EntityType.loadEntityRecursive(compoundTag2.getCompound("Entity"), serverWorld3, (vehicle) -> { + return !serverWorld3.addWithUUID(vehicle) ? null : vehicle; + }); if (entity != null) { UUID uUID2; - if (compoundTag2.containsUuid("Attach")) { - uUID2 = compoundTag2.getUuid("Attach"); - } else { + if (compoundTag2.hasUUID("Attach")) { + uUID2 = compoundTag2.getUUID("Attach"); + } + else { uUID2 = null; } Iterator var21; Entity entity3; - if (entity.getUuid().equals(uUID2)) { + if (entity.getUUID().equals(uUID2)) { player.startRiding(entity, true); - } else { - var21 = entity.getPassengersDeep().iterator(); + } + else { + var21 = entity.getIndirectPassengers().iterator(); while (var21.hasNext()) { entity3 = (Entity) var21.next(); - if (entity3.getUuid().equals(uUID2)) { + if (entity3.getUUID().equals(uUID2)) { player.startRiding(entity3, true); break; } } } - if (!player.hasVehicle()) { + if (!player.isPassenger()) { LOGGER.warn("Couldn't reattach entity to player"); - serverWorld3.removeEntity(entity); - var21 = entity.getPassengersDeep().iterator(); + serverWorld3.despawn(entity); + var21 = entity.getIndirectPassengers().iterator(); while (var21.hasNext()) { entity3 = (Entity) var21.next(); - serverWorld3.removeEntity(entity3); + serverWorld3.despawn(entity3); } } } } - player.onSpawn(); + player.initMenu(); info.cancel(); } } @@ -240,12 +229,10 @@ public class PlayerManagerMixin { } @Shadow - private void setGameMode(ServerPlayer player, @Nullable ServerPlayer oldPlayer, ServerLevel world) { - } + private void setGameMode(ServerPlayer player, @Nullable ServerPlayer oldPlayer, ServerLevel world) {} @Shadow - public void sendCommandTree(ServerPlayer player) { - } + public void sendCommandTree(ServerPlayer player) {} @Shadow public int getMaxPlayerCount() { @@ -258,18 +245,14 @@ public class PlayerManagerMixin { } @Shadow - protected void sendScoreboard(ServerScoreboard scoreboard, ServerPlayer player) { - } + protected void sendScoreboard(ServerScoreboard scoreboard, ServerPlayer player) {} @Shadow - public void broadcastChatMessage(Text message, MessageType type, UUID senderUuid) { - } + public void broadcastChatMessage(Component message, ChatType type, UUID senderUuid) {} @Shadow - public void sendToAll(Packet packet) { - } + public void sendToAll(Packet packet) {} @Shadow - public void sendWorldInfo(ServerPlayer player, ServerLevel world) { - } + public void sendWorldInfo(ServerPlayer player, ServerLevel world) {} } diff --git a/src/main/java/ru/betterend/mixin/common/RecipeManagerAccessor.java b/src/main/java/ru/betterend/mixin/common/RecipeManagerAccessor.java index 759f56f3..5f680919 100644 --- a/src/main/java/ru/betterend/mixin/common/RecipeManagerAccessor.java +++ b/src/main/java/ru/betterend/mixin/common/RecipeManagerAccessor.java @@ -1,14 +1,12 @@ package ru.betterend.mixin.common; import java.util.Map; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(RecipeManager.class) public interface RecipeManagerAccessor { diff --git a/src/main/java/ru/betterend/mixin/common/RecipeManagerMixin.java b/src/main/java/ru/betterend/mixin/common/RecipeManagerMixin.java index 10dce970..5baffe2a 100644 --- a/src/main/java/ru/betterend/mixin/common/RecipeManagerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/RecipeManagerMixin.java @@ -5,7 +5,15 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; - +import net.minecraft.Util; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @@ -14,16 +22,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.google.gson.JsonElement; - -import net.minecraft.inventory.Inventory; -import net.minecraft.world.item.crafting.Recipe; -import net.minecraft.world.item.crafting.RecipeManager; -import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Util; -import net.minecraft.util.profiler.Profiler; -import net.minecraft.world.level.Level; import ru.betterend.recipe.EndRecipeManager; @Mixin(RecipeManager.class) @@ -32,26 +30,23 @@ public class RecipeManagerMixin { private Map, Map>> recipes; @Inject(method = "apply", at = @At(value = "RETURN")) - private void beSetRecipes(Map map, ResourceManager resourceManager, - Profiler profiler, CallbackInfo info) { + private void beSetRecipes(Map map, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo info) { recipes = EndRecipeManager.getMap(recipes); } @Shadow - private > Map> getAllOfType( - RecipeType type) { + private > Map> getAllOfType(RecipeType type) { return null; } /** * @author paulevs - * @reason Remove conflicts with vanilla tags Change recipe order to show mod - * recipes first, helps when block have vanilla tag (example - mod stone - * with vanilla tags and furnace from that stone) + * @reason Remove conflicts with vanilla tags + * Change recipe order to show mod recipes first, helps when block have vanilla tag + * (example - mod stone with vanilla tags and furnace from that stone) */ @Overwrite - public > Optional getFirstMatch(RecipeType type, C inventory, - Level world) { + public > Optional getFirstMatch(RecipeType type, C inventory, Level world) { Collection> values = getAllOfType(type).values(); List> list = new ArrayList>(values); list.sort((v1, v2) -> { @@ -61,7 +56,7 @@ public class RecipeManagerMixin { }); return list.stream().flatMap((recipe) -> { - return Util.stream(type.get(recipe, world, inventory)); + return Util.toStream(type.tryMatch(recipe, world, inventory)); }).findFirst(); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java b/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java index f592d94d..bda5a594 100644 --- a/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ServerPlayerEntityMixin.java @@ -9,27 +9,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfile; - -import net.minecraft.world.entity.Entity; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Player; -import net.minecraft.network.packet.s2c.play.DifficultyS2CPacket; -import net.minecraft.network.packet.s2c.play.EntityMobEffectS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; -import net.minecraft.network.packet.s2c.play.WorldEventS2CPacket; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerPlayerInteractionManager; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.TeleportTarget; +import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket; +import net.minecraft.network.protocol.game.ClientboundLevelEventPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; +import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.players.PlayerList; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; -import net.minecraft.world.WorldProperties; -import net.minecraft.world.biome.source.BiomeAccess; +import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.portal.PortalInfo; +import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.phys.Vec3; import ru.betterend.interfaces.TeleportingEntity; import ru.betterend.world.generator.GeneratorOptions; @@ -37,10 +36,10 @@ import ru.betterend.world.generator.GeneratorOptions; public abstract class ServerPlayerEntityMixin extends Player implements TeleportingEntity { @Shadow - public ServerPlayNetworkHandler networkHandler; + public ServerGamePacketListenerImpl networkHandler; @Final @Shadow - public ServerPlayerInteractionManager interactionManager; + public ServerPlayerGameMode interactionManager; @Final @Shadow public MinecraftServer server; @@ -67,52 +66,47 @@ public abstract class ServerPlayerEntityMixin extends Player implements Teleport } @Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true) - protected void be_getTeleportTarget(ServerLevel destination, CallbackInfoReturnable info) { + protected void be_getTeleportTarget(ServerLevel destination, CallbackInfoReturnable info) { if (beCanTeleport()) { - info.setReturnValue(new TeleportTarget( - new Vec3d(exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5), getVelocity(), yaw, pitch)); + info.setReturnValue(new PortalInfo(new Vec3(exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5), getDeltaMovement(), yRot, xRot)); } } @Inject(method = "moveToWorld", at = @At("HEAD"), cancellable = true) public void be_moveToWorld(ServerLevel destination, CallbackInfoReturnable info) { - if (beCanTeleport() && world instanceof ServerLevel) { + if (beCanTeleport() && level instanceof ServerLevel) { this.inTeleportationState = true; ServerLevel serverWorld = this.getServerWorld(); - WorldProperties worldProperties = destination.getLevelProperties(); + LevelData worldProperties = destination.getLevelData(); ServerPlayer player = ServerPlayer.class.cast(this); - this.networkHandler.sendPacket(new PlayerRespawnS2CPacket(destination.getDimension(), - destination.dimension(), BiomeAccess.hashSeed(destination.getSeed()), - interactionManager.getGameMode(), interactionManager.getPreviousGameMode(), - destination.isDebugWorld(), destination.isFlat(), true)); - this.networkHandler.sendPacket( - new DifficultyS2CPacket(worldProperties.getDifficulty(), worldProperties.isDifficultyLocked())); - PlayerManager playerManager = this.server.getPlayerManager(); - playerManager.sendCommandTree(player); - serverWorld.removePlayer(player); + this.networkHandler.send(new ClientboundRespawnPacket(destination.dimensionType(), destination.dimension(), BiomeManager.obfuscateSeed(destination.getSeed()), + interactionManager.getGameModeForPlayer(),interactionManager.getPreviousGameModeForPlayer(), destination.isDebug(), destination.isFlat(), true)); + this.networkHandler.send(new ClientboundChangeDifficultyPacket(worldProperties.getDifficulty(), worldProperties.isDifficultyLocked())); + PlayerList playerManager = this.server.getPlayerList(); + playerManager.sendPlayerPermissionLevel(player); + serverWorld.removePlayerImmediately(player); this.removed = false; - TeleportTarget teleportTarget = this.getTeleportTarget(destination); + PortalInfo teleportTarget = this.findDimensionEntryPoint(destination); if (teleportTarget != null) { serverWorld.getProfiler().push("moving"); serverWorld.getProfiler().pop(); serverWorld.getProfiler().push("placing"); - this.setWorld(destination); - destination.onPlayerChangeDimension(player); - this.setRotation(teleportTarget.yaw, teleportTarget.pitch); - this.refreshPositionAfterTeleport(teleportTarget.position.x, teleportTarget.position.y, - teleportTarget.position.z); + this.setLevel(destination); + destination.addDuringPortalTeleport(player); + this.setRot(teleportTarget.yRot, teleportTarget.xRot); + this.moveTo(teleportTarget.pos.x, teleportTarget.pos.y, teleportTarget.pos.z); serverWorld.getProfiler().pop(); this.worldChanged(serverWorld); - this.interactionManager.setWorld(destination); - this.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(this.abilities)); - playerManager.sendWorldInfo(player, destination); - playerManager.sendPlayerStatus(player); + this.interactionManager.setLevel(destination); + this.networkHandler.send(new ClientboundPlayerAbilitiesPacket(this.abilities)); + playerManager.sendLevelInfo(player, destination); + playerManager.sendAllPlayerInfo(player); - for (MobEffectInstance statusEffectInstance : this.getMobEffects()) { - this.networkHandler.sendPacket(new EntityMobEffectS2CPacket(getEntityId(), statusEffectInstance)); + for (MobEffectInstance statusEffectInstance : this.getActiveEffects()) { + this.networkHandler.send(new ClientboundUpdateMobEffectPacket(getId(), statusEffectInstance)); } - this.networkHandler.sendPacket(new WorldEventS2CPacket(1032, BlockPos.ORIGIN, 0, false)); + this.networkHandler.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false)); this.syncedExperience = -1; this.syncedHealth = -1.0F; this.syncedFoodLevel = -1; @@ -130,7 +124,7 @@ public abstract class ServerPlayerEntityMixin extends Player implements Teleport @Shadow @Override - protected abstract TeleportTarget getTeleportTarget(ServerLevel destination); + protected abstract PortalInfo findDimensionEntryPoint(ServerLevel destination); @Override public void beSetExitPos(BlockPos pos) { diff --git a/src/main/java/ru/betterend/mixin/common/ServerWorldMixin.java b/src/main/java/ru/betterend/mixin/common/ServerWorldMixin.java index 944990c0..39e90b32 100644 --- a/src/main/java/ru/betterend/mixin/common/ServerWorldMixin.java +++ b/src/main/java/ru/betterend/mixin/common/ServerWorldMixin.java @@ -13,19 +13,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.WorldGenerationProgressListener; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.progress.ChunkProgressListener; +import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.gen.Spawner; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.ServerWorldProperties; -import net.minecraft.world.level.storage.LevelStorage; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelStorageSource; +import net.minecraft.world.level.storage.ServerLevelData; import ru.betterend.BetterEnd; import ru.betterend.util.DataFixerUtil; import ru.betterend.util.WorldDataUtil; @@ -36,34 +36,31 @@ public class ServerWorldMixin { private static final int DEV_VERSION = be_getVersionInt("63.63.63"); private static final int FIX_VERSION = DEV_VERSION; private static String lastWorld = null; - + @Inject(method = "*", at = @At("TAIL")) - private void be_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, - ServerWorldProperties properties, ResourceKey registryKey, DimensionType dimensionType, - WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, - boolean debugWorld, long l, List list, boolean bl, CallbackInfo info) { - if (lastWorld != null && lastWorld.equals(session.getDirectoryName())) { + private void be_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List list, boolean bl, CallbackInfo info) { + if (lastWorld != null && lastWorld.equals(session.getLevelId())) { return; } - - lastWorld = session.getDirectoryName(); - + + lastWorld = session.getLevelId(); + @SuppressWarnings("resource") ServerLevel world = (ServerLevel) (Object) this; - File dir = session.getWorldDirectory(world.dimension()); + File dir = session.getDimensionPath(world.dimension()); if (!new File(dir, "level.dat").exists()) { dir = dir.getParentFile(); } File data = new File(dir, "data/betterend_data.nbt"); - + ModMetadata meta = FabricLoader.getInstance().getModContainer(BetterEnd.MOD_ID).get().getMetadata(); int version = BetterEnd.isDevEnvironment() ? DEV_VERSION : be_getVersionInt(meta.getVersion().toString()); - + WorldDataUtil.load(data); CompoundTag root = WorldDataUtil.getRootTag(); int dataVersion = be_getVersionInt(root.getString("version")); - GeneratorOptions.setPortalPos(NbtHelper.toBlockPos(root.getCompound("portal"))); - + GeneratorOptions.setPortalPos(NbtUtils.readBlockPos(root.getCompound("portal"))); + if (dataVersion < version) { if (version < FIX_VERSION) { DataFixerUtil.fixData(data.getParentFile()); @@ -82,7 +79,7 @@ public class ServerWorldMixin { } } } - + private static int be_getVersionInt(String version) { if (version.isEmpty()) { return 0; @@ -90,11 +87,12 @@ public class ServerWorldMixin { try { String[] values = version.split("\\."); return Integer.parseInt(values[0]) << 12 | Integer.parseInt(values[1]) << 6 | Integer.parseInt(values[1]); - } catch (Exception e) { + } + catch (Exception e) { return 0; } } - + private static String be_getVersionString(int version) { int a = (version >> 12) & 63; int b = (version >> 6) & 63; diff --git a/src/main/java/ru/betterend/mixin/common/SlimeEntityMixin.java b/src/main/java/ru/betterend/mixin/common/SlimeEntityMixin.java index d4874e59..151180d7 100644 --- a/src/main/java/ru/betterend/mixin/common/SlimeEntityMixin.java +++ b/src/main/java/ru/betterend/mixin/common/SlimeEntityMixin.java @@ -1,17 +1,15 @@ package ru.betterend.mixin.common; +import net.minecraft.world.entity.monster.Slime; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; - -import net.minecraft.world.entity.mob.SlimeEntity; import ru.betterend.interfaces.ISlime; -@Mixin(SlimeEntity.class) +@Mixin(Slime.class) public class SlimeEntityMixin implements ISlime { @Shadow - protected void setSize(int size, boolean heal) { - } - + protected void setSize(int size, boolean heal) {} + @Override public void beSetSlimeSize(int size, boolean heal) { setSize(size, heal); diff --git a/src/main/java/ru/betterend/mixin/common/TagGroupLoaderMixin.java b/src/main/java/ru/betterend/mixin/common/TagGroupLoaderMixin.java index 8f7c02d2..825d68be 100644 --- a/src/main/java/ru/betterend/mixin/common/TagGroupLoaderMixin.java +++ b/src/main/java/ru/betterend/mixin/common/TagGroupLoaderMixin.java @@ -3,28 +3,25 @@ package ru.betterend.mixin.common; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; - +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagLoader; 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; - -import net.minecraft.resource.ResourceManager; -import net.minecraft.tags.Tag; -import net.minecraft.tags.TagGroupLoader; -import net.minecraft.resources.ResourceLocation; import ru.betterend.util.TagHelper; -@Mixin(TagGroupLoader.class) +@Mixin(TagLoader.class) public class TagGroupLoaderMixin { - + @Shadow private String entryType; - + @Inject(method = "prepareReload", at = @At("RETURN"), cancellable = true) - public void be_prepareReload(ResourceManager manager, Executor prepareExecutor, - CallbackInfoReturnable>> info) { + public void be_prepareReload(ResourceManager manager, Executor prepareExecutor, CallbackInfoReturnable>> info) { CompletableFuture> future = info.getReturnValue(); info.setReturnValue(CompletableFuture.supplyAsync(() -> { Map map = future.join(); diff --git a/src/main/java/ru/betterend/mixin/common/WeightedBiomePickerMixin.java b/src/main/java/ru/betterend/mixin/common/WeightedBiomePickerMixin.java index f8f3830e..7e07ce2c 100644 --- a/src/main/java/ru/betterend/mixin/common/WeightedBiomePickerMixin.java +++ b/src/main/java/ru/betterend/mixin/common/WeightedBiomePickerMixin.java @@ -19,21 +19,20 @@ import ru.betterend.interfaces.IBiomeList; @Mixin(value = WeightedBiomePicker.class, remap = false) public class WeightedBiomePickerMixin implements IBiomeList { private List> biomes = Lists.newArrayList(); - + @Inject(method = "addBiome", at = @At("TAIL")) private void be_addBiome(final ResourceKey biome, final double weight, CallbackInfo info) { if (be_isCorrectPicker((WeightedBiomePicker) (Object) this)) { biomes.add(biome); } } - + @Override public List> getBiomes() { return biomes; } - + private boolean be_isCorrectPicker(WeightedBiomePicker picker) { - return picker == InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS) - || picker == InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS); + return picker == InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS) || picker == InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS); } } diff --git a/src/main/java/ru/betterend/noise/VoronoiNoise.java b/src/main/java/ru/betterend/noise/VoronoiNoise.java index c7735336..20356055 100644 --- a/src/main/java/ru/betterend/noise/VoronoiNoise.java +++ b/src/main/java/ru/betterend/noise/VoronoiNoise.java @@ -1,14 +1,13 @@ package ru.betterend.noise; import java.util.Random; - import net.minecraft.core.BlockPos; import ru.betterend.util.MHelper; public class VoronoiNoise { private static final Random RANDOM = new Random(); final int seed; - + public VoronoiNoise() { this(0); } @@ -16,7 +15,7 @@ public class VoronoiNoise { public VoronoiNoise(int seed) { this.seed = seed; } - + private int getSeed(int x, int y, int z) { int h = seed + x * 374761393 + y * 668265263 + z; h = (h ^ (h >> 13)) * 1274126177; @@ -27,13 +26,13 @@ public class VoronoiNoise { int ix = MHelper.floor(x); int iy = MHelper.floor(y); int iz = MHelper.floor(z); - + float px = (float) (x - ix); float py = (float) (y - iy); float pz = (float) (z - iz); - + float d = 10; - + for (int pox = -1; pox < 2; pox++) { for (int poy = -1; poy < 2; poy++) { for (int poz = -1; poz < 2; poz++) { @@ -48,19 +47,19 @@ public class VoronoiNoise { } } } - + return Math.sqrt(d); } - + public BlockPos[] getPos(double x, double y, double z, double scale) { int ix = MHelper.floor(x); int iy = MHelper.floor(y); int iz = MHelper.floor(z); - + float px = (float) (x - ix); float py = (float) (y - iy); float pz = (float) (z - iz); - + float d = 10; float selX = 0; float selY = 0; @@ -68,7 +67,7 @@ public class VoronoiNoise { float selXPre = 0; float selYPre = 0; float selZPre = 0; - + for (int pox = -1; pox < 2; pox++) { for (int poy = -1; poy < 2; poy++) { for (int poz = -1; poz < 2; poz++) { @@ -89,11 +88,9 @@ public class VoronoiNoise { } } } - - BlockPos p1 = new BlockPos((ix + (double) selX) * scale, (iy + (double) selY) * scale, - (iz + (double) selZ) * scale); - BlockPos p2 = new BlockPos((ix + (double) selXPre) * scale, (iy + (double) selYPre) * scale, - (iz + (double) selZPre) * scale); - return new BlockPos[] { p1, p2 }; + + BlockPos p1 = new BlockPos((ix + (double) selX) * scale, (iy + (double) selY) * scale, (iz + (double) selZ) * scale); + BlockPos p2 = new BlockPos((ix + (double) selXPre) * scale, (iy + (double) selYPre) * scale, (iz + (double) selZPre) * scale); + return new BlockPos[] {p1, p2}; } } diff --git a/src/main/java/ru/betterend/particle/FireflyParticle.java b/src/main/java/ru/betterend/particle/FireflyParticle.java index 808d69fc..fc1f68d8 100644 --- a/src/main/java/ru/betterend/particle/FireflyParticle.java +++ b/src/main/java/ru/betterend/particle/FireflyParticle.java @@ -2,11 +2,11 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.SimpleAnimatedParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @@ -19,26 +19,25 @@ public class FireflyParticle extends SimpleAnimatedParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected FireflyParticle(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, double g, - double b) { + + protected FireflyParticle(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, double g, double b) { super(world, x, y, z, sprites, 0); - setSprite(sprites.getSprite(random)); - this.maxAge = MHelper.randRange(150, 300, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); - this.setTargetColor(15916745); - this.setSpriteForAge(spriteProvider); - this.setColorAlpha(0); - + setSprite(sprites.get(random)); + this.lifetime = MHelper.randRange(150, 300, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); + this.setFadeColor(15916745); + this.setSpriteFromAge(sprites); + this.setAlpha(0); + preVX = random.nextGaussian() * 0.02; preVY = random.nextGaussian() * 0.02; preVZ = random.nextGaussian() * 0.02; - + nextVX = random.nextGaussian() * 0.02; nextVY = random.nextGaussian() * 0.02; nextVZ = random.nextGaussian() * 0.02; } - + @Override public void tick() { int ticks = this.age & 31; @@ -51,22 +50,23 @@ public class FireflyParticle extends SimpleAnimatedParticle { nextVZ = random.nextGaussian() * 0.02; } double delta = (double) ticks / 31.0; - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + if (this.age <= 60) { - this.setColorAlpha(this.age / 60F); - } else if (this.age > maxAge - 60) { - this.setColorAlpha((maxAge - this.age) / 60F); + this.setAlpha(this.age / 60F); } - + else if (this.age > lifetime - 60) { + this.setAlpha((lifetime - this.age) / 60F); + } + super.tick(); } @Environment(EnvType.CLIENT) - public static class FireflyParticleFactory implements ParticleFactory { + public static class FireflyParticleFactory implements ParticleProvider { private final SpriteSet sprites; public FireflyParticleFactory(SpriteSet sprites) { @@ -74,8 +74,7 @@ public class FireflyParticle extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new FireflyParticle(world, x, y, z, sprites, 1, 1, 1); } } diff --git a/src/main/java/ru/betterend/particle/GlowingSphereParticleEffect.java b/src/main/java/ru/betterend/particle/GlowingSphereParticleEffect.java index 2c971282..67d8fca1 100644 --- a/src/main/java/ru/betterend/particle/GlowingSphereParticleEffect.java +++ b/src/main/java/ru/betterend/particle/GlowingSphereParticleEffect.java @@ -1,11 +1,10 @@ package ru.betterend.particle; import java.util.Locale; - -import net.minecraft.network.PacketByteBuf; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.core.Registry; +import net.minecraft.network.FriendlyByteBuf; import ru.betterend.registry.EndParticles; public class GlowingSphereParticleEffect implements ParticleOptions { @@ -25,16 +24,15 @@ public class GlowingSphereParticleEffect implements ParticleOptions { } @Override - public void write(PacketByteBuf buf) { + public void writeToNetwork(FriendlyByteBuf buf) { buf.writeFloat(this.red); buf.writeFloat(this.green); buf.writeFloat(this.blue); } @Override - public String asString() { - return String.format(Locale.ROOT, "%s %.2f %.2f %.2f", Registry.PARTICLE_TYPE.getId(this.getType()), this.red, - this.green, this.blue); + public String writeToString() { + return String.format(Locale.ROOT, "%s %.2f %.2f %.2f", Registry.PARTICLE_TYPE.getKey(this.getType()), this.red, this.green, this.blue); } public float getRed() { diff --git a/src/main/java/ru/betterend/particle/InfusionParticle.java b/src/main/java/ru/betterend/particle/InfusionParticle.java index e856a4a0..8bdac965 100644 --- a/src/main/java/ru/betterend/particle/InfusionParticle.java +++ b/src/main/java/ru/betterend/particle/InfusionParticle.java @@ -2,62 +2,60 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; -public class InfusionParticle extends SpriteBillboardParticle { - +public class InfusionParticle extends TextureSheetParticle { + private final SpriteSet spriteProvider; - public InfusionParticle(ClientLevel clientWorld, double x, double y, double z, double velocityX, double velocityY, - double velocityZ, float[] palette, SpriteSet spriteProvider) { + public InfusionParticle(ClientLevel clientWorld, double x, double y, double z, double velocityX, double velocityY, double velocityZ, float[] palette, SpriteSet spriteProvider) { super(clientWorld, x, y, z, 0.0, 0.0, 0.0); - this.setSpriteForAge(spriteProvider); + this.setSpriteFromAge(spriteProvider); this.spriteProvider = spriteProvider; this.setColor(palette[0], palette[1], palette[2]); - this.setColorAlpha(palette[3]); - this.velocityX = velocityX * 0.1D; - this.velocityY = velocityY * 0.1D; - this.velocityZ = velocityZ * 0.1D; - this.maxAge = (int) (3.0F / (this.random.nextFloat() * 0.9F + 0.1F)); - this.scale *= 0.9F; + this.setAlpha(palette[3]); + this.xd = velocityX * 0.1D; + this.yd = velocityY * 0.1D; + this.zd = velocityZ * 0.1D; + this.lifetime = (int) (3.0F / (this.random.nextFloat() * 0.9F + 0.1F)); + this.quadSize *= 0.9F; } @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } - + @Override public void tick() { - this.prevPosX = this.x; - this.prevPosY = this.y; - this.prevPosZ = this.z; - if (this.age++ >= this.maxAge) { - this.markDead(); + this.xo = this.x; + this.yo = this.y; + this.zo = this.z; + if (this.age++ >= this.lifetime) { + this.remove(); } else { - this.setSpriteForAge(spriteProvider); - double velocityX = 2.0D * this.velocityX * this.random.nextDouble(); - double velocityY = 3.0D * this.velocityY * this.random.nextDouble(); - double velocityZ = 2.0D * this.velocityZ * this.random.nextDouble(); + this.setSpriteFromAge(spriteProvider); + double velocityX = 2.0D * this.xd * this.random.nextDouble(); + double velocityY = 3.0D * this.yd * this.random.nextDouble(); + double velocityZ = 2.0D * this.zd * this.random.nextDouble(); this.move(velocityX, velocityY, velocityZ); } } @Environment(EnvType.CLIENT) - public static class InfusionFactory implements ParticleFactory { + public static class InfusionFactory implements ParticleProvider { private final SpriteSet spriteProvider; - + public InfusionFactory(SpriteSet spriteProvider) { this.spriteProvider = spriteProvider; } - - public Particle createParticle(InfusionParticleType particleType, ClientLevel clientWorld, double d, double e, - double f, double g, double h, double i) { + + public Particle createParticle(InfusionParticleType particleType, ClientLevel clientWorld, double d, double e, double f, double g, double h, double i) { return new InfusionParticle(clientWorld, d, e, f, g, h, i, particleType.getPalette(), this.spriteProvider); } } diff --git a/src/main/java/ru/betterend/particle/InfusionParticleType.java b/src/main/java/ru/betterend/particle/InfusionParticleType.java index 6d237c06..9ab3f67b 100644 --- a/src/main/java/ru/betterend/particle/InfusionParticleType.java +++ b/src/main/java/ru/betterend/particle/InfusionParticleType.java @@ -6,13 +6,13 @@ import com.mojang.serialization.Codec; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.command.argument.ItemStackArgument; -import net.minecraft.command.argument.ItemStringReader; -import net.minecraft.world.item.ItemStack; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.commands.arguments.item.ItemInput; +import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.core.Registry; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.ItemStack; import ru.betterend.registry.EndParticles; import ru.betterend.util.ColorUtil; @@ -22,34 +22,32 @@ public class InfusionParticleType extends ParticleType imp }, infusionParticleType -> { return infusionParticleType.itemStack; }); - public static final ParticleOptions.Factory PARAMETERS_FACTORY = new ParticleOptions.Factory() { - public InfusionParticleType read(ParticleType particleType, StringReader stringReader) - throws CommandSyntaxException { + public static final ParticleOptions.Deserializer PARAMETERS_FACTORY = new ParticleOptions.Deserializer() { + public InfusionParticleType fromCommand(ParticleType particleType, StringReader stringReader) throws CommandSyntaxException { stringReader.expect(' '); - ItemStringReader itemStringReader = new ItemStringReader(stringReader, false).consume(); - ItemStack itemStack = new ItemStackArgument(itemStringReader.getItem(), itemStringReader.getTag()) - .createStack(1, false); + ItemParser itemStringReader = new ItemParser(stringReader, false).parse(); + ItemStack itemStack = new ItemInput(itemStringReader.getItem(), itemStringReader.getNbt()).createItemStack(1, false); return new InfusionParticleType(particleType, itemStack); } - public InfusionParticleType read(ParticleType particleType, PacketByteBuf packetByteBuf) { - return new InfusionParticleType(particleType, packetByteBuf.readItemStack()); + public InfusionParticleType fromNetwork(ParticleType particleType, FriendlyByteBuf packetByteBuf) { + return new InfusionParticleType(particleType, packetByteBuf.readItem()); } }; - + private ParticleType type; private ItemStack itemStack; - + public InfusionParticleType(ParticleType particleType, ItemStack stack) { super(true, PARAMETERS_FACTORY); this.type = particleType; this.itemStack = stack; } - + public InfusionParticleType(ItemStack stack) { this(EndParticles.INFUSION, stack); } - + @Environment(EnvType.CLIENT) public float[] getPalette() { int color = ColorUtil.extractColor(itemStack.getItem()); @@ -62,17 +60,17 @@ public class InfusionParticleType extends ParticleType imp } @Override - public void write(PacketByteBuf buffer) { - buffer.writeItemStack(itemStack); + public void writeToNetwork(FriendlyByteBuf buffer) { + buffer.writeItem(itemStack); } @Override - public String asString() { - return Registry.PARTICLE_TYPE.getId(this).toString(); + public String writeToString() { + return Registry.PARTICLE_TYPE.getKey(this).toString(); } @Override - public Codec getCodec() { + public Codec codec() { return CODEC; } } diff --git a/src/main/java/ru/betterend/particle/ParticleBlackSpore.java b/src/main/java/ru/betterend/particle/ParticleBlackSpore.java index 2185c4e5..b1216424 100644 --- a/src/main/java/ru/betterend/particle/ParticleBlackSpore.java +++ b/src/main/java/ru/betterend/particle/ParticleBlackSpore.java @@ -2,12 +2,12 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.SimpleAnimatedParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @@ -20,26 +20,25 @@ public class ParticleBlackSpore extends SimpleAnimatedParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected ParticleBlackSpore(ClientLevel world, double x, double y, double z, double r, double g, double b, - SpriteSet sprites) { + + protected ParticleBlackSpore(ClientLevel world, double x, double y, double z, double r, double g, double b, SpriteSet sprites) { super(world, x, y, z, sprites, 0); - setSprite(sprites.getSprite(random)); - - this.maxAge = MHelper.randRange(30, 60, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); + setSprite(sprites.get(random)); + + this.lifetime = MHelper.randRange(30, 60, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); this.setColor(1, 1, 1); - this.setColorAlpha(0); - + this.setAlpha(0); + preVX = random.nextGaussian() * 0.015; preVY = 0; preVZ = random.nextGaussian() * 0.015; - + nextVX = random.nextGaussian() * 0.015; nextVY = random.nextFloat() * 0.02 + 0.01; nextVZ = random.nextGaussian() * 0.015; } - + @Override public void tick() { int ticks = this.age & 15; @@ -52,31 +51,32 @@ public class ParticleBlackSpore extends SimpleAnimatedParticle { nextVZ = random.nextGaussian() * 0.015; } double delta = (double) ticks / 15.0; - + if (this.age <= 15) { - this.setColorAlpha(this.age / 15F); - } else if (this.age >= this.maxAge - 15) { - this.setColorAlpha((this.maxAge - this.age) / 15F); + this.setAlpha(this.age / 15F); } - - if (this.age >= this.maxAge) { - this.markDead(); + else if (this.age >= this.lifetime - 15) { + this.setAlpha((this.lifetime - this.age) / 15F); } - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + if (this.age >= this.lifetime) { + this.remove(); + } + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class FactoryBlackSpore implements ParticleFactory { + public static class FactoryBlackSpore implements ParticleProvider { private final SpriteSet sprites; @@ -85,8 +85,7 @@ public class ParticleBlackSpore extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleBlackSpore(world, x, y, z, 1, 1, 1, sprites); } } diff --git a/src/main/java/ru/betterend/particle/ParticleGeyser.java b/src/main/java/ru/betterend/particle/ParticleGeyser.java index dbe6f814..f51913dd 100644 --- a/src/main/java/ru/betterend/particle/ParticleGeyser.java +++ b/src/main/java/ru/betterend/particle/ParticleGeyser.java @@ -2,67 +2,68 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.particles.SimpleParticleType; import ru.betterend.util.MHelper; @Environment(EnvType.CLIENT) -public class ParticleGeyser extends SpriteBillboardParticle { +public class ParticleGeyser extends TextureSheetParticle { private MutableBlockPos mut = new MutableBlockPos(); private boolean changeDir = false; private boolean check = true; - - protected ParticleGeyser(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, - SpriteSet sprites) { + + protected ParticleGeyser(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet sprites) { super(world, x, y, z, vx, vy, vz); - setSprite(sprites); - this.maxAge = MHelper.randRange(400, 800, random); - this.scale = MHelper.randRange(0.5F, 1.0F, random); - this.velocityX = vx; - this.velocityZ = vz; - this.prevPosY = y - 0.125; + pickSprite(sprites); + this.lifetime = MHelper.randRange(400, 800, random); + this.quadSize = MHelper.randRange(0.5F, 1.0F, random); + this.xd = vx; + this.zd = vz; + this.yo = y - 0.125; } - + @Override public void tick() { - - if (this.prevPosY == this.y || this.age > this.maxAge) { - this.markDead(); - } else { - if (this.age >= this.maxAge - 200) { - this.setColorAlpha((this.maxAge - this.age) / 200F); + + if (this.yo == this.y || this.age > this.lifetime) { + this.remove(); + } + else { + if (this.age >= this.lifetime - 200) { + this.setAlpha((this.lifetime - this.age) / 200F); } - - this.scale += 0.005F; - this.velocityY = 0.125; - + + this.quadSize += 0.005F; + this.yd = 0.125; + if (changeDir) { changeDir = false; check = false; - this.velocityX += MHelper.randRange(-0.2, 0.2, random); - this.velocityZ += MHelper.randRange(-0.2, 0.2, random); - } else if (check) { - changeDir = world.getBlockState(mut.set(x, y, z)).getFluidState().isEmpty(); - this.velocityX = 0; - this.velocityZ = 0; + this.xd += MHelper.randRange(-0.2, 0.2, random); + this.zd += MHelper.randRange(-0.2, 0.2, random); + } + else if (check) { + changeDir = level.getBlockState(mut.set(x, y, z)).getFluidState().isEmpty(); + this.xd = 0; + this.zd = 0; } } super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class FactoryGeyser implements ParticleFactory { + public static class FactoryGeyser implements ParticleProvider { private final SpriteSet sprites; @@ -71,8 +72,7 @@ public class ParticleGeyser extends SpriteBillboardParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleGeyser(world, x, y, z, 0, 0.125, 0, sprites); } } diff --git a/src/main/java/ru/betterend/particle/ParticleGlowingSphere.java b/src/main/java/ru/betterend/particle/ParticleGlowingSphere.java index 2628d725..09f5bd02 100644 --- a/src/main/java/ru/betterend/particle/ParticleGlowingSphere.java +++ b/src/main/java/ru/betterend/particle/ParticleGlowingSphere.java @@ -3,9 +3,9 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.particle.SimpleAnimatedParticle; import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SimpleAnimatedParticle; import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; @@ -20,28 +20,27 @@ public class ParticleGlowingSphere extends SimpleAnimatedParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected ParticleGlowingSphere(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, - double g, double b) { + + protected ParticleGlowingSphere(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, double g, double b) { super(world, x, y, z, sprites, 0); setSprite(sprites.get(random)); this.lifetime = MHelper.randRange(150, 300, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); this.setFadeColor(15916745); this.setSpriteFromAge(sprites); - + preVX = random.nextGaussian() * 0.02; preVY = random.nextGaussian() * 0.02; preVZ = random.nextGaussian() * 0.02; - + nextVX = random.nextGaussian() * 0.02; nextVY = random.nextGaussian() * 0.02; nextVZ = random.nextGaussian() * 0.02; } - + @Override public void tick() { - ticks++; + ticks ++; if (ticks > 30) { preVX = nextVX; preVY = nextVY; @@ -52,16 +51,16 @@ public class ParticleGlowingSphere extends SimpleAnimatedParticle { ticks = 0; } double delta = (double) ticks / 30.0; - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } @Environment(EnvType.CLIENT) - public static class FactoryGlowingSphere implements ParticleFactory { + public static class FactoryGlowingSphere implements ParticleProvider { private final SpriteSet sprites; @@ -70,8 +69,7 @@ public class ParticleGlowingSphere extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleGlowingSphere(world, x, y, z, sprites, 1, 1, 1); } } diff --git a/src/main/java/ru/betterend/particle/ParticleJungleSpore.java b/src/main/java/ru/betterend/particle/ParticleJungleSpore.java index 691ad9e9..496bc106 100644 --- a/src/main/java/ru/betterend/particle/ParticleJungleSpore.java +++ b/src/main/java/ru/betterend/particle/ParticleJungleSpore.java @@ -2,58 +2,60 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.SimpleAnimatedParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import ru.betterend.util.MHelper; @Environment(EnvType.CLIENT) public class ParticleJungleSpore extends SimpleAnimatedParticle { - - protected ParticleJungleSpore(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, - double g, double b) { + + protected ParticleJungleSpore(ClientLevel world, double x, double y, double z, SpriteSet sprites, double r, double g, double b) { super(world, x, y, z, sprites, 0); - setSprite(sprites.getSprite(random)); - this.maxAge = MHelper.randRange(150, 300, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); - this.setTargetColor(15916745); - this.setSpriteForAge(spriteProvider); - this.setColorAlpha(0); + setSprite(sprites.get(random)); + this.lifetime = MHelper.randRange(150, 300, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); + this.setFadeColor(15916745); + this.setSpriteFromAge(sprites); + this.setAlpha(0); } - + @Override public void tick() { super.tick(); - + int ticks = this.age % 30; if (ticks == 0) { - this.velocityX = random.nextGaussian() * 0.02; - this.velocityY = random.nextFloat() * 0.02 + 0.02; - this.velocityZ = random.nextGaussian() * 0.02; + this.xd = random.nextGaussian() * 0.02; + this.yd = random.nextFloat() * 0.02 + 0.02; + this.zd = random.nextGaussian() * 0.02; ticks = 0; } - + if (this.age <= 30) { float delta = ticks / 30F; - this.setColorAlpha(delta); - } else if (this.age >= this.maxAge) { - this.setColorAlpha(0); - } else if (this.age >= this.maxAge - 30) { - this.setColorAlpha((this.maxAge - this.age) / 30F); - } else { - this.setColorAlpha(1); + this.setAlpha(delta); } - - this.velocityY -= 0.001F; - this.velocityX *= 0.99F; - this.velocityZ *= 0.99F; + else if (this.age >= this.lifetime) { + this.setAlpha(0); + } + else if (this.age >= this.lifetime - 30) { + this.setAlpha((this.lifetime - this.age) / 30F); + } + else { + this.setAlpha(1); + } + + this.yd -= 0.001F; + this.xd *= 0.99F; + this.zd *= 0.99F; } @Environment(EnvType.CLIENT) - public static class FactoryJungleSpore implements ParticleFactory { + public static class FactoryJungleSpore implements ParticleProvider { private final SpriteSet sprites; public FactoryJungleSpore(SpriteSet sprites) { @@ -61,8 +63,7 @@ public class ParticleJungleSpore extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleJungleSpore(world, x, y, z, sprites, 1, 1, 1); } } diff --git a/src/main/java/ru/betterend/particle/ParticleSnowflake.java b/src/main/java/ru/betterend/particle/ParticleSnowflake.java index 1801fada..f7e389e4 100644 --- a/src/main/java/ru/betterend/particle/ParticleSnowflake.java +++ b/src/main/java/ru/betterend/particle/ParticleSnowflake.java @@ -2,18 +2,18 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @Environment(EnvType.CLIENT) -public class ParticleSnowflake extends SpriteBillboardParticle { +public class ParticleSnowflake extends TextureSheetParticle { private int ticks; private double preVX; private double preVY; @@ -21,28 +21,27 @@ public class ParticleSnowflake extends SpriteBillboardParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected ParticleSnowflake(ClientLevel world, double x, double y, double z, double r, double g, double b, - SpriteSet sprites) { + + protected ParticleSnowflake(ClientLevel world, double x, double y, double z, double r, double g, double b, SpriteSet sprites) { super(world, x, y, z, r, g, b); - setSprite(sprites); - - this.maxAge = MHelper.randRange(150, 300, random); - this.scale = MHelper.randRange(0.05F, 0.2F, random); - this.setColorAlpha(0F); - + pickSprite(sprites); + + this.lifetime = MHelper.randRange(150, 300, random); + this.quadSize = MHelper.randRange(0.05F, 0.2F, random); + this.setAlpha(0F); + preVX = random.nextGaussian() * 0.015; preVY = random.nextGaussian() * 0.015; preVZ = random.nextGaussian() * 0.015; - + nextVX = random.nextGaussian() * 0.015; nextVY = random.nextGaussian() * 0.015; nextVZ = random.nextGaussian() * 0.015; } - + @Override public void tick() { - ticks++; + ticks ++; if (ticks > 200) { preVX = nextVX; preVY = nextVY; @@ -56,31 +55,32 @@ public class ParticleSnowflake extends SpriteBillboardParticle { ticks = 0; } double delta = (double) ticks / 200.0; - + if (this.age <= 40) { - this.setColorAlpha(this.age / 40F); - } else if (this.age >= this.maxAge - 40) { - this.setColorAlpha((this.maxAge - this.age) / 40F); + this.setAlpha(this.age / 40F); } - - if (this.age >= this.maxAge) { - this.markDead(); + else if (this.age >= this.lifetime - 40) { + this.setAlpha((this.lifetime - this.age) / 40F); } - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + if (this.age >= this.lifetime) { + this.remove(); + } + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class FactorySnowflake implements ParticleFactory { + public static class FactorySnowflake implements ParticleProvider { private final SpriteSet sprites; @@ -89,8 +89,7 @@ public class ParticleSnowflake extends SpriteBillboardParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleSnowflake(world, x, y, z, 1, 1, 1, sprites); } } diff --git a/src/main/java/ru/betterend/particle/ParticleSulphur.java b/src/main/java/ru/betterend/particle/ParticleSulphur.java index 74a3d9f7..288bc830 100644 --- a/src/main/java/ru/betterend/particle/ParticleSulphur.java +++ b/src/main/java/ru/betterend/particle/ParticleSulphur.java @@ -2,18 +2,18 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @Environment(EnvType.CLIENT) -public class ParticleSulphur extends SpriteBillboardParticle { +public class ParticleSulphur extends TextureSheetParticle { private int ticks; private double preVX; private double preVY; @@ -21,29 +21,28 @@ public class ParticleSulphur extends SpriteBillboardParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected ParticleSulphur(ClientLevel world, double x, double y, double z, double r, double g, double b, - SpriteSet sprites) { + + protected ParticleSulphur(ClientLevel world, double x, double y, double z, double r, double g, double b, SpriteSet sprites) { super(world, x, y, z, r, g, b); - setSprite(sprites); - - this.maxAge = MHelper.randRange(150, 300, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); + pickSprite(sprites); + + this.lifetime = MHelper.randRange(150, 300, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); this.setColor(1, 1, 1); - this.setColorAlpha(0); - + this.setAlpha(0); + preVX = random.nextGaussian() * 0.015; preVY = random.nextGaussian() * 0.015; preVZ = random.nextGaussian() * 0.015; - + nextVX = random.nextGaussian() * 0.015; nextVY = random.nextGaussian() * 0.015; nextVZ = random.nextGaussian() * 0.015; } - + @Override public void tick() { - ticks++; + ticks ++; if (ticks > 200) { preVX = nextVX; preVY = nextVY; @@ -57,31 +56,32 @@ public class ParticleSulphur extends SpriteBillboardParticle { ticks = 0; } double delta = (double) ticks / 200.0; - + if (this.age <= 40) { - this.setColorAlpha(this.age / 40F); - } else if (this.age >= this.maxAge - 40) { - this.setColorAlpha((this.maxAge - this.age) / 40F); + this.setAlpha(this.age / 40F); } - - if (this.age >= this.maxAge) { - this.markDead(); + else if (this.age >= this.lifetime - 40) { + this.setAlpha((this.lifetime - this.age) / 40F); } - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + if (this.age >= this.lifetime) { + this.remove(); + } + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class FactorySulphur implements ParticleFactory { + public static class FactorySulphur implements ParticleProvider { private final SpriteSet sprites; @@ -90,8 +90,7 @@ public class ParticleSulphur extends SpriteBillboardParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleSulphur(world, x, y, z, 1, 1, 1, sprites); } } diff --git a/src/main/java/ru/betterend/particle/ParticleTenaneaPetal.java b/src/main/java/ru/betterend/particle/ParticleTenaneaPetal.java index 52e438bb..abf2c9d7 100644 --- a/src/main/java/ru/betterend/particle/ParticleTenaneaPetal.java +++ b/src/main/java/ru/betterend/particle/ParticleTenaneaPetal.java @@ -3,62 +3,61 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.color.block.BlockColor; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteBillboardParticle; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SpriteSet; +import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.interfaces.IColorProvider; import ru.betterend.registry.EndBlocks; import ru.betterend.util.MHelper; @Environment(EnvType.CLIENT) -public class ParticleTenaneaPetal extends SpriteBillboardParticle { +public class ParticleTenaneaPetal extends TextureSheetParticle { private static BlockColor provider; - + private double preVX; private double preVY; private double preVZ; private double nextVX; private double nextVY; private double nextVZ; - - protected ParticleTenaneaPetal(ClientLevel world, double x, double y, double z, double r, double g, double b, - SpriteSet sprites) { + + protected ParticleTenaneaPetal(ClientLevel world, double x, double y, double z, double r, double g, double b, SpriteSet sprites) { super(world, x, y, z, r, g, b); - setSprite(sprites); - + pickSprite(sprites); + if (provider == null) { IColorProvider block = (IColorProvider) EndBlocks.TENANEA_FLOWERS; - provider = block.getBlockProvider(); + provider = block.getProvider(); } int color = provider.getColor(null, null, new BlockPos(x, y, z), 0); - this.colorRed = ((color >> 16) & 255) / 255F; - this.colorGreen = ((color >> 8) & 255) / 255F; - this.colorBlue = ((color) & 255) / 255F; - - this.maxAge = MHelper.randRange(120, 200, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); - this.setColorAlpha(0); - + this.rCol = ((color >> 16) & 255) / 255F; + this.gCol = ((color >> 8) & 255) / 255F; + this.bCol = ((color) & 255) / 255F; + + this.lifetime = MHelper.randRange(120, 200, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); + this.setAlpha(0); + preVX = 0; preVY = 0; preVZ = 0; - + nextVX = random.nextGaussian() * 0.02; nextVY = -random.nextDouble() * 0.02 - 0.02; nextVZ = random.nextGaussian() * 0.02; } @Override - public int getColorMultiplier(float tint) { + public int getLightColor(float tint) { return 15728880; } - + @Override public void tick() { int ticks = this.age & 63; @@ -71,31 +70,32 @@ public class ParticleTenaneaPetal extends SpriteBillboardParticle { nextVZ = random.nextGaussian() * 0.02; } double delta = (double) ticks / 63.0; - + if (this.age <= 40) { - this.setColorAlpha(this.age / 40F); - } else if (this.age >= this.maxAge - 40) { - this.setColorAlpha((this.maxAge - this.age) / 40F); + this.setAlpha(this.age / 40F); } - - if (this.age >= this.maxAge) { - this.markDead(); + else if (this.age >= this.lifetime - 40) { + this.setAlpha((this.lifetime - this.age) / 40F); } - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + if (this.age >= this.lifetime) { + this.remove(); + } + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class FactoryTenaneaPetal implements ParticleFactory { + public static class FactoryTenaneaPetal implements ParticleProvider { private final SpriteSet sprites; @@ -104,8 +104,7 @@ public class ParticleTenaneaPetal extends SpriteBillboardParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new ParticleTenaneaPetal(world, x, y, z, 1, 1, 1, sprites); } } diff --git a/src/main/java/ru/betterend/particle/PaticlePortalSphere.java b/src/main/java/ru/betterend/particle/PaticlePortalSphere.java index 7566c67b..4df6155e 100644 --- a/src/main/java/ru/betterend/particle/PaticlePortalSphere.java +++ b/src/main/java/ru/betterend/particle/PaticlePortalSphere.java @@ -2,11 +2,11 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.SimpleAnimatedParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @@ -19,25 +19,25 @@ public class PaticlePortalSphere extends SimpleAnimatedParticle { private double nextVX; private double nextVY; private double nextVZ; - + public PaticlePortalSphere(ClientLevel world, double x, double y, double z, SpriteSet spriteProvider) { super(world, x, y, z, spriteProvider, 0); - setSprite(spriteProvider.getSprite(random)); - this.maxAge = MHelper.randRange(20, 80, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); + setSprite(spriteProvider.get(random)); + this.lifetime = MHelper.randRange(20, 80, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); this.setColor(0xFEBBD5); - this.setTargetColor(0xBBFEE4); - this.setSpriteForAge(spriteProvider); - + this.setFadeColor(0xBBFEE4); + this.setSpriteFromAge(spriteProvider); + preVX = random.nextGaussian() * 0.02; preVY = random.nextGaussian() * 0.02; preVZ = random.nextGaussian() * 0.02; - + nextVX = random.nextGaussian() * 0.02; nextVY = random.nextGaussian() * 0.02; nextVZ = random.nextGaussian() * 0.02; } - + @Override public void tick() { ticks++; @@ -51,16 +51,16 @@ public class PaticlePortalSphere extends SimpleAnimatedParticle { ticks = 0; } double delta = (double) ticks / 30.0; - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } @Environment(EnvType.CLIENT) - public static class FactoryPortalSphere implements ParticleFactory { + public static class FactoryPortalSphere implements ParticleProvider { private final SpriteSet sprites; @@ -69,8 +69,7 @@ public class PaticlePortalSphere extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new PaticlePortalSphere(world, x, y, z, sprites); } } diff --git a/src/main/java/ru/betterend/particle/SmaragdantParticle.java b/src/main/java/ru/betterend/particle/SmaragdantParticle.java index 2cb5aac3..ceab0088 100644 --- a/src/main/java/ru/betterend/particle/SmaragdantParticle.java +++ b/src/main/java/ru/betterend/particle/SmaragdantParticle.java @@ -2,12 +2,12 @@ package ru.betterend.particle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.particle.SimpleAnimatedParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.client.particle.ParticleFactory; -import net.minecraft.client.particle.ParticleTextureSheet; -import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleProvider; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.particle.SimpleAnimatedParticle; +import net.minecraft.client.particle.SpriteSet; import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.util.Mth; import ru.betterend.util.MHelper; @@ -20,26 +20,25 @@ public class SmaragdantParticle extends SimpleAnimatedParticle { private double nextVX; private double nextVY; private double nextVZ; - - protected SmaragdantParticle(ClientLevel world, double x, double y, double z, double r, double g, double b, - SpriteSet sprites) { + + protected SmaragdantParticle(ClientLevel world, double x, double y, double z, double r, double g, double b, SpriteSet sprites) { super(world, x, y, z, sprites, 0); - setSprite(sprites.getSprite(random)); - - this.maxAge = MHelper.randRange(60, 120, random); - this.scale = MHelper.randRange(0.05F, 0.15F, random); + setSprite(sprites.get(random)); + + this.lifetime = MHelper.randRange(60, 120, random); + this.quadSize = MHelper.randRange(0.05F, 0.15F, random); this.setColor(1, 1, 1); - this.setColorAlpha(0); - + this.setAlpha(0); + preVX = random.nextGaussian() * 0.01; preVY = random.nextGaussian() * 0.01; preVZ = random.nextGaussian() * 0.01; - + nextVX = random.nextGaussian() * 0.01; nextVY = random.nextGaussian() * 0.01; nextVZ = random.nextGaussian() * 0.01; } - + @Override public void tick() { int ticks = this.age & 31; @@ -52,31 +51,32 @@ public class SmaragdantParticle extends SimpleAnimatedParticle { nextVZ = random.nextGaussian() * 0.015; } double delta = (double) ticks / 31.0; - + if (this.age <= 31) { - this.setColorAlpha(this.age / 31F); - } else if (this.age >= this.maxAge - 31) { - this.setColorAlpha((this.maxAge - this.age) / 31F); + this.setAlpha(this.age / 31F); } - - if (this.age >= this.maxAge) { - this.markDead(); + else if (this.age >= this.lifetime - 31) { + this.setAlpha((this.lifetime - this.age) / 31F); } - - this.velocityX = Mth.lerp(delta, preVX, nextVX); - this.velocityY = Mth.lerp(delta, preVY, nextVY); - this.velocityZ = Mth.lerp(delta, preVZ, nextVZ); - + + if (this.age >= this.lifetime) { + this.remove(); + } + + this.xd = Mth.lerp(delta, preVX, nextVX); + this.yd = Mth.lerp(delta, preVY, nextVY); + this.zd = Mth.lerp(delta, preVZ, nextVZ); + super.tick(); } - + @Override - public ParticleTextureSheet getType() { - return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + public ParticleRenderType getRenderType() { + return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT; } @Environment(EnvType.CLIENT) - public static class SmaragdantParticleFactory implements ParticleFactory { + public static class SmaragdantParticleFactory implements ParticleProvider { private final SpriteSet sprites; @@ -85,8 +85,7 @@ public class SmaragdantParticle extends SimpleAnimatedParticle { } @Override - public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, - double vX, double vY, double vZ) { + public Particle createParticle(SimpleParticleType type, ClientLevel world, double x, double y, double z, double vX, double vY, double vZ) { return new SmaragdantParticle(world, x, y, z, 1, 1, 1, sprites); } } diff --git a/src/main/java/ru/betterend/patterns/BlockPatterned.java b/src/main/java/ru/betterend/patterns/BlockPatterned.java index 61feee5d..3e35dee0 100644 --- a/src/main/java/ru/betterend/patterns/BlockPatterned.java +++ b/src/main/java/ru/betterend/patterns/BlockPatterned.java @@ -1,14 +1,12 @@ package ru.betterend.patterns; import java.io.Reader; - import net.minecraft.resources.ResourceLocation; public interface BlockPatterned extends Patterned { default String getStatesPattern(Reader data) { return null; } - default ResourceLocation statePatternId() { return null; } diff --git a/src/main/java/ru/betterend/patterns/Patterns.java b/src/main/java/ru/betterend/patterns/Patterns.java index d4f5b7da..9db38371 100644 --- a/src/main/java/ru/betterend/patterns/Patterns.java +++ b/src/main/java/ru/betterend/patterns/Patterns.java @@ -8,17 +8,15 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Collectors; - -import com.google.common.collect.Maps; - import net.minecraft.client.Minecraft; -import net.minecraft.resource.ResourceManager; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import com.google.common.collect.Maps; import ru.betterend.BetterEnd; public class Patterns { - - // Blockstates + + //Blockstates public final static ResourceLocation STATE_SIMPLE = BetterEnd.makeID("patterns/blockstate/block.json"); public final static ResourceLocation STATE_SLAB = BetterEnd.makeID("patterns/blockstate/slab.json"); public final static ResourceLocation STATE_STAIRS = BetterEnd.makeID("patterns/blockstate/stairs.json"); @@ -27,8 +25,7 @@ public class Patterns { public final static ResourceLocation STATE_BUTTON = BetterEnd.makeID("patterns/blockstate/button.json"); public final static ResourceLocation STATE_PILLAR = BetterEnd.makeID("patterns/blockstate/pillar.json"); public final static ResourceLocation STATE_PLATE = BetterEnd.makeID("patterns/blockstate/pressure_plate.json"); - public final static ResourceLocation STATE_PLATE_ROTATED = BetterEnd - .makeID("patterns/blockstate/pressure_plate_rotated.json"); + public final static ResourceLocation STATE_PLATE_ROTATED = BetterEnd.makeID("patterns/blockstate/pressure_plate_rotated.json"); public final static ResourceLocation STATE_DOOR = BetterEnd.makeID("patterns/blockstate/door.json"); public final static ResourceLocation STATE_SAPLING = BetterEnd.makeID("patterns/blockstate/sapling.json"); public final static ResourceLocation STATE_GATE = BetterEnd.makeID("patterns/blockstate/fence_gate.json"); @@ -36,8 +33,7 @@ public class Patterns { public final static ResourceLocation STATE_LADDER = BetterEnd.makeID("patterns/blockstate/ladder.json"); public final static ResourceLocation STATE_BARREL = BetterEnd.makeID("patterns/blockstate/barrel.json"); public final static ResourceLocation STATE_PEDESTAL = BetterEnd.makeID("patterns/blockstate/pedestal.json"); - public final static ResourceLocation STATE_STONE_LANTERN = BetterEnd - .makeID("patterns/blockstate/stone_lantern.json"); + public final static ResourceLocation STATE_STONE_LANTERN = BetterEnd.makeID("patterns/blockstate/stone_lantern.json"); public final static ResourceLocation STATE_DIRECT = BetterEnd.makeID("patterns/blockstate/direct.json"); public final static ResourceLocation STATE_BULB_LANTERN = BetterEnd.makeID("patterns/blockstate/bulb_lantern.json"); public final static ResourceLocation STATE_COMPOSTER = BetterEnd.makeID("patterns/blockstate/composter.json"); @@ -48,11 +44,10 @@ public class Patterns { public final static ResourceLocation STATE_CHANDELIER = BetterEnd.makeID("patterns/blockstate/chandelier.json"); public final static ResourceLocation STATE_FURNACE = BetterEnd.makeID("patterns/blockstate/furnace.json"); public final static ResourceLocation STATE_ROTATED_TOP = BetterEnd.makeID("patterns/blockstate/rotated_top.json"); - public final static ResourceLocation STATE_TRIPLE_ROTATED_TOP = BetterEnd - .makeID("patterns/blockstate/triple_rotated_top.json"); + public final static ResourceLocation STATE_TRIPLE_ROTATED_TOP = BetterEnd.makeID("patterns/blockstate/triple_rotated_top.json"); public final static ResourceLocation STATE_STALACTITE = BetterEnd.makeID("patterns/blockstate/stalactite.json"); - - // Models Block + + //Models Block public final static ResourceLocation BLOCK_EMPTY = BetterEnd.makeID("patterns/block/empty.json"); public final static ResourceLocation BLOCK_BASE = BetterEnd.makeID("patterns/block/block.json"); public final static ResourceLocation BLOCK_SIDED = BetterEnd.makeID("patterns/block/block_sided.json"); @@ -74,59 +69,43 @@ public class Patterns { public final static ResourceLocation BLOCK_DOOR_TOP = BetterEnd.makeID("patterns/block/door_top.json"); public final static ResourceLocation BLOCK_DOOR_TOP_HINGE = BetterEnd.makeID("patterns/block/door_top_hinge.json"); public final static ResourceLocation BLOCK_DOOR_BOTTOM = BetterEnd.makeID("patterns/block/door_bottom.json"); - public final static ResourceLocation BLOCK_DOOR_BOTTOM_HINGE = BetterEnd - .makeID("patterns/block/door_bottom_hinge.json"); + public final static ResourceLocation BLOCK_DOOR_BOTTOM_HINGE = BetterEnd.makeID("patterns/block/door_bottom_hinge.json"); public final static ResourceLocation BLOCK_CROSS = BetterEnd.makeID("patterns/block/cross.json"); public final static ResourceLocation BLOCK_CROSS_SHADED = BetterEnd.makeID("patterns/block/cross_shaded.json"); public final static ResourceLocation BLOCK_GATE_CLOSED = BetterEnd.makeID("patterns/block/fence_gate_closed.json"); - public final static ResourceLocation BLOCK_GATE_CLOSED_WALL = BetterEnd - .makeID("patterns/block/wall_gate_closed.json"); + public final static ResourceLocation BLOCK_GATE_CLOSED_WALL = BetterEnd.makeID("patterns/block/wall_gate_closed.json"); public final static ResourceLocation BLOCK_GATE_OPEN = BetterEnd.makeID("patterns/block/fence_gate_open.json"); public final static ResourceLocation BLOCK_GATE_OPEN_WALL = BetterEnd.makeID("patterns/block/wall_gate_open.json"); public final static ResourceLocation BLOCK_TRAPDOOR = BetterEnd.makeID("patterns/block/trapdoor.json"); public final static ResourceLocation BLOCK_LADDER = BetterEnd.makeID("patterns/block/ladder.json"); public final static ResourceLocation BLOCK_BARREL_OPEN = BetterEnd.makeID("patterns/block/barrel_open.json"); - public final static ResourceLocation BLOCK_PEDESTAL_DEFAULT = BetterEnd - .makeID("patterns/block/pedestal_default.json"); - public final static ResourceLocation BLOKC_PEDESTAL_COLUMN = BetterEnd - .makeID("patterns/block/pedestal_column.json"); - public final static ResourceLocation BLOCK_PEDESTAL_COLUMN_TOP = BetterEnd - .makeID("patterns/block/pedestal_column_top.json"); + public final static ResourceLocation BLOCK_PEDESTAL_DEFAULT = BetterEnd.makeID("patterns/block/pedestal_default.json"); + public final static ResourceLocation BLOKC_PEDESTAL_COLUMN = BetterEnd.makeID("patterns/block/pedestal_column.json"); + public final static ResourceLocation BLOCK_PEDESTAL_COLUMN_TOP = BetterEnd.makeID("patterns/block/pedestal_column_top.json"); public final static ResourceLocation BLOCK_PEDESTAL_TOP = BetterEnd.makeID("patterns/block/pedestal_top.json"); - public final static ResourceLocation BLOCK_PEDESTAL_BOTTOM = BetterEnd - .makeID("patterns/block/pedestal_bottom.json"); - public final static ResourceLocation BLOCK_PEDESTAL_PILLAR = BetterEnd - .makeID("patterns/block/pedestal_pillar.json"); + public final static ResourceLocation BLOCK_PEDESTAL_BOTTOM = BetterEnd.makeID("patterns/block/pedestal_bottom.json"); + public final static ResourceLocation BLOCK_PEDESTAL_PILLAR = BetterEnd.makeID("patterns/block/pedestal_pillar.json"); public final static ResourceLocation BLOCK_BOOKSHELF = BetterEnd.makeID("patterns/block/bookshelf.json"); - public final static ResourceLocation BLOCK_STONE_LANTERN_CEIL = BetterEnd - .makeID("patterns/block/stone_lantern_ceil.json"); - public final static ResourceLocation BLOCK_STONE_LANTERN_FLOOR = BetterEnd - .makeID("patterns/block/stone_lantern_floor.json"); - public final static ResourceLocation BLOCK_BULB_LANTERN_FLOOR = BetterEnd - .makeID("patterns/block/bulb_lantern_floor.json"); - public final static ResourceLocation BLOCK_BULB_LANTERN_CEIL = BetterEnd - .makeID("patterns/block/bulb_lantern_ceil.json"); - public final static ResourceLocation BLOCK_PETAL_COLORED = BetterEnd - .makeID("models/block/block_petal_colored.json"); + public final static ResourceLocation BLOCK_STONE_LANTERN_CEIL = BetterEnd.makeID("patterns/block/stone_lantern_ceil.json"); + public final static ResourceLocation BLOCK_STONE_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/stone_lantern_floor.json"); + public final static ResourceLocation BLOCK_BULB_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/bulb_lantern_floor.json"); + public final static ResourceLocation BLOCK_BULB_LANTERN_CEIL = BetterEnd.makeID("patterns/block/bulb_lantern_ceil.json"); + public final static ResourceLocation BLOCK_PETAL_COLORED = BetterEnd.makeID("models/block/block_petal_colored.json"); public final static ResourceLocation BLOCK_COMPOSTER = BetterEnd.makeID("patterns/block/composter.json"); public final static ResourceLocation BLOCK_COLORED = BetterEnd.makeID("patterns/block/block_colored.json"); public final static ResourceLocation BLOCK_BARS_POST = BetterEnd.makeID("patterns/block/bars_post.json"); public final static ResourceLocation BLOCK_BARS_SIDE = BetterEnd.makeID("patterns/block/bars_side.json"); public final static ResourceLocation BLOCK_ANVIL = BetterEnd.makeID("patterns/block/anvil.json"); public final static ResourceLocation BLOCK_CHAIN = BetterEnd.makeID("patterns/block/chain.json"); - public final static ResourceLocation BLOCK_CHANDELIER_FLOOR = BetterEnd - .makeID("patterns/block/chandelier_floor.json"); - public final static ResourceLocation BLOCK_CHANDELIER_WALL = BetterEnd - .makeID("patterns/block/chandelier_wall.json"); - public final static ResourceLocation BLOCK_CHANDELIER_CEIL = BetterEnd - .makeID("patterns/block/chandelier_ceil.json"); + public final static ResourceLocation BLOCK_CHANDELIER_FLOOR = BetterEnd.makeID("patterns/block/chandelier_floor.json"); + public final static ResourceLocation BLOCK_CHANDELIER_WALL = BetterEnd.makeID("patterns/block/chandelier_wall.json"); + public final static ResourceLocation BLOCK_CHANDELIER_CEIL = BetterEnd.makeID("patterns/block/chandelier_ceil.json"); public final static ResourceLocation BLOCK_FURNACE = BetterEnd.makeID("patterns/block/furnace.json"); public final static ResourceLocation BLOCK_FURNACE_GLOW = BetterEnd.makeID("patterns/block/furnace_glow.json"); - public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd - .makeID("patterns/block/top_side_bottom.json"); + public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json"); public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json"); - - // Models Item + + //Models Item public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); public final static ResourceLocation ITEM_FENCE = BetterEnd.makeID("patterns/item/pattern_fence.json"); public final static ResourceLocation ITEM_BUTTON = BetterEnd.makeID("patterns/item/pattern_button.json"); @@ -135,15 +114,17 @@ public class Patterns { public final static ResourceLocation ITEM_GENERATED = BetterEnd.makeID("patterns/item/pattern_item_generated.json"); public final static ResourceLocation ITEM_HANDHELD = BetterEnd.makeID("patterns/item/pattern_item_handheld.json"); public final static ResourceLocation ITEM_SPAWN_EGG = BetterEnd.makeID("patterns/item/pattern_item_spawn_egg.json"); - + public static String createJson(Reader data, String parent, String block) { try (BufferedReader buffer = new BufferedReader(data)) { - return buffer.lines().collect(Collectors.joining()).replace("%parent%", parent).replace("%block%", block); + return buffer.lines().collect(Collectors.joining()) + .replace("%parent%", parent) + .replace("%block%", block); } catch (Exception ex) { return null; } } - + public static String createJson(ResourceLocation patternId, String parent, String block) { ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); try (InputStream input = resourceManager.getResource(patternId).getInputStream()) { @@ -162,8 +143,8 @@ public class Patterns { public static String createJson(ResourceLocation patternId, Map textures) { ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); try (InputStream input = resourceManager.getResource(patternId).getInputStream()) { - String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines() - .collect(Collectors.joining()); + String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) + .lines().collect(Collectors.joining()); for (Entry texture : textures.entrySet()) { json = json.replace(texture.getKey(), texture.getValue()); } diff --git a/src/main/java/ru/betterend/recipe/AlloyingRecipes.java b/src/main/java/ru/betterend/recipe/AlloyingRecipes.java index 0204b435..9d6dfc88 100644 --- a/src/main/java/ru/betterend/recipe/AlloyingRecipes.java +++ b/src/main/java/ru/betterend/recipe/AlloyingRecipes.java @@ -1,25 +1,46 @@ package ru.betterend.recipe; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; import ru.betterend.recipe.builders.AlloyingRecipe; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public class AlloyingRecipes { public static void register() { - AlloyingRecipe.Builder.create("additional_iron").setInput(Blocks.IRON_ORE, Blocks.IRON_ORE) - .setOutput(Items.IRON_INGOT, 3).setExpiriense(2.1F).build(); - AlloyingRecipe.Builder.create("additional_gold").setInput(Blocks.GOLD_ORE, Blocks.GOLD_ORE) - .setOutput(Items.GOLD_INGOT, 3).setExpiriense(3F).build(); - AlloyingRecipe.Builder.create("additional_netherite").setInput(Blocks.ANCIENT_DEBRIS, Blocks.ANCIENT_DEBRIS) - .setOutput(Items.NETHERITE_SCRAP, 3).setExpiriense(6F).setSmeltTime(1000).build(); - AlloyingRecipe.Builder.create("terminite_ingot").setInput(Items.IRON_INGOT, EndItems.ENDER_DUST) - .setOutput(EndBlocks.TERMINITE.ingot, 1).setExpiriense(2.5F).setSmeltTime(450).build(); - AlloyingRecipe.Builder.create("aeternium_ingot").setInput(EndBlocks.TERMINITE.ingot, Items.NETHERITE_INGOT) - .setOutput(EndItems.AETERNIUM_INGOT, 1).setExpiriense(4.5F).setSmeltTime(850).build(); + AlloyingRecipe.Builder.create("additional_iron") + .setInput(Blocks.IRON_ORE, Blocks.IRON_ORE) + .setOutput(Items.IRON_INGOT, 3) + .setExpiriense(2.1F) + .build(); + AlloyingRecipe.Builder.create("additional_gold") + .setInput(Blocks.GOLD_ORE, Blocks.GOLD_ORE) + .setOutput(Items.GOLD_INGOT, 3) + .setExpiriense(3F) + .build(); + AlloyingRecipe.Builder.create("additional_netherite") + .setInput(Blocks.ANCIENT_DEBRIS, Blocks.ANCIENT_DEBRIS) + .setOutput(Items.NETHERITE_SCRAP, 3) + .setExpiriense(6F) + .setSmeltTime(1000) + .build(); + AlloyingRecipe.Builder.create("terminite_ingot") + .setInput(Items.IRON_INGOT, EndItems.ENDER_DUST) + .setOutput(EndBlocks.TERMINITE.ingot, 1) + .setExpiriense(2.5F) + .setSmeltTime(450) + .build(); + AlloyingRecipe.Builder.create("aeternium_ingot") + .setInput(EndBlocks.TERMINITE.ingot, Items.NETHERITE_INGOT) + .setOutput(EndItems.AETERNIUM_INGOT, 1) + .setExpiriense(4.5F) + .setSmeltTime(850) + .build(); AlloyingRecipe.Builder.create("terminite_ingot_thallasium") - .setInput(EndBlocks.THALLASIUM.ingot, EndItems.ENDER_DUST).setOutput(EndBlocks.TERMINITE.ingot, 1) - .setExpiriense(2.5F).setSmeltTime(450).build(); + .setInput(EndBlocks.THALLASIUM.ingot, EndItems.ENDER_DUST) + .setOutput(EndBlocks.TERMINITE.ingot, 1) + .setExpiriense(2.5F) + .setSmeltTime(450) + .build(); } } diff --git a/src/main/java/ru/betterend/recipe/AnvilRecipes.java b/src/main/java/ru/betterend/recipe/AnvilRecipes.java index b72ce6d4..0e110e83 100644 --- a/src/main/java/ru/betterend/recipe/AnvilRecipes.java +++ b/src/main/java/ru/betterend/recipe/AnvilRecipes.java @@ -7,27 +7,61 @@ import ru.betterend.registry.EndItems; public class AnvilRecipes { public static void register() { - AnvilRecipe.Builder.create("ender_pearl_to_dust").setInput(Items.ENDER_PEARL).setOutput(EndItems.ENDER_DUST) - .setToolLevel(4).setDamage(5).build(); - AnvilRecipe.Builder.create("ender_shard_to_dust").setInput(EndItems.ENDER_SHARD).setOutput(EndItems.ENDER_DUST) - .setToolLevel(0).setDamage(3).build(); - + AnvilRecipe.Builder.create("ender_pearl_to_dust") + .setInput(Items.ENDER_PEARL) + .setOutput(EndItems.ENDER_DUST) + .setToolLevel(4) + .setDamage(5) + .build(); + AnvilRecipe.Builder.create("ender_shard_to_dust") + .setInput(EndItems.ENDER_SHARD) + .setOutput(EndItems.ENDER_DUST) + .setToolLevel(0) + .setDamage(3) + .build(); + int anvilLevel = EndToolMaterial.AETERNIUM.getLevel(); - AnvilRecipe.Builder.create("aeternium_axe_head").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_AXE_HEAD).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6).build(); - AnvilRecipe.Builder.create("aeternium_pickaxe_head").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_PICKAXE_HEAD).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6) - .build(); - AnvilRecipe.Builder.create("aeternium_shovel_head").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_SHOVEL_HEAD).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6) - .build(); - AnvilRecipe.Builder.create("aeternium_hoe_head").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_HOE_HEAD).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6).build(); - AnvilRecipe.Builder.create("aeternium_hammer_head").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_HAMMER_HEAD).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6) - .build(); - AnvilRecipe.Builder.create("aeternium_sword_blade").setInput(EndItems.AETERNIUM_INGOT) - .setOutput(EndItems.AETERNIUM_SWORD_BLADE).setAnvilLevel(anvilLevel).setToolLevel(4).setDamage(6) - .build(); + AnvilRecipe.Builder.create("aeternium_axe_head") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_AXE_HEAD) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); + AnvilRecipe.Builder.create("aeternium_pickaxe_head") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_PICKAXE_HEAD) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); + AnvilRecipe.Builder.create("aeternium_shovel_head") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_SHOVEL_HEAD) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); + AnvilRecipe.Builder.create("aeternium_hoe_head") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_HOE_HEAD) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); + AnvilRecipe.Builder.create("aeternium_hammer_head") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_HAMMER_HEAD) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); + AnvilRecipe.Builder.create("aeternium_sword_blade") + .setInput(EndItems.AETERNIUM_INGOT) + .setOutput(EndItems.AETERNIUM_SWORD_BLADE) + .setAnvilLevel(anvilLevel) + .setToolLevel(4) + .setDamage(6) + .build(); } } diff --git a/src/main/java/ru/betterend/recipe/CraftingRecipes.java b/src/main/java/ru/betterend/recipe/CraftingRecipes.java index 841be2e2..4b894a6b 100644 --- a/src/main/java/ru/betterend/recipe/CraftingRecipes.java +++ b/src/main/java/ru/betterend/recipe/CraftingRecipes.java @@ -1,12 +1,12 @@ package ru.betterend.recipe; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; -import net.minecraft.potion.PotionUtil; +import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import ru.betterend.BetterEnd; import ru.betterend.item.GuideBookItem; import ru.betterend.recipe.builders.GridRecipe; @@ -15,66 +15,71 @@ import ru.betterend.registry.EndItems; import ru.betterend.registry.EndTags; public class CraftingRecipes { - + public static void register() { if (BetterEnd.hasGuideBook()) { - GridRecipe.make("guide_book", GuideBookItem.GUIDE_BOOK).setShape("D", "B", "C") - .addMaterial('D', EndItems.ENDER_DUST).addMaterial('B', Items.BOOK) - .addMaterial('C', EndItems.CRYSTAL_SHARDS).build(); + GridRecipe.make("guide_book", GuideBookItem.GUIDE_BOOK) + .setShape("D", "B", "C") + .addMaterial('D', EndItems.ENDER_DUST) + .addMaterial('B', Items.BOOK) + .addMaterial('C', EndItems.CRYSTAL_SHARDS) + .build(); } - - GridRecipe.make("ender_perl_to_block", EndBlocks.ENDER_BLOCK).setShape("OO", "OO") - .addMaterial('O', Items.ENDER_PEARL).build(); - GridRecipe.make("ender_block_to_perl", Items.ENDER_PEARL).addMaterial('#', EndBlocks.ENDER_BLOCK) - .setOutputCount(4).setList("#").build(); - - GridRecipe.make("end_stone_smelter", EndBlocks.END_STONE_SMELTER).setShape("T#T", "V V", "T#T") - .addMaterial('#', Blocks.END_STONE_BRICKS).addMaterial('T', EndBlocks.THALLASIUM.ingot) - .addMaterial('V', EndTags.FURNACES).build(); - - registerPedestal("andesite_pedestal", EndBlocks.ANDESITE_PEDESTAL, Blocks.POLISHED_ANDESITE_SLAB, - Blocks.POLISHED_ANDESITE); - registerPedestal("diorite_pedestal", EndBlocks.DIORITE_PEDESTAL, Blocks.POLISHED_DIORITE_SLAB, - Blocks.POLISHED_DIORITE); - registerPedestal("granite_pedestal", EndBlocks.GRANITE_PEDESTAL, Blocks.POLISHED_GRANITE_SLAB, - Blocks.POLISHED_GRANITE); + + GridRecipe.make("ender_perl_to_block", EndBlocks.ENDER_BLOCK) + .setShape("OO", "OO") + .addMaterial('O', Items.ENDER_PEARL) + .build(); + GridRecipe.make("ender_block_to_perl", Items.ENDER_PEARL) + .addMaterial('#', EndBlocks.ENDER_BLOCK) + .setOutputCount(4) + .setList("#") + .build(); + + GridRecipe.make("end_stone_smelter", EndBlocks.END_STONE_SMELTER) + .setShape("T#T", "V V", "T#T") + .addMaterial('#', Blocks.END_STONE_BRICKS) + .addMaterial('T', EndBlocks.THALLASIUM.ingot) + .addMaterial('V', EndTags.FURNACES) + .build(); + + registerPedestal("andesite_pedestal", EndBlocks.ANDESITE_PEDESTAL, Blocks.POLISHED_ANDESITE_SLAB, Blocks.POLISHED_ANDESITE); + registerPedestal("diorite_pedestal", EndBlocks.DIORITE_PEDESTAL, Blocks.POLISHED_DIORITE_SLAB, Blocks.POLISHED_DIORITE); + registerPedestal("granite_pedestal", EndBlocks.GRANITE_PEDESTAL, Blocks.POLISHED_GRANITE_SLAB, Blocks.POLISHED_GRANITE); registerPedestal("quartz_pedestal", EndBlocks.QUARTZ_PEDESTAL, Blocks.QUARTZ_SLAB, Blocks.QUARTZ_PILLAR); registerPedestal("purpur_pedestal", EndBlocks.PURPUR_PEDESTAL, Blocks.PURPUR_SLAB, Blocks.PURPUR_PILLAR); - - GridRecipe.make("infusion_pedestal", EndBlocks.INFUSION_PEDESTAL).setShape(" Y ", "O#O", " # ") - .addMaterial('O', Items.ENDER_PEARL).addMaterial('Y', Items.ENDER_EYE).addMaterial('#', Blocks.OBSIDIAN) - .build(); - + + GridRecipe.make("infusion_pedestal", EndBlocks.INFUSION_PEDESTAL) + .setShape(" Y ", "O#O", " # ") + .addMaterial('O', Items.ENDER_PEARL) + .addMaterial('Y', Items.ENDER_EYE) + .addMaterial('#', Blocks.OBSIDIAN) + .build(); + String material = "aeternium"; - GridRecipe.make(material + "_block", EndBlocks.AETERNIUM_BLOCK).setShape("III", "III", "III") - .addMaterial('I', EndItems.AETERNIUM_INGOT).build(); + GridRecipe.make(material + "_block", EndBlocks.AETERNIUM_BLOCK) + .setShape("III", "III", "III") + .addMaterial('I', EndItems.AETERNIUM_INGOT) + .build(); GridRecipe.make(material + "_block_to_ingot", EndItems.AETERNIUM_INGOT) - .addMaterial('#', EndBlocks.AETERNIUM_BLOCK).setOutputCount(9).setList("#").build(); - - GridRecipe.make("blue_vine_seed_dye", Items.BLUE_DYE).setList("#").addMaterial('#', EndBlocks.BLUE_VINE_SEED) - .build(); - GridRecipe.make("creeping_moss_dye", Items.CYAN_DYE).setList("#").addMaterial('#', EndBlocks.CREEPING_MOSS) - .build(); - GridRecipe.make("umbrella_moss_dye", Items.YELLOW_DYE).setList("#").addMaterial('#', EndBlocks.UMBRELLA_MOSS) - .build(); - GridRecipe.make("umbrella_moss_tall_dye", Items.YELLOW_DYE).setOutputCount(2).setList("#") - .addMaterial('#', EndBlocks.UMBRELLA_MOSS_TALL).build(); - GridRecipe.make("shadow_plant_dye", Items.BLACK_DYE).setList("#").addMaterial('#', EndBlocks.SHADOW_PLANT) - .build(); - - GridRecipe.make("paper", Items.PAPER).setShape("###").addMaterial('#', EndItems.END_LILY_LEAF_DRIED) - .setOutputCount(3).build(); - - GridRecipe.make("aurora_block", EndBlocks.AURORA_CRYSTAL).setShape("##", "##") - .addMaterial('#', EndItems.CRYSTAL_SHARDS).build(); - GridRecipe.make("lotus_block", EndBlocks.END_LOTUS.log).setShape("##", "##") - .addMaterial('#', EndBlocks.END_LOTUS_STEM).build(); - GridRecipe.make("needlegrass_stick", Items.STICK).setList("#").setOutputCount(2) - .addMaterial('#', EndBlocks.NEEDLEGRASS).build(); - GridRecipe.make("shadow_berry_seeds", EndBlocks.SHADOW_BERRY).setList("#").setOutputCount(4) - .addMaterial('#', EndItems.SHADOW_BERRY_RAW).build(); - GridRecipe.make("purple_polypore_dye", Items.PURPLE_DYE).setList("#") - .addMaterial('#', EndBlocks.PURPLE_POLYPORE).build(); + .addMaterial('#', EndBlocks.AETERNIUM_BLOCK) + .setOutputCount(9) + .setList("#") + .build(); + + GridRecipe.make("blue_vine_seed_dye", Items.BLUE_DYE).setList("#").addMaterial('#', EndBlocks.BLUE_VINE_SEED).build(); + GridRecipe.make("creeping_moss_dye", Items.CYAN_DYE).setList("#").addMaterial('#', EndBlocks.CREEPING_MOSS).build(); + GridRecipe.make("umbrella_moss_dye", Items.YELLOW_DYE).setList("#").addMaterial('#', EndBlocks.UMBRELLA_MOSS).build(); + GridRecipe.make("umbrella_moss_tall_dye", Items.YELLOW_DYE).setOutputCount(2).setList("#").addMaterial('#', EndBlocks.UMBRELLA_MOSS_TALL).build(); + GridRecipe.make("shadow_plant_dye", Items.BLACK_DYE).setList("#").addMaterial('#', EndBlocks.SHADOW_PLANT).build(); + + GridRecipe.make("paper", Items.PAPER).setShape("###").addMaterial('#', EndItems.END_LILY_LEAF_DRIED).setOutputCount(3).build(); + + GridRecipe.make("aurora_block", EndBlocks.AURORA_CRYSTAL).setShape("##", "##").addMaterial('#', EndItems.CRYSTAL_SHARDS).build(); + GridRecipe.make("lotus_block", EndBlocks.END_LOTUS.log).setShape("##", "##").addMaterial('#', EndBlocks.END_LOTUS_STEM).build(); + GridRecipe.make("needlegrass_stick", Items.STICK).setList("#").setOutputCount(2).addMaterial('#', EndBlocks.NEEDLEGRASS).build(); + GridRecipe.make("shadow_berry_seeds", EndBlocks.SHADOW_BERRY).setList("#").setOutputCount(4).addMaterial('#', EndItems.SHADOW_BERRY_RAW).build(); + GridRecipe.make("purple_polypore_dye", Items.PURPLE_DYE).setList("#").addMaterial('#', EndBlocks.PURPLE_POLYPORE).build(); registerLantern("end_stone_lantern", EndBlocks.END_STONE_LANTERN, Blocks.END_STONE_BRICK_SLAB); registerLantern("andesite_lantern", EndBlocks.ANDESITE_LANTERN, Blocks.ANDESITE_SLAB); @@ -83,130 +88,136 @@ public class CraftingRecipes { registerLantern("quartz_lantern", EndBlocks.QUARTZ_LANTERN, Blocks.QUARTZ_SLAB); registerLantern("purpur_lantern", EndBlocks.PURPUR_LANTERN, Blocks.PURPUR_SLAB); registerLantern("blackstone_lantern", EndBlocks.BLACKSTONE_LANTERN, Blocks.BLACKSTONE_SLAB); - - GridRecipe.make("amber_gem", EndItems.AMBER_GEM).setShape("##", "##").addMaterial('#', EndItems.RAW_AMBER) - .build(); - GridRecipe.make("amber_block", EndBlocks.AMBER_BLOCK).setShape("##", "##").addMaterial('#', EndItems.AMBER_GEM) - .build(); - GridRecipe.make("amber_gem_block", EndItems.AMBER_GEM).setOutputCount(4).setList("#") - .addMaterial('#', EndBlocks.AMBER_BLOCK).build(); - GridRecipe.make("iron_bulb_lantern", EndBlocks.IRON_BULB_LANTERN).setShape("C", "I", "#") - .addMaterial('C', Items.CHAIN).addMaterial('I', Items.IRON_INGOT) - .addMaterial('#', EndItems.GLOWING_BULB).build(); - GridRecipe.make("twisted_moss_dye", Items.PINK_DYE).setList("#").addMaterial('#', EndBlocks.TWISTED_MOSS) - .build(); - GridRecipe.make("byshy_grass_dye", Items.MAGENTA_DYE).setList("#").addMaterial('#', EndBlocks.BUSHY_GRASS) - .build(); + + GridRecipe.make("amber_gem", EndItems.AMBER_GEM).setShape("##", "##").addMaterial('#', EndItems.RAW_AMBER).build(); + GridRecipe.make("amber_block", EndBlocks.AMBER_BLOCK).setShape("##", "##").addMaterial('#', EndItems.AMBER_GEM).build(); + GridRecipe.make("amber_gem_block", EndItems.AMBER_GEM).setOutputCount(4).setList("#").addMaterial('#', EndBlocks.AMBER_BLOCK).build(); + GridRecipe.make("iron_bulb_lantern", EndBlocks.IRON_BULB_LANTERN).setShape("C", "I", "#").addMaterial('C', Items.CHAIN).addMaterial('I', Items.IRON_INGOT).addMaterial('#', EndItems.GLOWING_BULB).build(); + GridRecipe.make("twisted_moss_dye", Items.PINK_DYE).setList("#").addMaterial('#', EndBlocks.TWISTED_MOSS).build(); + GridRecipe.make("byshy_grass_dye", Items.MAGENTA_DYE).setList("#").addMaterial('#', EndBlocks.BUSHY_GRASS).build(); GridRecipe.make("tail_moss_dye", Items.GRAY_DYE).setList("#").addMaterial('#', EndBlocks.TAIL_MOSS).build(); - GridRecipe.make("petal_block", EndBlocks.HYDRALUX_PETAL_BLOCK).setShape("##", "##") - .addMaterial('#', EndItems.HYDRALUX_PETAL).build(); - GridRecipe.make("petal_white_dye", Items.WHITE_DYE).setList("#").addMaterial('#', EndItems.HYDRALUX_PETAL) - .build(); - - GridRecipe.make("sweet_berry_jelly", EndItems.SWEET_BERRY_JELLY).setList("JWSB") - .addMaterial('J', EndItems.GELATINE) - .addMaterial('W', PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER)) - .addMaterial('S', Items.SUGAR).addMaterial('B', Items.SWEET_BERRIES).build(); - - GridRecipe.make("shadow_berry_jelly", EndItems.SHADOW_BERRY_JELLY).setList("JWSB") - .addMaterial('J', EndItems.GELATINE) - .addMaterial('W', PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER)) - .addMaterial('S', Items.SUGAR).addMaterial('B', EndItems.SHADOW_BERRY_COOKED).build(); - - GridRecipe.make("sulphur_gunpowder", Items.GUNPOWDER).setList("SCB") - .addMaterial('S', EndItems.CRYSTALLINE_SULPHUR).addMaterial('C', Items.COAL, Items.CHARCOAL) - .addMaterial('B', Items.BONE_MEAL).build(); - - GridRecipe.make("dense_emerald_ice", EndBlocks.DENSE_EMERALD_ICE).setShape("##", "##") - .addMaterial('#', EndBlocks.EMERALD_ICE).build(); - GridRecipe.make("ancient_emerald_ice", EndBlocks.ANCIENT_EMERALD_ICE).setShape("###", "###", "###") - .addMaterial('#', EndBlocks.DENSE_EMERALD_ICE).build(); - - GridRecipe.make("charnia_cyan_dye", Items.CYAN_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_CYAN) - .build(); - GridRecipe.make("charnia_green_dye", Items.GREEN_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_GREEN) - .build(); - GridRecipe.make("charnia_light_blue_dye", Items.LIGHT_BLUE_DYE).setList("#") - .addMaterial('#', EndBlocks.CHARNIA_LIGHT_BLUE).build(); - GridRecipe.make("charnia_orange_dye", Items.ORANGE_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_ORANGE) - .build(); - GridRecipe.make("charnia_purple_dye", Items.PURPLE_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_PURPLE) - .build(); + GridRecipe.make("petal_block", EndBlocks.HYDRALUX_PETAL_BLOCK).setShape("##", "##").addMaterial('#', EndItems.HYDRALUX_PETAL).build(); + GridRecipe.make("petal_white_dye", Items.WHITE_DYE).setList("#").addMaterial('#', EndItems.HYDRALUX_PETAL).build(); + + GridRecipe.make("sweet_berry_jelly", EndItems.SWEET_BERRY_JELLY) + .setList("JWSB") + .addMaterial('J', EndItems.GELATINE) + .addMaterial('W', PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)) + .addMaterial('S', Items.SUGAR).addMaterial('B', Items.SWEET_BERRIES) + .build(); + + GridRecipe.make("shadow_berry_jelly", EndItems.SHADOW_BERRY_JELLY) + .setList("JWSB") + .addMaterial('J', EndItems.GELATINE) + .addMaterial('W', PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)) + .addMaterial('S', Items.SUGAR) + .addMaterial('B', EndItems.SHADOW_BERRY_COOKED) + .build(); + + GridRecipe.make("sulphur_gunpowder", Items.GUNPOWDER).setList("SCB").addMaterial('S', EndItems.CRYSTALLINE_SULPHUR).addMaterial('C', Items.COAL, Items.CHARCOAL).addMaterial('B', Items.BONE_MEAL).build(); + + GridRecipe.make("dense_emerald_ice", EndBlocks.DENSE_EMERALD_ICE).setShape("##", "##").addMaterial('#', EndBlocks.EMERALD_ICE).build(); + GridRecipe.make("ancient_emerald_ice", EndBlocks.ANCIENT_EMERALD_ICE).setShape("###", "###", "###").addMaterial('#', EndBlocks.DENSE_EMERALD_ICE).build(); + + GridRecipe.make("charnia_cyan_dye", Items.CYAN_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_CYAN).build(); + GridRecipe.make("charnia_green_dye", Items.GREEN_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_GREEN).build(); + GridRecipe.make("charnia_light_blue_dye", Items.LIGHT_BLUE_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_LIGHT_BLUE).build(); + GridRecipe.make("charnia_orange_dye", Items.ORANGE_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_ORANGE).build(); + GridRecipe.make("charnia_purple_dye", Items.PURPLE_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_PURPLE).build(); GridRecipe.make("charnia_red_dye", Items.RED_DYE).setList("#").addMaterial('#', EndBlocks.CHARNIA_RED).build(); - - GridRecipe.make("respawn_obelisk", EndBlocks.RESPAWN_OBELISK).setShape("CSC", "CSC", "AAA") - .addMaterial('C', EndBlocks.AURORA_CRYSTAL).addMaterial('S', EndItems.ETERNAL_CRYSTAL) - .addMaterial('A', EndBlocks.AMBER_BLOCK).build(); - - GridRecipe.make("hopper", Blocks.HOPPER).setShape("I I", "ICI", " I ").addMaterial('I', Items.IRON_INGOT) - .addMaterial('C', EndTags.ITEM_CHEST).build(); - - GridRecipe.make("shulker_box", Blocks.SHULKER_BOX).setShape("S", "C", "S").addMaterial('S', Items.SHULKER_SHELL) - .addMaterial('C', EndTags.ITEM_CHEST).build(); - - GridRecipe.make("twisted_umbrella_moss_dye", Items.PURPLE_DYE).setList("#") - .addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS).build(); - GridRecipe.make("twisted_umbrella_moss_dye_tall", Items.PURPLE_DYE).setOutputCount(2).setList("#") - .addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS_TALL).build(); - - GridRecipe.make("leather_to_stripes", EndItems.LEATHER_STRIPE).setList("L").addMaterial('L', Items.LEATHER) - .setOutputCount(3).build(); - GridRecipe.make("stripes_to_leather", Items.LEATHER).setList("SSS").addMaterial('S', EndItems.LEATHER_STRIPE) - .build(); - GridRecipe.make("leather_wrapped_stick", EndItems.LEATHER_WRAPPED_STICK).setList("SL") - .addMaterial('S', Items.STICK).addMaterial('L', EndItems.LEATHER_STRIPE).build(); - - GridRecipe.make("fiber_string", Items.STRING).setOutputCount(6).setShape("#", "#", "#") - .addMaterial('#', EndItems.SILK_FIBER).build(); - - GridRecipe.make("ender_eye_amber", Items.ENDER_EYE).setShape("SAS", "APA", "SAS") - .addMaterial('S', EndItems.CRYSTAL_SHARDS).addMaterial('A', EndItems.AMBER_GEM) - .addMaterial('P', Items.ENDER_PEARL).build(); - - GridRecipe.make("iron_chandelier", EndBlocks.IRON_CHANDELIER).setShape("I#I", " # ") - .addMaterial('#', Items.IRON_INGOT).addMaterial('I', EndItems.LUMECORN_ROD) - .setGroup("end_metal_chandelier").build(); - GridRecipe.make("gold_chandelier", EndBlocks.GOLD_CHANDELIER).setShape("I#I", " # ") - .addMaterial('#', Items.GOLD_INGOT).addMaterial('I', EndItems.LUMECORN_ROD) - .setGroup("end_metal_chandelier").build(); - - GridRecipe.make("missing_tile", EndBlocks.MISSING_TILE).setOutputCount(4).setShape("#P", "P#") - .addMaterial('#', EndBlocks.VIOLECITE.stone, EndBlocks.VIOLECITE.bricks, EndBlocks.VIOLECITE.tiles) - .addMaterial('P', Blocks.PURPUR_BLOCK).build(); + + GridRecipe.make("respawn_obelisk", EndBlocks.RESPAWN_OBELISK) + .setShape("CSC", "CSC", "AAA") + .addMaterial('C', EndBlocks.AURORA_CRYSTAL) + .addMaterial('S', EndItems.ETERNAL_CRYSTAL) + .addMaterial('A', EndBlocks.AMBER_BLOCK) + .build(); + + GridRecipe.make("hopper", Blocks.HOPPER) + .setShape("I I", "ICI", " I ") + .addMaterial('I', Items.IRON_INGOT) + .addMaterial('C', EndTags.ITEM_CHEST) + .build(); + + GridRecipe.make("shulker_box", Blocks.SHULKER_BOX) + .setShape("S", "C", "S") + .addMaterial('S', Items.SHULKER_SHELL) + .addMaterial('C', EndTags.ITEM_CHEST) + .build(); + + GridRecipe.make("twisted_umbrella_moss_dye", Items.PURPLE_DYE).setList("#").addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS).build(); + GridRecipe.make("twisted_umbrella_moss_dye_tall", Items.PURPLE_DYE).setOutputCount(2).setList("#").addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS_TALL).build(); + + GridRecipe.make("leather_to_stripes", EndItems.LEATHER_STRIPE) + .setList("L") + .addMaterial('L', Items.LEATHER) + .setOutputCount(3) + .build(); + GridRecipe.make("stripes_to_leather", Items.LEATHER) + .setList("SSS") + .addMaterial('S', EndItems.LEATHER_STRIPE) + .build(); + GridRecipe.make("leather_wrapped_stick", EndItems.LEATHER_WRAPPED_STICK) + .setList("SL") + .addMaterial('S', Items.STICK) + .addMaterial('L', EndItems.LEATHER_STRIPE) + .build(); + + GridRecipe.make("fiber_string", Items.STRING).setOutputCount(6).setShape("#", "#", "#").addMaterial('#', EndItems.SILK_FIBER).build(); + + GridRecipe.make("ender_eye_amber", Items.ENDER_EYE) + .setShape("SAS", "APA", "SAS") + .addMaterial('S', EndItems.CRYSTAL_SHARDS) + .addMaterial('A', EndItems.AMBER_GEM) + .addMaterial('P', Items.ENDER_PEARL) + .build(); + + GridRecipe.make("iron_chandelier", EndBlocks.IRON_CHANDELIER).setShape("I#I", " # ").addMaterial('#', Items.IRON_INGOT).addMaterial('I', EndItems.LUMECORN_ROD).setGroup("end_metal_chandelier").build(); + GridRecipe.make("gold_chandelier", EndBlocks.GOLD_CHANDELIER).setShape("I#I", " # ").addMaterial('#', Items.GOLD_INGOT).addMaterial('I', EndItems.LUMECORN_ROD).setGroup("end_metal_chandelier").build(); + + GridRecipe.make("missing_tile", EndBlocks.MISSING_TILE) + .setOutputCount(4) + .setShape("#P", "P#") + .addMaterial('#', EndBlocks.VIOLECITE.stone, EndBlocks.VIOLECITE.bricks, EndBlocks.VIOLECITE.tiles) + .addMaterial('P', Blocks.PURPUR_BLOCK) + .build(); registerHammer("iron", Items.IRON_INGOT, EndItems.IRON_HAMMER); registerHammer("golden", Items.GOLD_INGOT, EndItems.GOLDEN_HAMMER); registerHammer("diamond", Items.DIAMOND, EndItems.DIAMOND_HAMMER); - GridRecipe.make("charcoal_block", EndBlocks.CHARCOAL_BLOCK).setShape("###", "###", "###") - .addMaterial('#', Items.CHARCOAL).build(); - GridRecipe.make("end_stone_furnace", EndBlocks.END_STONE_FURNACE).setShape("###", "# #", "###") - .addMaterial('#', Blocks.END_STONE).build(); - GridRecipe.make("filalux_lantern", EndBlocks.FILALUX_LANTERN).setShape("###", "###", "###") - .addMaterial('#', EndBlocks.FILALUX).build(); - - GridRecipe.make("silk_moth_hive", EndBlocks.SILK_MOTH_HIVE).setShape("#L#", "LML", "#L#") - .addMaterial('#', EndBlocks.TENANEA.planks).addMaterial('L', EndBlocks.TENANEA_LEAVES) - .addMaterial('M', EndItems.SILK_MOTH_MATRIX).build(); - GridRecipe.make("cave_pumpkin_pie", EndItems.CAVE_PUMPKIN_PIE).setShape(" B ", "BPB", " B ") - .addMaterial('P', EndBlocks.CAVE_PUMPKIN) - .addMaterial('B', EndItems.BLOSSOM_BERRY, EndItems.SHADOW_BERRY_RAW).build(); - GridRecipe.make("cave_pumpkin_seeds", EndBlocks.CAVE_PUMPKIN_SEED).setOutputCount(4).setList("#") - .addMaterial('#', EndBlocks.CAVE_PUMPKIN).build(); + GridRecipe.make("charcoal_block", EndBlocks.CHARCOAL_BLOCK).setShape("###", "###", "###").addMaterial('#', Items.CHARCOAL).build(); + GridRecipe.make("end_stone_furnace", EndBlocks.END_STONE_FURNACE).setShape("###", "# #", "###").addMaterial('#', Blocks.END_STONE).build(); + GridRecipe.make("filalux_lantern", EndBlocks.FILALUX_LANTERN).setShape("###", "###", "###").addMaterial('#', EndBlocks.FILALUX).build(); + + GridRecipe.make("silk_moth_hive", EndBlocks.SILK_MOTH_HIVE).setShape("#L#", "LML", "#L#").addMaterial('#', EndBlocks.TENANEA.planks).addMaterial('L', EndBlocks.TENANEA_LEAVES).addMaterial('M', EndItems.SILK_MOTH_MATRIX).build(); + GridRecipe.make("cave_pumpkin_pie", EndItems.CAVE_PUMPKIN_PIE).setShape(" B ", "BPB", " B ").addMaterial('P', EndBlocks.CAVE_PUMPKIN).addMaterial('B', EndItems.BLOSSOM_BERRY, EndItems.SHADOW_BERRY_RAW).build(); + GridRecipe.make("cave_pumpkin_seeds", EndBlocks.CAVE_PUMPKIN_SEED).setOutputCount(4).setList("#").addMaterial('#', EndBlocks.CAVE_PUMPKIN).build(); } - + private static void registerLantern(String name, Block lantern, Block slab) { - GridRecipe.make(name, lantern).setShape("S", "#", "S").addMaterial('#', EndItems.CRYSTAL_SHARDS) - .addMaterial('S', slab).setGroup("end_stone_lanterns").build(); + GridRecipe.make(name, lantern) + .setShape("S", "#", "S") + .addMaterial('#', EndItems.CRYSTAL_SHARDS) + .addMaterial('S', slab) + .setGroup("end_stone_lanterns") + .build(); } - + public static void registerPedestal(String name, Block pedestal, Block slab, Block pillar) { - GridRecipe.make(name, pedestal).setShape("S", "#", "S").addMaterial('S', slab).addMaterial('#', pillar) - .setOutputCount(2).build(); + GridRecipe.make(name, pedestal) + .setShape("S", "#", "S") + .addMaterial('S', slab) + .addMaterial('#', pillar) + .setOutputCount(2) + .build(); } private static void registerHammer(String name, Item material, Item result) { - GridRecipe.make(name + "_hammer", result).setShape("I I", "I#I", " # ").addMaterial('I', material) - .addMaterial('#', Items.STICK).build(); + GridRecipe.make(name + "_hammer", result) + .setShape("I I", "I#I", " # ") + .addMaterial('I', material) + .addMaterial('#', Items.STICK) + .build(); } } diff --git a/src/main/java/ru/betterend/recipe/EndRecipeManager.java b/src/main/java/ru/betterend/recipe/EndRecipeManager.java index 4a3eb2ca..eef6a87e 100644 --- a/src/main/java/ru/betterend/recipe/EndRecipeManager.java +++ b/src/main/java/ru/betterend/recipe/EndRecipeManager.java @@ -2,14 +2,12 @@ package ru.betterend.recipe; import java.util.Map; import java.util.Map.Entry; - -import com.google.common.collect.Maps; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import com.google.common.collect.Maps; import ru.betterend.BetterEnd; public class EndRecipeManager { @@ -23,7 +21,7 @@ public class EndRecipeManager { } list.put(recipe.getId(), recipe); } - + @SuppressWarnings("unchecked") public static > T getRecipe(RecipeType type, ResourceLocation id) { if (RECIPES.containsKey(type)) { @@ -32,8 +30,7 @@ public class EndRecipeManager { return null; } - public static Map, Map>> getMap( - Map, Map>> recipes) { + public static Map, Map>> getMap(Map, Map>> recipes) { Map, Map>> result = Maps.newHashMap(); for (RecipeType type : recipes.keySet()) { @@ -71,6 +68,6 @@ public class EndRecipeManager { public String toString() { return type; } - }); + }); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/recipe/FurnaceRecipes.java b/src/main/java/ru/betterend/recipe/FurnaceRecipes.java index de83076f..50ecab0d 100644 --- a/src/main/java/ru/betterend/recipe/FurnaceRecipes.java +++ b/src/main/java/ru/betterend/recipe/FurnaceRecipes.java @@ -1,7 +1,7 @@ package ru.betterend.recipe; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; import ru.betterend.recipe.builders.FurnaceRecipe; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; @@ -14,8 +14,7 @@ public class FurnaceRecipes { FurnaceRecipe.make("end_fish", EndItems.END_FISH_RAW, EndItems.END_FISH_COOKED).buildFoodlike(); FurnaceRecipe.make("slime_ball", EndBlocks.JELLYSHROOM_CAP_PURPLE, Items.SLIME_BALL).build(); FurnaceRecipe.make("menger_sponge", EndBlocks.MENGER_SPONGE_WET, EndBlocks.MENGER_SPONGE).build(); - FurnaceRecipe.make("chorus_mushroom", EndItems.CHORUS_MUSHROOM_RAW, EndItems.CHORUS_MUSHROOM_COOKED) - .buildFoodlike(); + FurnaceRecipe.make("chorus_mushroom", EndItems.CHORUS_MUSHROOM_RAW, EndItems.CHORUS_MUSHROOM_COOKED).buildFoodlike(); FurnaceRecipe.make("bolux_mushroom", EndBlocks.BOLUX_MUSHROOM, EndItems.BOLUX_MUSHROOM_COOKED).buildFoodlike(); } } diff --git a/src/main/java/ru/betterend/recipe/InfusionRecipes.java b/src/main/java/ru/betterend/recipe/InfusionRecipes.java index 6aba6304..64569b97 100644 --- a/src/main/java/ru/betterend/recipe/InfusionRecipes.java +++ b/src/main/java/ru/betterend/recipe/InfusionRecipes.java @@ -1,268 +1,591 @@ package ru.betterend.recipe; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.enchantment.Enchantment; -import net.minecraft.world.item.enchantment.EnchantmentLevelEntry; -import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.item.EnchantedBookItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentInstance; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.block.Blocks; import ru.betterend.recipe.builders.InfusionRecipe; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public class InfusionRecipes { public static void register() { - InfusionRecipe.Builder.create("runed_flavolite").setInput(EndBlocks.FLAVOLITE.polished) - .setOutput(EndBlocks.FLAVOLITE_RUNED).addCatalyst(0, EndItems.CRYSTAL_SHARDS) - .addCatalyst(2, EndItems.CRYSTAL_SHARDS).addCatalyst(4, EndItems.CRYSTAL_SHARDS) - .addCatalyst(6, EndItems.CRYSTAL_SHARDS).setTime(100).build(); + InfusionRecipe.Builder.create("runed_flavolite") + .setInput(EndBlocks.FLAVOLITE.polished) + .setOutput(EndBlocks.FLAVOLITE_RUNED) + .addCatalyst(0, EndItems.CRYSTAL_SHARDS) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(4, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .setTime(100) + .build(); + + InfusionRecipe.Builder.create("eternal_crystal") + .setInput(Items.END_CRYSTAL) + .setOutput(EndItems.ETERNAL_CRYSTAL) + .addCatalyst(0, EndItems.CRYSTAL_SHARDS) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(4, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .addCatalyst(1, EndItems.ENDER_SHARD) + .addCatalyst(3, EndItems.ENDER_SHARD) + .addCatalyst(5, EndItems.ENDER_SHARD) + .addCatalyst(7, EndItems.ENDER_SHARD) + .setTime(250) + .build(); + + InfusionRecipe.Builder.create("crystalite_helmet") + .setInput(EndBlocks.TERMINITE.helmet) + .setOutput(EndItems.CRYSTALITE_HELMET) + .addCatalyst(0, EndItems.AMBER_GEM) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .setTime(150) + .build(); + InfusionRecipe.Builder.create("crystalite_chestplate") + .setInput(EndBlocks.TERMINITE.chestplate) + .setOutput(EndItems.CRYSTALITE_CHESTPLATE) + .addCatalyst(0, EndItems.AMBER_GEM) + .addCatalyst(1, EndItems.CRYSTAL_SHARDS) + .addCatalyst(3, EndItems.CRYSTAL_SHARDS) + .addCatalyst(5, EndItems.CRYSTAL_SHARDS) + .addCatalyst(7, EndItems.CRYSTAL_SHARDS) + .setTime(300) + .build(); + InfusionRecipe.Builder.create("crystalite_leggings") + .setInput(EndBlocks.TERMINITE.leggings) + .setOutput(EndItems.CRYSTALITE_LEGGINGS) + .addCatalyst(0, EndItems.AMBER_GEM) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(4, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .setTime(225) + .build(); + InfusionRecipe.Builder.create("crystalite_boots") + .setInput(EndBlocks.TERMINITE.boots) + .setOutput(EndItems.CRYSTALITE_BOOTS) + .addCatalyst(0, EndItems.AMBER_GEM) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .setTime(150) + .build(); + + InfusionRecipe.Builder.create("enchanted_petal") + .setInput(EndItems.HYDRALUX_PETAL) + .setOutput(EndItems.ENCHANTED_PETAL) + .addCatalyst(0, EndItems.CRYSTAL_SHARDS) + .addCatalyst(2, EndItems.CRYSTAL_SHARDS) + .addCatalyst(4, EndItems.CRYSTAL_SHARDS) + .addCatalyst(6, EndItems.CRYSTAL_SHARDS) + .setTime(75) + .build(); - InfusionRecipe.Builder.create("eternal_crystal").setInput(Items.END_CRYSTAL).setOutput(EndItems.ETERNAL_CRYSTAL) - .addCatalyst(0, EndItems.CRYSTAL_SHARDS).addCatalyst(2, EndItems.CRYSTAL_SHARDS) - .addCatalyst(4, EndItems.CRYSTAL_SHARDS).addCatalyst(6, EndItems.CRYSTAL_SHARDS) - .addCatalyst(1, EndItems.ENDER_SHARD).addCatalyst(3, EndItems.ENDER_SHARD) - .addCatalyst(5, EndItems.ENDER_SHARD).addCatalyst(7, EndItems.ENDER_SHARD).setTime(250).build(); - - InfusionRecipe.Builder.create("crystalite_helmet").setInput(EndBlocks.TERMINITE.helmet) - .setOutput(EndItems.CRYSTALITE_HELMET).addCatalyst(0, EndItems.AMBER_GEM) - .addCatalyst(2, EndItems.CRYSTAL_SHARDS).addCatalyst(6, EndItems.CRYSTAL_SHARDS).setTime(150).build(); - InfusionRecipe.Builder.create("crystalite_chestplate").setInput(EndBlocks.TERMINITE.chestplate) - .setOutput(EndItems.CRYSTALITE_CHESTPLATE).addCatalyst(0, EndItems.AMBER_GEM) - .addCatalyst(1, EndItems.CRYSTAL_SHARDS).addCatalyst(3, EndItems.CRYSTAL_SHARDS) - .addCatalyst(5, EndItems.CRYSTAL_SHARDS).addCatalyst(7, EndItems.CRYSTAL_SHARDS).setTime(300).build(); - InfusionRecipe.Builder.create("crystalite_leggings").setInput(EndBlocks.TERMINITE.leggings) - .setOutput(EndItems.CRYSTALITE_LEGGINGS).addCatalyst(0, EndItems.AMBER_GEM) - .addCatalyst(2, EndItems.CRYSTAL_SHARDS).addCatalyst(4, EndItems.CRYSTAL_SHARDS) - .addCatalyst(6, EndItems.CRYSTAL_SHARDS).setTime(225).build(); - InfusionRecipe.Builder.create("crystalite_boots").setInput(EndBlocks.TERMINITE.boots) - .setOutput(EndItems.CRYSTALITE_BOOTS).addCatalyst(0, EndItems.AMBER_GEM) - .addCatalyst(2, EndItems.CRYSTAL_SHARDS).addCatalyst(6, EndItems.CRYSTAL_SHARDS).setTime(150).build(); - - InfusionRecipe.Builder.create("enchanted_petal").setInput(EndItems.HYDRALUX_PETAL) - .setOutput(EndItems.ENCHANTED_PETAL).addCatalyst(0, EndItems.CRYSTAL_SHARDS) - .addCatalyst(2, EndItems.CRYSTAL_SHARDS).addCatalyst(4, EndItems.CRYSTAL_SHARDS) - .addCatalyst(6, EndItems.CRYSTAL_SHARDS).setTime(75).build(); - - InfusionRecipe.Builder.create("protection_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.PROTECTION, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(4, Items.TURTLE_HELMET).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("fire_protection_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.FIRE_PROTECTION, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Items.BLAZE_ROD) - .addCatalyst(4, Items.BLAZE_ROD).addCatalyst(6, Items.BLAZE_ROD).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("feather_falling_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.FEATHER_FALLING, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Items.FEATHER).addCatalyst(4, Items.FEATHER) - .addCatalyst(6, Items.FEATHER).addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("blast_protection_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.BLAST_PROTECTION, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Blocks.OBSIDIAN) - .addCatalyst(4, Blocks.OBSIDIAN).addCatalyst(6, Blocks.OBSIDIAN).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("projectile_protection_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.PROJECTILE_PROTECTION, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Items.SCUTE).addCatalyst(4, Items.SHIELD) - .addCatalyst(6, Items.SCUTE).addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("respiration_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.RESPIRATION, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.NAUTILUS_SHELL).addCatalyst(4, Items.NAUTILUS_SHELL) - .addCatalyst(6, Items.NAUTILUS_SHELL).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("aqua_affinity_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.AQUA_AFFINITY, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.PRISMARINE_CRYSTALS).addCatalyst(4, Items.PRISMARINE_CRYSTALS) - .addCatalyst(6, Items.PRISMARINE_CRYSTALS).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("thorns_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.THORNS, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Blocks.CACTUS).addCatalyst(4, Blocks.CACTUS).addCatalyst(6, Blocks.CACTUS) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("depth_strider_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.DEPTH_STRIDER, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Blocks.LILY_PAD).addCatalyst(4, EndBlocks.END_LILY_SEED).addCatalyst(6, Blocks.LILY_PAD) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("frost_walker_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.FROST_WALKER, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(4, EndBlocks.ANCIENT_EMERALD_ICE).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("soul_speed_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.SOUL_SPEED, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Blocks.SOUL_SAND, Blocks.SOUL_SOIL).addCatalyst(4, Blocks.SOUL_SAND, Blocks.SOUL_SOIL) - .addCatalyst(6, Blocks.SOUL_SAND, Blocks.SOUL_SOIL).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("sharpness_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.SHARPNESS, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(4, Items.NETHERITE_SCRAP).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("smite_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.SMITE, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Blocks.SUNFLOWER).addCatalyst(4, Items.GOLD_INGOT).addCatalyst(6, Blocks.SUNFLOWER) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("bane_of_arthropods_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.BANE_OF_ARTHROPODS, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Items.FERMENTED_SPIDER_EYE) - .addCatalyst(4, Items.IRON_INGOT).addCatalyst(6, Items.FERMENTED_SPIDER_EYE) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("knockback_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.KNOCKBACK, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.REDSTONE).addCatalyst(4, Blocks.PISTON).addCatalyst(6, Items.REDSTONE) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("fire_aspect_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.FIRE_ASPECT, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.BLAZE_POWDER).addCatalyst(4, Items.MAGMA_CREAM).addCatalyst(6, Items.BLAZE_POWDER) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("looting_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.LOOTING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.EMERALD).addCatalyst(4, Items.GOLD_INGOT).addCatalyst(6, Items.EMERALD) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("sweeping_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.SWEEPING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.GOLDEN_SWORD).addCatalyst(4, Items.IRON_SWORD).addCatalyst(6, Items.GOLDEN_SWORD) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("efficiency_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.EFFICIENCY, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, EndItems.AMBER_GEM).addCatalyst(4, EndItems.AMBER_GEM) - .addCatalyst(6, EndItems.AMBER_GEM).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("silk_touch_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.SILK_TOUCH, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Blocks.COBWEB).addCatalyst(4, EndItems.ETERNAL_CRYSTAL).addCatalyst(6, Blocks.COBWEB) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(375).build(); - InfusionRecipe.Builder.create("unbreaking_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.UNBREAKING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.DIAMOND).addCatalyst(4, Items.DIAMOND).addCatalyst(6, Items.DIAMOND) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("fortune_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.BLOCK_FORTUNE, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.EMERALD).addCatalyst(4, Items.RABBIT_FOOT).addCatalyst(6, Items.EMERALD) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("power_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.POWER, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, EndItems.AMBER_GEM).addCatalyst(4, Items.DIAMOND_SWORD) - .addCatalyst(6, EndItems.AMBER_GEM).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("punch_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.PUNCH, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.POPPED_CHORUS_FRUIT).addCatalyst(4, Items.SPECTRAL_ARROW) - .addCatalyst(6, Items.POPPED_CHORUS_FRUIT).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("flame_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.FLAME, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.BLAZE_POWDER).addCatalyst(4, Items.SPECTRAL_ARROW) - .addCatalyst(6, Items.BLAZE_POWDER).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("infinity_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.INFINITY, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.SPECTRAL_ARROW).addCatalyst(4, EndItems.ETERNAL_CRYSTAL) - .addCatalyst(6, Items.SPECTRAL_ARROW).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(375).build(); - InfusionRecipe.Builder.create("luck_of_sea_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.LUCK_OF_THE_SEA, 1)) - .addCatalyst(0, EndItems.ENCHANTED_PETAL).addCatalyst(2, Items.EMERALD) - .addCatalyst(4, Items.FISHING_ROD).addCatalyst(6, Items.EMERALD).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("lure_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.LURE, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.GOLD_NUGGET).addCatalyst(4, Items.FISHING_ROD).addCatalyst(6, Items.GOLD_NUGGET) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("loyalty_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.LOYALTY, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.ENDER_EYE).addCatalyst(4, Items.HEART_OF_THE_SEA).addCatalyst(6, Items.ENDER_EYE) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(375).build(); - InfusionRecipe.Builder.create("impaling_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.IMPALING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.PRISMARINE_SHARD).addCatalyst(4, Items.IRON_SWORD) - .addCatalyst(6, Items.PRISMARINE_SHARD).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("riptide_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.RIPTIDE, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.LEAD).addCatalyst(4, Items.HEART_OF_THE_SEA).addCatalyst(6, Items.LEAD) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(375).build(); - InfusionRecipe.Builder.create("channeling_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.CHANNELING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.CHAIN).addCatalyst(4, Items.HEART_OF_THE_SEA).addCatalyst(6, Items.CHAIN) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(375).build(); - InfusionRecipe.Builder.create("multishot_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.MULTISHOT, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.ARROW).addCatalyst(4, Items.SPECTRAL_ARROW).addCatalyst(6, Items.ARROW) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("quick_charge_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.QUICK_CHARGE, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.QUARTZ).addCatalyst(4, Items.GLOWSTONE_DUST).addCatalyst(6, Items.QUARTZ) - .addCatalyst(1, Items.LAPIS_LAZULI).addCatalyst(3, Items.LAPIS_LAZULI) - .addCatalyst(5, Items.LAPIS_LAZULI).addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment") - .setTime(300).build(); - InfusionRecipe.Builder.create("piercing_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.PIERCING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.GLOWSTONE_DUST).addCatalyst(4, Items.SPECTRAL_ARROW) - .addCatalyst(6, Items.GLOWSTONE_DUST).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(300).build(); - InfusionRecipe.Builder.create("mending_book").setInput(Items.BOOK) - .setOutput(createEnchantedBook(Enchantments.MENDING, 1)).addCatalyst(0, EndItems.ENCHANTED_PETAL) - .addCatalyst(2, Items.EXPERIENCE_BOTTLE).addCatalyst(4, Blocks.ANVIL) - .addCatalyst(6, Items.EXPERIENCE_BOTTLE).addCatalyst(1, Items.LAPIS_LAZULI) - .addCatalyst(3, Items.LAPIS_LAZULI).addCatalyst(5, Items.LAPIS_LAZULI) - .addCatalyst(7, Items.LAPIS_LAZULI).setGroup("enchantment").setTime(375).build(); + InfusionRecipe.Builder.create("protection_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.ALL_DAMAGE_PROTECTION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(4, Items.TURTLE_HELMET) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("fire_protection_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FIRE_PROTECTION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.BLAZE_ROD) + .addCatalyst(4, Items.BLAZE_ROD) + .addCatalyst(6, Items.BLAZE_ROD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("feather_falling_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FALL_PROTECTION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.FEATHER) + .addCatalyst(4, Items.FEATHER) + .addCatalyst(6, Items.FEATHER) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("blast_protection_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.BLAST_PROTECTION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.OBSIDIAN) + .addCatalyst(4, Blocks.OBSIDIAN) + .addCatalyst(6, Blocks.OBSIDIAN) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("projectile_protection_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.PROJECTILE_PROTECTION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.SCUTE) + .addCatalyst(4, Items.SHIELD) + .addCatalyst(6, Items.SCUTE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("respiration_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.RESPIRATION, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.NAUTILUS_SHELL) + .addCatalyst(4, Items.NAUTILUS_SHELL) + .addCatalyst(6, Items.NAUTILUS_SHELL) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("aqua_affinity_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.AQUA_AFFINITY, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.PRISMARINE_CRYSTALS) + .addCatalyst(4, Items.PRISMARINE_CRYSTALS) + .addCatalyst(6, Items.PRISMARINE_CRYSTALS) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("thorns_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.THORNS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.CACTUS) + .addCatalyst(4, Blocks.CACTUS) + .addCatalyst(6, Blocks.CACTUS) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("depth_strider_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.DEPTH_STRIDER, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.LILY_PAD) + .addCatalyst(4, EndBlocks.END_LILY_SEED) + .addCatalyst(6, Blocks.LILY_PAD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("frost_walker_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FROST_WALKER, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(4, EndBlocks.ANCIENT_EMERALD_ICE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("soul_speed_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.SOUL_SPEED, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.SOUL_SAND, Blocks.SOUL_SOIL) + .addCatalyst(4, Blocks.SOUL_SAND, Blocks.SOUL_SOIL) + .addCatalyst(6, Blocks.SOUL_SAND, Blocks.SOUL_SOIL) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("sharpness_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.SHARPNESS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(4, Items.NETHERITE_SCRAP) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("smite_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.SMITE, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.SUNFLOWER) + .addCatalyst(4, Items.GOLD_INGOT) + .addCatalyst(6, Blocks.SUNFLOWER) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("bane_of_arthropods_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.BANE_OF_ARTHROPODS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.FERMENTED_SPIDER_EYE) + .addCatalyst(4, Items.IRON_INGOT) + .addCatalyst(6, Items.FERMENTED_SPIDER_EYE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("knockback_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.KNOCKBACK, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.REDSTONE) + .addCatalyst(4, Blocks.PISTON) + .addCatalyst(6, Items.REDSTONE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("fire_aspect_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FIRE_ASPECT, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.BLAZE_POWDER) + .addCatalyst(4, Items.MAGMA_CREAM) + .addCatalyst(6, Items.BLAZE_POWDER) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("looting_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.MOB_LOOTING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.EMERALD) + .addCatalyst(4, Items.GOLD_INGOT) + .addCatalyst(6, Items.EMERALD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("sweeping_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.SWEEPING_EDGE, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.GOLDEN_SWORD) + .addCatalyst(4, Items.IRON_SWORD) + .addCatalyst(6, Items.GOLDEN_SWORD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("efficiency_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.BLOCK_EFFICIENCY, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, EndItems.AMBER_GEM) + .addCatalyst(4, EndItems.AMBER_GEM) + .addCatalyst(6, EndItems.AMBER_GEM) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("silk_touch_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.SILK_TOUCH, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Blocks.COBWEB) + .addCatalyst(4, EndItems.ETERNAL_CRYSTAL) + .addCatalyst(6, Blocks.COBWEB) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); + InfusionRecipe.Builder.create("unbreaking_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.UNBREAKING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.DIAMOND) + .addCatalyst(4, Items.DIAMOND) + .addCatalyst(6, Items.DIAMOND) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("fortune_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.BLOCK_FORTUNE, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.EMERALD) + .addCatalyst(4, Items.RABBIT_FOOT) + .addCatalyst(6, Items.EMERALD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("power_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.POWER_ARROWS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, EndItems.AMBER_GEM) + .addCatalyst(4, Items.DIAMOND_SWORD) + .addCatalyst(6, EndItems.AMBER_GEM) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("punch_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.PUNCH_ARROWS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.POPPED_CHORUS_FRUIT) + .addCatalyst(4, Items.SPECTRAL_ARROW) + .addCatalyst(6, Items.POPPED_CHORUS_FRUIT) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("flame_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FLAMING_ARROWS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.BLAZE_POWDER) + .addCatalyst(4, Items.SPECTRAL_ARROW) + .addCatalyst(6, Items.BLAZE_POWDER) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("infinity_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.INFINITY_ARROWS, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.SPECTRAL_ARROW) + .addCatalyst(4, EndItems.ETERNAL_CRYSTAL) + .addCatalyst(6, Items.SPECTRAL_ARROW) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); + InfusionRecipe.Builder.create("luck_of_sea_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FISHING_LUCK, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.EMERALD) + .addCatalyst(4, Items.FISHING_ROD) + .addCatalyst(6, Items.EMERALD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("lure_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.FISHING_SPEED, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.GOLD_NUGGET) + .addCatalyst(4, Items.FISHING_ROD) + .addCatalyst(6, Items.GOLD_NUGGET) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("loyalty_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.LOYALTY, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.ENDER_EYE) + .addCatalyst(4, Items.HEART_OF_THE_SEA) + .addCatalyst(6, Items.ENDER_EYE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); + InfusionRecipe.Builder.create("impaling_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.IMPALING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.PRISMARINE_SHARD) + .addCatalyst(4, Items.IRON_SWORD) + .addCatalyst(6, Items.PRISMARINE_SHARD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("riptide_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.RIPTIDE, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.LEAD) + .addCatalyst(4, Items.HEART_OF_THE_SEA) + .addCatalyst(6, Items.LEAD) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); + InfusionRecipe.Builder.create("channeling_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.CHANNELING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.CHAIN) + .addCatalyst(4, Items.HEART_OF_THE_SEA) + .addCatalyst(6, Items.CHAIN) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); + InfusionRecipe.Builder.create("multishot_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.MULTISHOT, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.ARROW) + .addCatalyst(4, Items.SPECTRAL_ARROW) + .addCatalyst(6, Items.ARROW) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("quick_charge_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.QUICK_CHARGE, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.QUARTZ) + .addCatalyst(4, Items.GLOWSTONE_DUST) + .addCatalyst(6, Items.QUARTZ) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("piercing_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.PIERCING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.GLOWSTONE_DUST) + .addCatalyst(4, Items.SPECTRAL_ARROW) + .addCatalyst(6, Items.GLOWSTONE_DUST) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(300) + .build(); + InfusionRecipe.Builder.create("mending_book") + .setInput(Items.BOOK) + .setOutput(createEnchantedBook(Enchantments.MENDING, 1)) + .addCatalyst(0, EndItems.ENCHANTED_PETAL) + .addCatalyst(2, Items.EXPERIENCE_BOTTLE) + .addCatalyst(4, Blocks.ANVIL) + .addCatalyst(6, Items.EXPERIENCE_BOTTLE) + .addCatalyst(1, Items.LAPIS_LAZULI) + .addCatalyst(3, Items.LAPIS_LAZULI) + .addCatalyst(5, Items.LAPIS_LAZULI) + .addCatalyst(7, Items.LAPIS_LAZULI) + .setGroup("enchantment") + .setTime(375) + .build(); } - + private static ItemStack createEnchantedBook(Enchantment enchantment, int level) { ItemStack book = new ItemStack(Items.ENCHANTED_BOOK); - EnchantedBookItem.addEnchantment(book, new EnchantmentLevelEntry(enchantment, level)); + EnchantedBookItem.addEnchantment(book, new EnchantmentInstance(enchantment, level)); return book; } } diff --git a/src/main/java/ru/betterend/recipe/SmithingRecipes.java b/src/main/java/ru/betterend/recipe/SmithingRecipes.java index a48ce9f0..0da63634 100644 --- a/src/main/java/ru/betterend/recipe/SmithingRecipes.java +++ b/src/main/java/ru/betterend/recipe/SmithingRecipes.java @@ -6,40 +6,82 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndItems; public class SmithingRecipes { - + public static void register() { - SmithingTableRecipe.create("aeternium_sword_handle").setResult(EndItems.AETERNIUM_SWORD_HANDLE) - .setBase(EndBlocks.TERMINITE.ingot).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); + SmithingTableRecipe.create("aeternium_sword_handle") + .setResult(EndItems.AETERNIUM_SWORD_HANDLE) + .setBase(EndBlocks.TERMINITE.ingot) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); + + SmithingTableRecipe.create("aeternium_sword") + .setResult(EndItems.AETERNIUM_SWORD) + .setBase(EndItems.AETERNIUM_SWORD_BLADE) + .setAddition(EndItems.AETERNIUM_SWORD_HANDLE) + .build(); + SmithingTableRecipe.create("aeternium_pickaxe") + .setResult(EndItems.AETERNIUM_PICKAXE) + .setBase(EndItems.AETERNIUM_PICKAXE_HEAD) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); + SmithingTableRecipe.create("aeternium_axe") + .setResult(EndItems.AETERNIUM_AXE) + .setBase(EndItems.AETERNIUM_AXE_HEAD) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); + SmithingTableRecipe.create("aeternium_shovel") + .setResult(EndItems.AETERNIUM_SHOVEL) + .setBase(EndItems.AETERNIUM_SHOVEL_HEAD) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); + SmithingTableRecipe.create("aeternium_hoe") + .setResult(EndItems.AETERNIUM_HOE) + .setBase(EndItems.AETERNIUM_HOE_HEAD) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); + SmithingTableRecipe.create("aeternium_hammer") + .setResult(EndItems.AETERNIUM_HAMMER) + .setBase(EndItems.AETERNIUM_HAMMER_HEAD) + .setAddition(EndItems.LEATHER_WRAPPED_STICK) + .build(); - SmithingTableRecipe.create("aeternium_sword").setResult(EndItems.AETERNIUM_SWORD) - .setBase(EndItems.AETERNIUM_SWORD_BLADE).setAddition(EndItems.AETERNIUM_SWORD_HANDLE).build(); - SmithingTableRecipe.create("aeternium_pickaxe").setResult(EndItems.AETERNIUM_PICKAXE) - .setBase(EndItems.AETERNIUM_PICKAXE_HEAD).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); - SmithingTableRecipe.create("aeternium_axe").setResult(EndItems.AETERNIUM_AXE) - .setBase(EndItems.AETERNIUM_AXE_HEAD).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); - SmithingTableRecipe.create("aeternium_shovel").setResult(EndItems.AETERNIUM_SHOVEL) - .setBase(EndItems.AETERNIUM_SHOVEL_HEAD).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); - SmithingTableRecipe.create("aeternium_hoe").setResult(EndItems.AETERNIUM_HOE) - .setBase(EndItems.AETERNIUM_HOE_HEAD).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); - SmithingTableRecipe.create("aeternium_hammer").setResult(EndItems.AETERNIUM_HAMMER) - .setBase(EndItems.AETERNIUM_HAMMER_HEAD).setAddition(EndItems.LEATHER_WRAPPED_STICK).build(); - - SmithingTableRecipe.create("netherite_hammer").setResult(EndItems.NETHERITE_HAMMER) - .setBase(EndItems.DIAMOND_HAMMER).setAddition(Items.NETHERITE_INGOT).build(); - - SmithingTableRecipe.create("aeternium_helmet").setResult(EndItems.AETERNIUM_HELMET) - .setBase(EndBlocks.TERMINITE.helmet).setAddition(EndItems.AETERNIUM_INGOT).build(); - SmithingTableRecipe.create("aeternium_chestplate").setResult(EndItems.AETERNIUM_CHESTPLATE) - .setBase(EndBlocks.TERMINITE.chestplate).setAddition(EndItems.AETERNIUM_INGOT).build(); - SmithingTableRecipe.create("aeternium_leggings").setResult(EndItems.AETERNIUM_LEGGINGS) - .setBase(EndBlocks.TERMINITE.leggings).setAddition(EndItems.AETERNIUM_INGOT).build(); - SmithingTableRecipe.create("aeternium_boots").setResult(EndItems.AETERNIUM_BOOTS) - .setBase(EndBlocks.TERMINITE.boots).setAddition(EndItems.AETERNIUM_INGOT).build(); - - SmithingTableRecipe.create("thallasium_anvil_updrade").setResult(EndBlocks.TERMINITE.anvil) - .setBase(EndBlocks.THALLASIUM.anvil).setAddition(EndBlocks.TERMINITE.block).build(); - - SmithingTableRecipe.create("terminite_anvil_updrade").setResult(EndBlocks.AETERNIUM_ANVIL) - .setBase(EndBlocks.TERMINITE.anvil).setAddition(EndBlocks.AETERNIUM_BLOCK).build(); + SmithingTableRecipe.create("netherite_hammer") + .setResult(EndItems.NETHERITE_HAMMER) + .setBase(EndItems.DIAMOND_HAMMER) + .setAddition(Items.NETHERITE_INGOT) + .build(); + + SmithingTableRecipe.create("aeternium_helmet") + .setResult(EndItems.AETERNIUM_HELMET) + .setBase(EndBlocks.TERMINITE.helmet) + .setAddition(EndItems.AETERNIUM_INGOT) + .build(); + SmithingTableRecipe.create("aeternium_chestplate") + .setResult(EndItems.AETERNIUM_CHESTPLATE) + .setBase(EndBlocks.TERMINITE.chestplate) + .setAddition(EndItems.AETERNIUM_INGOT) + .build(); + SmithingTableRecipe.create("aeternium_leggings") + .setResult(EndItems.AETERNIUM_LEGGINGS) + .setBase(EndBlocks.TERMINITE.leggings) + .setAddition(EndItems.AETERNIUM_INGOT) + .build(); + SmithingTableRecipe.create("aeternium_boots") + .setResult(EndItems.AETERNIUM_BOOTS) + .setBase(EndBlocks.TERMINITE.boots) + .setAddition(EndItems.AETERNIUM_INGOT) + .build(); + + SmithingTableRecipe.create("thallasium_anvil_updrade") + .setResult(EndBlocks.TERMINITE.anvil) + .setBase(EndBlocks.THALLASIUM.anvil) + .setAddition(EndBlocks.TERMINITE.block) + .build(); + + SmithingTableRecipe.create("terminite_anvil_updrade") + .setResult(EndBlocks.AETERNIUM_ANVIL) + .setBase(EndBlocks.TERMINITE.anvil) + .setAddition(EndBlocks.AETERNIUM_BLOCK) + .build(); } } diff --git a/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java b/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java index fc5876a1..465a3ec1 100644 --- a/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/AlloyingRecipe.java @@ -5,19 +5,19 @@ import com.google.gson.JsonObject; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.inventory.Inventory; +import net.minecraft.core.NonNullList; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.Container; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.item.ItemStack; -import net.minecraft.network.PacketByteBuf; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -27,13 +27,13 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.util.ItemUtil; import ru.betterend.util.RecipeHelper; -public class AlloyingRecipe implements Recipe, BetterEndRecipe { - +public class AlloyingRecipe implements Recipe, BetterEndRecipe { + public final static String GROUP = "alloying"; public final static RecipeType TYPE = EndRecipeManager.registerType(GROUP); public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer()); public final static ResourceLocation ID = BetterEnd.makeID(GROUP); - + protected final RecipeType type; protected final ResourceLocation id; protected final Ingredient primaryInput; @@ -42,9 +42,8 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { protected final String group; protected final float experience; protected final int smeltTime; - - public AlloyingRecipe(ResourceLocation id, String group, Ingredient primaryInput, Ingredient secondaryInput, - ItemStack output, float experience, int smeltTime) { + + public AlloyingRecipe(ResourceLocation id, String group, Ingredient primaryInput, Ingredient secondaryInput, ItemStack output, float experience, int smeltTime) { this.group = group; this.id = id; this.primaryInput = primaryInput; @@ -54,42 +53,42 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { this.smeltTime = smeltTime; this.type = TYPE; } - + public float getExperience() { return this.experience; } - + public int getSmeltTime() { return this.smeltTime; } @Override - public DefaultedList getPreviewInputs() { - DefaultedList defaultedList = DefaultedList.of(); + public NonNullList getIngredients() { + NonNullList defaultedList = NonNullList.create(); defaultedList.add(primaryInput); defaultedList.add(secondaryInput); - + return defaultedList; } @Override - public boolean matches(Inventory inv, Level world) { - return this.primaryInput.test(inv.getStack(0)) && this.secondaryInput.test(inv.getStack(1)) - || this.primaryInput.test(inv.getStack(1)) && this.secondaryInput.test(inv.getStack(0)); + public boolean matches(Container inv, Level world) { + return this.primaryInput.test(inv.getItem(0)) && this.secondaryInput.test(inv.getItem(1)) || + this.primaryInput.test(inv.getItem(1)) && this.secondaryInput.test(inv.getItem(0)); } @Override - public ItemStack craft(Inventory inv) { + public ItemStack assemble(Container inv) { return this.output.copy(); } @Override - public boolean fits(int width, int height) { + public boolean canCraftInDimensions(int width, int height) { return true; } @Override - public ItemStack getOutput() { + public ItemStack getResultItem() { return this.output; } @@ -107,22 +106,22 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { public RecipeType getType() { return this.type; } - + @Override @Environment(EnvType.CLIENT) public String getGroup() { return this.group; } - + @Environment(EnvType.CLIENT) - public ItemStack getRecipeKindIcon() { + public ItemStack getToastSymbol() { return new ItemStack(EndBlocks.END_STONE_SMELTER); } - + public static class Builder { private final static Builder INSTANCE = new Builder(); private static boolean exist; - + public static Builder create(ResourceLocation id) { INSTANCE.id = id; INSTANCE.group = String.format("%s_%s", GROUP, id); @@ -132,14 +131,14 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { INSTANCE.experience = 0.0F; INSTANCE.smeltTime = 350; exist = Configs.RECIPE_CONFIG.getBoolean("alloying", id.getPath(), true); - + return INSTANCE; } - + public static Builder create(String id) { return create(BetterEnd.makeID(id)); } - + private ResourceLocation id; private Ingredient primaryInput; private Ingredient secondaryInput; @@ -148,15 +147,14 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { private float experience; private int smeltTime; private boolean alright = true; - - private Builder() { - } - + + private Builder() {} + public Builder setGroup(String group) { this.group = group; return this; } - + public Builder setPrimaryInput(ItemLike... inputs) { for (ItemLike item : inputs) { this.alright &= RecipeHelper.exists(item); @@ -164,7 +162,7 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { this.primaryInput = Ingredient.of(inputs); return this; } - + public Builder setSecondaryInput(ItemLike... inputs) { for (ItemLike item : inputs) { this.alright &= RecipeHelper.exists(item); @@ -172,58 +170,56 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { this.secondaryInput = Ingredient.of(inputs); return this; } - + public Builder setPrimaryInput(Tag input) { - this.primaryInput = Ingredient.fromTag(input); + this.primaryInput = Ingredient.of(input); return this; } - + public Builder setSecondaryInput(Tag input) { - this.secondaryInput = Ingredient.fromTag(input); + this.secondaryInput = Ingredient.of(input); return this; } - + public Builder setInput(ItemLike primaryInput, ItemLike secondaryInput) { this.setPrimaryInput(primaryInput); this.setSecondaryInput(secondaryInput); return this; } - + public Builder setInput(Tag primaryInput, Tag secondaryInput) { this.setPrimaryInput(primaryInput); this.setSecondaryInput(secondaryInput); return this; } - + public Builder setOutput(ItemLike output, int amount) { this.alright &= RecipeHelper.exists(output); this.output = new ItemStack(output, amount); return this; } - + public Builder setExpiriense(float amount) { this.experience = amount; return this; } - + public Builder setSmeltTime(int time) { this.smeltTime = time; return this; } - + public void build() { if (exist) { if (primaryInput == null) { - BetterEnd.LOGGER.warning( - "Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!", id); + BetterEnd.LOGGER.warning("Primary input for Alloying recipe can't be 'null', recipe {} will be ignored!", id); return; } - if (secondaryInput == null) { - BetterEnd.LOGGER.warning("Secondary input for Alloying can't be 'null', recipe {} will be ignored!", - id); + if(secondaryInput == null) { + BetterEnd.LOGGER.warning("Secondary input for Alloying can't be 'null', recipe {} will be ignored!", id); return; } - if (output == null) { + if(output == null) { BetterEnd.LOGGER.warning("Output for Alloying can't be 'null', recipe {} will be ignored!", id); return; } @@ -235,48 +231,47 @@ public class AlloyingRecipe implements Recipe, BetterEndRecipe { BetterEnd.LOGGER.debug("Can't add Alloying recipe {}! Ingeredient or output not exists.", id); return; } - EndRecipeManager.addRecipe(TYPE, - new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime)); + EndRecipeManager.addRecipe(TYPE, new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime)); } } } - + public static class Serializer implements RecipeSerializer { @Override - public AlloyingRecipe read(ResourceLocation id, JsonObject json) { - JsonArray ingredients = JsonHelper.getArray(json, "ingredients"); + public AlloyingRecipe fromJson(ResourceLocation id, JsonObject json) { + JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients"); Ingredient primaryInput = Ingredient.fromJson(ingredients.get(0)); Ingredient secondaryInput = Ingredient.fromJson(ingredients.get(1)); - String group = JsonHelper.getString(json, "group", ""); - JsonObject result = JsonHelper.getObject(json, "result"); + String group = GsonHelper.getAsString(json, "group", ""); + JsonObject result = GsonHelper.getAsJsonObject(json, "result"); ItemStack output = ItemUtil.fromJsonRecipe(result); if (output == null) { throw new IllegalStateException("Output item does not exists!"); } - float experience = JsonHelper.getFloat(json, "experience", 0.0F); - int smeltTime = JsonHelper.getInt(json, "smelttime", 350); - + float experience = GsonHelper.getAsFloat(json, "experience", 0.0F); + int smeltTime = GsonHelper.getAsInt(json, "smelttime", 350); + return new AlloyingRecipe(id, group, primaryInput, secondaryInput, output, experience, smeltTime); } @Override - public AlloyingRecipe read(ResourceLocation id, PacketByteBuf packetBuffer) { - String group = packetBuffer.readString(32767); - Ingredient primary = Ingredient.fromPacket(packetBuffer); - Ingredient secondary = Ingredient.fromPacket(packetBuffer); - ItemStack output = packetBuffer.readItemStack(); + public AlloyingRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) { + String group = packetBuffer.readUtf(32767); + Ingredient primary = Ingredient.fromNetwork(packetBuffer); + Ingredient secondary = Ingredient.fromNetwork(packetBuffer); + ItemStack output = packetBuffer.readItem(); float experience = packetBuffer.readFloat(); int smeltTime = packetBuffer.readVarInt(); - + return new AlloyingRecipe(id, group, primary, secondary, output, experience, smeltTime); } @Override - public void write(PacketByteBuf packetBuffer, AlloyingRecipe recipe) { - packetBuffer.writeString(recipe.group); - recipe.primaryInput.write(packetBuffer); - recipe.secondaryInput.write(packetBuffer); - packetBuffer.writeItemStack(recipe.output); + public void toNetwork(FriendlyByteBuf packetBuffer, AlloyingRecipe recipe) { + packetBuffer.writeUtf(recipe.group); + recipe.primaryInput.toNetwork(packetBuffer); + recipe.secondaryInput.toNetwork(packetBuffer); + packetBuffer.writeItem(recipe.output); packetBuffer.writeFloat(recipe.experience); packetBuffer.writeVarInt(recipe.smeltTime); } diff --git a/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java b/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java index 498d55f5..5feda8ab 100644 --- a/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/AnvilRecipe.java @@ -6,21 +6,22 @@ import com.google.gson.JsonObject; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.core.NonNullList; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.util.GsonHelper; +import net.minecraft.world.Container; +import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; -import net.minecraft.inventory.Inventory; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TieredItem; -import net.minecraft.network.PacketByteBuf; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -30,13 +31,13 @@ import ru.betterend.registry.EndTags; import ru.betterend.util.ItemUtil; import ru.betterend.util.RecipeHelper; -public class AnvilRecipe implements Recipe, BetterEndRecipe { - +public class AnvilRecipe implements Recipe, BetterEndRecipe { + public final static String GROUP = "smithing"; public final static RecipeType TYPE = EndRecipeManager.registerType(GROUP); public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer()); public final static ResourceLocation ID = BetterEnd.makeID(GROUP); - + private final ResourceLocation id; private final Ingredient input; private final ItemStack output; @@ -44,9 +45,8 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { private final int toolLevel; private final int anvilLevel; private final int inputCount; - - public AnvilRecipe(ResourceLocation identifier, Ingredient input, ItemStack output, int inputCount, int toolLevel, - int anvilLevel, int damage) { + + public AnvilRecipe(ResourceLocation identifier, Ingredient input, ItemStack output, int inputCount, int toolLevel, int anvilLevel, int damage) { this.id = identifier; this.input = input; this.output = output; @@ -62,50 +62,50 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { } @Override - public ItemStack getOutput() { + public ItemStack getResultItem() { return this.output; } - + @Override - public boolean matches(Inventory craftingInventory, Level world) { + public boolean matches(Container craftingInventory, Level world) { return this.matches(craftingInventory); } - + @Override - public ItemStack craft(Inventory craftingInventory) { + public ItemStack assemble(Container craftingInventory) { return this.output.copy(); } - - public ItemStack craft(Inventory craftingInventory, Player player) { + + public ItemStack craft(Container craftingInventory, Player player) { if (!player.isCreative()) { - if (!checkHammerDurability(craftingInventory, player)) - return ItemStack.EMPTY; - ItemStack hammer = craftingInventory.getStack(1); - hammer.damage(this.damage, player, entity -> entity.sendEquipmentBreakStatus(null)); + if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY; + ItemStack hammer = craftingInventory.getItem(1); + hammer.hurtAndBreak(this.damage, player, entity -> + entity.broadcastBreakEvent((InteractionHand) null)); } - return this.craft(craftingInventory); + return this.assemble(craftingInventory); } - public boolean checkHammerDurability(Inventory craftingInventory, Player player) { - if (player.isCreative()) - return true; - ItemStack hammer = craftingInventory.getStack(1); - int damage = hammer.getDamage() + this.damage; + public boolean checkHammerDurability(Container craftingInventory, Player player) { + if (player.isCreative()) return true; + ItemStack hammer = craftingInventory.getItem(1); + int damage = hammer.getDamageValue() + this.damage; return damage < hammer.getMaxDamage(); } - - public boolean matches(Inventory craftingInventory) { - ItemStack hammer = craftingInventory.getStack(1); + + public boolean matches(Container craftingInventory) { + ItemStack hammer = craftingInventory.getItem(1); if (hammer.isEmpty() || !EndTags.HAMMERS.contains(hammer.getItem())) { return false; } - ItemStack material = craftingInventory.getStack(0); + ItemStack material = craftingInventory.getItem(0); int materialCount = material.getCount(); int level = ((TieredItem) hammer.getItem()).getTier().getLevel(); - return this.input.test(craftingInventory.getStack(0)) && materialCount >= this.inputCount - && level >= this.toolLevel; + return this.input.test(craftingInventory.getItem(0)) && + materialCount >= this.inputCount && + level >= this.toolLevel; } - + public int getDamage() { return this.damage; } @@ -119,18 +119,18 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { } @Override - public DefaultedList getPreviewInputs() { - DefaultedList defaultedList = DefaultedList.of(); - defaultedList.add(Ingredient.ofStacks(EndTags.HAMMERS.values().stream() - .filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel).map(ItemStack::new))); + public NonNullList getIngredients() { + NonNullList defaultedList = NonNullList.create(); + defaultedList.add(Ingredient.of(EndTags.HAMMERS.getValues().stream().filter(hammer -> + ((TieredItem) hammer).getTier().getLevel() >= toolLevel).map(ItemStack::new))); defaultedList.add(input); - + return defaultedList; } @Override @Environment(EnvType.CLIENT) - public boolean fits(int width, int height) { + public boolean canCraftInDimensions(int width, int height) { return true; } @@ -143,21 +143,18 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { public RecipeType getType() { return TYPE; } - + @Override - public boolean isIgnoredInRecipeBook() { + public boolean isSpecial() { return true; } @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; AnvilRecipe that = (AnvilRecipe) o; - return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input) - && output.equals(that.output); + return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input) && output.equals(that.output); } @Override @@ -172,11 +169,11 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { public static class Builder { private final static Builder INSTANCE = new Builder(); - + public static Builder create(String id) { return create(BetterEnd.makeID(id)); } - + public static Builder create(ResourceLocation id) { INSTANCE.id = id; INSTANCE.input = null; @@ -186,10 +183,10 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { INSTANCE.anvilLevel = 1; INSTANCE.damage = 1; INSTANCE.alright = true; - + return INSTANCE; } - + private ResourceLocation id; private Ingredient input; private ItemStack output; @@ -198,21 +195,20 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { private int anvilLevel = 1; private int damage = 1; private boolean alright; - - private Builder() { - } - + + private Builder() {} + public Builder setInput(ItemLike... inputItems) { this.alright &= RecipeHelper.exists(inputItems); this.setInput(Ingredient.of(inputItems)); return this; } - + public Builder setInput(Tag inputTag) { - this.setInput(Ingredient.fromTag(inputTag)); + this.setInput(Ingredient.of(inputTag)); return this; } - + public Builder setInput(Ingredient ingredient) { this.input = ingredient; return this; @@ -222,17 +218,17 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { this.inputCount = count; return this; } - + public Builder setOutput(ItemLike output) { return this.setOutput(output, 1); } - + public Builder setOutput(ItemLike output, int amount) { this.alright &= RecipeHelper.exists(output); this.output = new ItemStack(output, amount); return this; } - + public Builder setToolLevel(int level) { this.toolLevel = level; return this; @@ -242,19 +238,19 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { this.anvilLevel = level; return this; } - + public Builder setDamage(int damage) { this.damage = damage; return this; } - + public void build() { if (Configs.RECIPE_CONFIG.getBoolean("anvil", id.getPath(), true)) { if (input == null) { BetterEnd.LOGGER.warning("Input for Anvil recipe can't be 'null', recipe {} will be ignored!", id); return; } - if (output == null) { + if(output == null) { BetterEnd.LOGGER.warning("Output for Anvil recipe can't be 'null', recipe {} will be ignored!", id); return; } @@ -266,45 +262,44 @@ public class AnvilRecipe implements Recipe, BetterEndRecipe { BetterEnd.LOGGER.debug("Can't add Anvil recipe {}! Ingeredient or output not exists.", id); return; } - EndRecipeManager.addRecipe(TYPE, - new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage)); + EndRecipeManager.addRecipe(TYPE, new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage)); } } } public static class Serializer implements RecipeSerializer { @Override - public AnvilRecipe read(ResourceLocation id, JsonObject json) { + public AnvilRecipe fromJson(ResourceLocation id, JsonObject json) { Ingredient input = Ingredient.fromJson(json.get("input")); - JsonObject result = JsonHelper.getObject(json, "result"); + JsonObject result = GsonHelper.getAsJsonObject(json, "result"); ItemStack output = ItemUtil.fromJsonRecipe(result); if (output == null) { throw new IllegalStateException("Output item does not exists!"); } - int inputCount = JsonHelper.getInt(json, "inputCount", 1); - int toolLevel = JsonHelper.getInt(json, "toolLevel", 1); - int anvilLevel = JsonHelper.getInt(json, "anvilLevel", 1); - int damage = JsonHelper.getInt(json, "damage", 1); - + int inputCount = GsonHelper.getAsInt(json, "inputCount", 1); + int toolLevel = GsonHelper.getAsInt(json, "toolLevel", 1); + int anvilLevel = GsonHelper.getAsInt(json, "anvilLevel", 1); + int damage = GsonHelper.getAsInt(json, "damage", 1); + return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage); } @Override - public AnvilRecipe read(ResourceLocation id, PacketByteBuf packetBuffer) { - Ingredient input = Ingredient.fromPacket(packetBuffer); - ItemStack output = packetBuffer.readItemStack(); + public AnvilRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) { + Ingredient input = Ingredient.fromNetwork(packetBuffer); + ItemStack output = packetBuffer.readItem(); int inputCount = packetBuffer.readVarInt(); int toolLevel = packetBuffer.readVarInt(); int anvilLevel = packetBuffer.readVarInt(); int damage = packetBuffer.readVarInt(); - + return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage); } @Override - public void write(PacketByteBuf packetBuffer, AnvilRecipe recipe) { - recipe.input.write(packetBuffer); - packetBuffer.writeItemStack(recipe.output); + public void toNetwork(FriendlyByteBuf packetBuffer, AnvilRecipe recipe) { + recipe.input.toNetwork(packetBuffer); + packetBuffer.writeItem(recipe.output); packetBuffer.writeVarInt(recipe.inputCount); packetBuffer.writeVarInt(recipe.toolLevel); packetBuffer.writeVarInt(recipe.anvilLevel); diff --git a/src/main/java/ru/betterend/recipe/builders/FurnaceRecipe.java b/src/main/java/ru/betterend/recipe/builders/FurnaceRecipe.java index 928a533e..ea441729 100644 --- a/src/main/java/ru/betterend/recipe/builders/FurnaceRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/FurnaceRecipe.java @@ -1,6 +1,6 @@ package ru.betterend.recipe.builders; -import net.minecraft.world.level.ItemLike; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.BlastingRecipe; import net.minecraft.world.item.crafting.CampfireCookingRecipe; @@ -8,7 +8,7 @@ import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.SmeltingRecipe; import net.minecraft.world.item.crafting.SmokingRecipe; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ItemLike; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; import ru.betterend.recipe.EndRecipeManager; @@ -16,7 +16,7 @@ import ru.betterend.util.RecipeHelper; public class FurnaceRecipe { private static final FurnaceRecipe INSTANCE = new FurnaceRecipe(); - + private ItemLike input; private ItemLike output; private boolean exist; @@ -25,10 +25,9 @@ public class FurnaceRecipe { private int count; private int time; private float xp; - - private FurnaceRecipe() { - } - + + private FurnaceRecipe() {} + public static FurnaceRecipe make(String name, ItemLike input, ItemLike output) { INSTANCE.name = name; INSTANCE.group = ""; @@ -37,68 +36,64 @@ public class FurnaceRecipe { INSTANCE.count = 1; INSTANCE.time = 200; INSTANCE.xp = 0; - INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("furnace", name, true) && RecipeHelper.exists(output) - && RecipeHelper.exists(input); + INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("furnace", name, true) && RecipeHelper.exists(output) && RecipeHelper.exists(input); return INSTANCE; } - + public FurnaceRecipe setGroup(String group) { this.group = group; return this; } - + public FurnaceRecipe setOutputCount(int count) { this.count = count; return this; } - + public FurnaceRecipe setXP(float xp) { this.xp = xp; return this; } - + public FurnaceRecipe setCookTime(int time) { this.time = time; return this; } - + public void build() { build(false, false, false); } - + public void buildWithBlasting() { build(true, false, false); } - + public void buildFoodlike() { build(false, true, true); } - + public void build(boolean blasting, boolean campfire, boolean smoker) { if (exist) { ResourceLocation id = BetterEnd.makeID(name); - SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), - xp, time); + SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time); EndRecipeManager.addRecipe(RecipeType.SMELTING, recipe); - + if (blasting) { - BlastingRecipe recipe2 = new BlastingRecipe(id, group, Ingredient.of(input), - new ItemStack(output, count), xp, time / 2); + BlastingRecipe recipe2 = new BlastingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2); EndRecipeManager.addRecipe(RecipeType.BLASTING, recipe2); } - + if (campfire) { - CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(id, group, Ingredient.of(input), - new ItemStack(output, count), xp, time * 3); + CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time * 3); EndRecipeManager.addRecipe(RecipeType.CAMPFIRE_COOKING, recipe2); } - + if (smoker) { - SmokingRecipe recipe2 = new SmokingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), - xp, time / 2); + SmokingRecipe recipe2 = new SmokingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2); EndRecipeManager.addRecipe(RecipeType.SMOKING, recipe2); } - } else { + } + else { BetterEnd.LOGGER.debug("Furnace recipe {} couldn't be added", name); } } diff --git a/src/main/java/ru/betterend/recipe/builders/GridRecipe.java b/src/main/java/ru/betterend/recipe/builders/GridRecipe.java index d3991074..b8ec3625 100644 --- a/src/main/java/ru/betterend/recipe/builders/GridRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/GridRecipe.java @@ -2,20 +2,18 @@ package ru.betterend.recipe.builders; import java.util.Arrays; import java.util.Map; - -import com.google.common.collect.Maps; - +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.ShapelessRecipe; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.level.ItemLike; +import com.google.common.collect.Maps; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; import ru.betterend.recipe.EndRecipeManager; @@ -23,10 +21,10 @@ import ru.betterend.util.RecipeHelper; public class GridRecipe { private static final GridRecipe INSTANCE = new GridRecipe(); - + private String name; private ItemLike output; - + private String group; private RecipeType type; private boolean shaped; @@ -34,23 +32,22 @@ public class GridRecipe { private Map materialKeys = Maps.newHashMap(); private int count; private boolean exist = true; - - private GridRecipe() { - } - + + private GridRecipe() {} + public static GridRecipe make(String name, ItemLike output) { INSTANCE.name = name; INSTANCE.output = output; - + INSTANCE.group = ""; INSTANCE.type = RecipeType.CRAFTING; INSTANCE.shaped = true; - INSTANCE.shape = new String[] { "#" }; + INSTANCE.shape = new String[] {"#"}; INSTANCE.materialKeys.clear(); INSTANCE.count = 1; - + INSTANCE.exist = Configs.RECIPE_CONFIG.getBoolean("grid", name, true) && RecipeHelper.exists(output); - + return INSTANCE; } @@ -58,66 +55,65 @@ public class GridRecipe { this.group = group; return this; } - + public GridRecipe setShape(String... shape) { this.shape = shape; return this; } - + public GridRecipe setList(String shape) { this.shape = new String[] { shape }; this.shaped = false; return this; } - + public GridRecipe addMaterial(char key, Tag value) { - return addMaterial(key, Ingredient.fromTag(value)); + return addMaterial(key, Ingredient.of(value)); } - + public GridRecipe addMaterial(char key, ItemStack... value) { - return addMaterial(key, Ingredient.ofStacks(Arrays.stream(value))); + return addMaterial(key, Ingredient.of(Arrays.stream(value))); } - + public GridRecipe addMaterial(char key, ItemLike... values) { - for (ItemLike item : values) { + for (ItemLike item: values) { exist &= RecipeHelper.exists(item); } return addMaterial(key, Ingredient.of(values)); } - + private GridRecipe addMaterial(char key, Ingredient value) { materialKeys.put(key, value); return this; } - + public GridRecipe setOutputCount(int count) { this.count = count; return this; } - - private DefaultedList getMaterials(int width, int height) { - DefaultedList materials = DefaultedList.ofSize(width * height, Ingredient.EMPTY); + + private NonNullList getMaterials(int width, int height) { + NonNullList materials = NonNullList.withSize(width * height, Ingredient.EMPTY); int pos = 0; - for (String line : shape) { + for (String line: shape) { for (int i = 0; i < width; i++) { char c = line.charAt(i); Ingredient material = materialKeys.get(c); - materials.set(pos++, material == null ? Ingredient.EMPTY : material); + materials.set(pos ++, material == null ? Ingredient.EMPTY : material); } } return materials; } - + public void build() { if (exist) { int height = shape.length; int width = shape[0].length(); ItemStack result = new ItemStack(output, count); ResourceLocation id = BetterEnd.makeID(name); - DefaultedList materials = this.getMaterials(width, height); - - CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) - : new ShapelessRecipe(id, group, result, materials); + NonNullList materials = this.getMaterials(width, height); + + CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials); EndRecipeManager.addRecipe(type, recipe); } else { BetterEnd.LOGGER.debug("Recipe {} couldn't be added", name); diff --git a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java index 8864b200..df7e7bfd 100644 --- a/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/InfusionRecipe.java @@ -6,16 +6,16 @@ import com.google.gson.JsonObject; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.world.level.ItemLike; +import net.minecraft.core.NonNullList; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.GsonHelper; import net.minecraft.world.item.ItemStack; -import net.minecraft.network.PacketByteBuf; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.Level; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -25,67 +25,65 @@ import ru.betterend.rituals.InfusionRitual; import ru.betterend.util.ItemUtil; public class InfusionRecipe implements Recipe, BetterEndRecipe { - + public final static String GROUP = "infusion"; public final static RecipeType TYPE = EndRecipeManager.registerType(GROUP); public final static Serializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new Serializer()); public final static ResourceLocation ID = BetterEnd.makeID(GROUP); - + private final ResourceLocation id; + private final Ingredient[] catalysts; private Ingredient input; private ItemStack output; private int time = 1; - private Ingredient[] catalysts = new Ingredient[8]; private String group; - + private InfusionRecipe(ResourceLocation id) { this(id, null, null); } - + private InfusionRecipe(ResourceLocation id, Ingredient input, ItemStack output) { this.id = id; this.input = input; this.output = output; + this.catalysts = new Ingredient[8]; Arrays.fill(catalysts, Ingredient.EMPTY); } - + public int getInfusionTime() { return this.time; } @Override public boolean matches(InfusionRitual inv, Level world) { - boolean valid = this.input.test(inv.getStack(0)); - if (!valid) - return false; + boolean valid = this.input.test(inv.getItem(0)); + if (!valid) return false; for (int i = 0; i < 8; i++) { - valid &= this.catalysts[i].test(inv.getStack(i + 1)); + valid &= this.catalysts[i].test(inv.getItem(i + 1)); } return valid; } @Override - public ItemStack craft(InfusionRitual ritual) { + public ItemStack assemble(InfusionRitual ritual) { return this.output.copy(); } @Override - public boolean fits(int width, int height) { + public boolean canCraftInDimensions(int width, int height) { return true; } - + @Override - public DefaultedList getPreviewInputs() { - DefaultedList defaultedList = DefaultedList.of(); + public NonNullList getIngredients() { + NonNullList defaultedList = NonNullList.create(); defaultedList.add(input); - for (Ingredient catalyst : catalysts) { - defaultedList.add(catalyst); - } + defaultedList.addAll(Arrays.asList(catalysts)); return defaultedList; } @Override - public ItemStack getOutput() { + public ItemStack getResultItem() { return this.output; } @@ -93,7 +91,7 @@ public class InfusionRecipe implements Recipe, BetterEndRecipe { public ResourceLocation getId() { return this.id; } - + @Override @Environment(EnvType.CLIENT) public String getGroup() { @@ -109,82 +107,79 @@ public class InfusionRecipe implements Recipe, BetterEndRecipe { public RecipeType getType() { return TYPE; } - + public static class Builder { private final static Builder INSTANCE = new Builder(); private static boolean exist; - + public static Builder create(String id) { return create(BetterEnd.makeID(id)); } - + public static Builder create(ResourceLocation id) { INSTANCE.id = id; INSTANCE.input = null; INSTANCE.output = null; INSTANCE.time = 1; exist = Configs.RECIPE_CONFIG.getBoolean("infusion", id.getPath(), true); - + Arrays.fill(INSTANCE.catalysts, Ingredient.EMPTY); - + return INSTANCE; } - + private ResourceLocation id; private Ingredient input; private ItemStack output; private String group; private int time = 1; private Ingredient[] catalysts = new Ingredient[8]; - + private Builder() { Arrays.fill(catalysts, Ingredient.EMPTY); } - + public Builder setGroup(String group) { this.group = group; return this; } - + public Builder setInput(ItemLike input) { this.input = Ingredient.of(input); return this; } - + public Builder setOutput(ItemLike output) { this.output = new ItemStack(output); this.output.setCount(1); return this; } - + public Builder setOutput(ItemStack output) { this.output = output; this.output.setCount(1); return this; } - + public Builder setTime(int time) { this.time = time; return this; } - + public Builder addCatalyst(int slot, ItemLike... items) { - if (slot > 7) - return this; + if (slot > 7) return this; this.catalysts[slot] = Ingredient.of(items); return this; } - + public void build() { if (exist) { if (input == null) { - BetterEnd.LOGGER.warning("Input for Infusion recipe can't be 'null', recipe {} will be ignored!", - id); + BetterEnd.LOGGER.warning("Input for Infusion recipe can't be 'null', recipe {} will be ignored!", id); return; } if (output == null) { - BetterEnd.LOGGER.warning("Output for Infusion recipe can't be 'null', recipe {} will be ignored!", - id); + BetterEnd.LOGGER.warning("Output for Infusion recipe can't be 'null', recipe {} will be ignored!", id); return; } InfusionRecipe recipe = new InfusionRecipe(id, input, output); @@ -192,10 +187,8 @@ public class InfusionRecipe implements Recipe, BetterEndRecipe { recipe.time = time; int empty = 0; for (int i = 0; i < catalysts.length; i++) { - if (catalysts[i].isEmpty()) - empty++; - else - recipe.catalysts[i] = catalysts[i]; + if (catalysts[i].isEmpty()) empty++; + else recipe.catalysts[i] = catalysts[i]; } if (empty == catalysts.length) { BetterEnd.LOGGER.warning("At least one catalyst must be non empty, recipe {} will be ignored!", id); @@ -205,62 +198,62 @@ public class InfusionRecipe implements Recipe, BetterEndRecipe { } } } - + public static class Serializer implements RecipeSerializer { @Override - public InfusionRecipe read(ResourceLocation id, JsonObject json) { + public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) { InfusionRecipe recipe = new InfusionRecipe(id); recipe.input = Ingredient.fromJson(json.get("input")); - JsonObject result = JsonHelper.getObject(json, "result"); + JsonObject result = GsonHelper.getAsJsonObject(json, "result"); recipe.output = ItemUtil.fromJsonRecipe(result); if (recipe.output == null) { throw new IllegalStateException("Output item does not exists!"); } - recipe.group = JsonHelper.getString(json, "group", GROUP); - recipe.time = JsonHelper.getInt(json, "time", 1); - - JsonObject catalysts = JsonHelper.asObject(json, "catalysts"); - ItemStack catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north", "")); - recipe.catalysts[0] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north_east", "")); - recipe.catalysts[1] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "east", "")); - recipe.catalysts[2] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south_east", "")); - recipe.catalysts[3] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south", "")); - recipe.catalysts[4] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "south_west", "")); - recipe.catalysts[5] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "west", "")); - recipe.catalysts[6] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - catalyst = ItemUtil.fromStackString(JsonHelper.getString(catalysts, "north_west", "")); - recipe.catalysts[7] = Ingredient.ofStacks(Arrays.stream(new ItemStack[] { catalyst })); - + recipe.group = GsonHelper.getAsString(json, "group", GROUP); + recipe.time = GsonHelper.getAsInt(json, "time", 1); + + JsonObject catalysts = GsonHelper.convertToJsonObject(json, "catalysts"); + ItemStack catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north", "")); + recipe.catalysts[0] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north_east", "")); + recipe.catalysts[1] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "east", "")); + recipe.catalysts[2] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south_east", "")); + recipe.catalysts[3] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south", "")); + recipe.catalysts[4] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "south_west", "")); + recipe.catalysts[5] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "west", "")); + recipe.catalysts[6] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + catalyst = ItemUtil.fromStackString(GsonHelper.getAsString(catalysts, "north_west", "")); + recipe.catalysts[7] = Ingredient.of(Arrays.stream(new ItemStack[] { catalyst })); + return recipe; } @Override - public InfusionRecipe read(ResourceLocation id, PacketByteBuf buffer) { + public InfusionRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) { InfusionRecipe recipe = new InfusionRecipe(id); - recipe.input = Ingredient.fromPacket(buffer); - recipe.output = buffer.readItemStack(); - recipe.group = buffer.readString(); + recipe.input = Ingredient.fromNetwork(buffer); + recipe.output = buffer.readItem(); + recipe.group = buffer.readUtf(); recipe.time = buffer.readVarInt(); for (int i = 0; i < 8; i++) { - recipe.catalysts[i] = Ingredient.fromPacket(buffer); + recipe.catalysts[i] = Ingredient.fromNetwork(buffer); } return recipe; } @Override - public void write(PacketByteBuf buffer, InfusionRecipe recipe) { - recipe.input.write(buffer); - buffer.writeItemStack(recipe.output); - buffer.writeString(recipe.group); + public void toNetwork(FriendlyByteBuf buffer, InfusionRecipe recipe) { + recipe.input.toNetwork(buffer); + buffer.writeItem(recipe.output); + buffer.writeUtf(recipe.group); buffer.writeVarInt(recipe.time); for (int i = 0; i < 8; i++) { - recipe.catalysts[i].write(buffer); + recipe.catalysts[i].toNetwork(buffer); } } } diff --git a/src/main/java/ru/betterend/recipe/builders/SmithingTableRecipe.java b/src/main/java/ru/betterend/recipe/builders/SmithingTableRecipe.java index bed7b508..b48d55f6 100644 --- a/src/main/java/ru/betterend/recipe/builders/SmithingTableRecipe.java +++ b/src/main/java/ru/betterend/recipe/builders/SmithingTableRecipe.java @@ -1,91 +1,88 @@ package ru.betterend.recipe.builders; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.crafting.SmithingRecipe; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.UpgradeRecipe; +import net.minecraft.world.level.ItemLike; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; import ru.betterend.recipe.EndRecipeManager; import ru.betterend.util.RecipeHelper; public class SmithingTableRecipe { - + private final static SmithingTableRecipe BUILDER = new SmithingTableRecipe(); - private final static RecipeType TYPE = RecipeType.SMITHING; - + private final static RecipeType TYPE = RecipeType.SMITHING; + public static SmithingTableRecipe create(String name) { return create(BetterEnd.makeID(name)); } - + public static SmithingTableRecipe create(ResourceLocation id) { BUILDER.id = id; BUILDER.base = null; BUILDER.addition = null; BUILDER.result = null; BUILDER.alright = true; - + return BUILDER; } - + private ResourceLocation id; private Ingredient base; private Ingredient addition; private ItemStack result; private boolean alright; - - private SmithingTableRecipe() { - } - + + private SmithingTableRecipe() {} + public SmithingTableRecipe setResult(ItemLike item) { return this.setResult(item, 1); } - + public SmithingTableRecipe setResult(ItemLike item, int count) { this.alright &= RecipeHelper.exists(item); this.result = new ItemStack(item, count); return this; } - + public SmithingTableRecipe setBase(ItemLike... items) { this.alright &= RecipeHelper.exists(items); this.base = Ingredient.of(items); return this; } - + public SmithingTableRecipe setBase(Tag tag) { - this.base = (Ingredient.fromTag(tag)); + this.base = (Ingredient.of(tag)); return this; } - + public SmithingTableRecipe setAddition(ItemLike... items) { this.alright &= RecipeHelper.exists(items); this.addition = Ingredient.of(items); return this; } - + public SmithingTableRecipe setAddition(Tag tag) { - this.addition = (Ingredient.fromTag(tag)); + this.addition = (Ingredient.of(tag)); return this; } - + public void build() { if (Configs.RECIPE_CONFIG.getBoolean("smithing", id.getPath(), true)) { if (base == null) { - BetterEnd.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", - id); + BetterEnd.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); return; } if (addition == null) { - BetterEnd.LOGGER - .warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); + BetterEnd.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); return; } - if (result == null) { + if(result == null) { BetterEnd.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id); return; } @@ -97,7 +94,7 @@ public class SmithingTableRecipe { BetterEnd.LOGGER.debug("Can't add Smithing recipe {}! Ingeredients or output not exists.", id); return; } - EndRecipeManager.addRecipe(TYPE, new SmithingRecipe(id, base, addition, result)); + EndRecipeManager.addRecipe(TYPE, new UpgradeRecipe(id, base, addition, result)); } } } diff --git a/src/main/java/ru/betterend/registry/EndBiomes.java b/src/main/java/ru/betterend/registry/EndBiomes.java index 9526810c..78107877 100644 --- a/src/main/java/ru/betterend/registry/EndBiomes.java +++ b/src/main/java/ru/betterend/registry/EndBiomes.java @@ -19,12 +19,13 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.biome.InternalBiomeData; import net.fabricmc.fabric.impl.biome.WeightedBiomePicker; import net.minecraft.client.Minecraft; +import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; -import net.minecraft.server.MinecraftServer; import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biomes; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; @@ -64,24 +65,24 @@ public class EndBiomes { private static final HashMap CLIENT = Maps.newHashMap(); public static final Set FABRIC_VOID = Sets.newHashSet(); private static final Set SUBBIOMES_UNMUTABLES = Sets.newHashSet(); - + public static final BiomePicker LAND_BIOMES = new BiomePicker(); public static final BiomePicker VOID_BIOMES = new BiomePicker(); public static final BiomePicker CAVE_BIOMES = new BiomePicker(); public static final List SUBBIOMES = Lists.newArrayList(); private static final JsonObject EMPTY_JSON = new JsonObject(); - + private static Registry biomeRegistry; - + // Vanilla Land public static final EndBiome END = registerBiome(Biomes.THE_END, BiomeType.LAND, 1F); public static final EndBiome END_MIDLANDS = registerSubBiome(Biomes.END_MIDLANDS, END, 0.5F); public static final EndBiome END_HIGHLANDS = registerSubBiome(Biomes.END_HIGHLANDS, END, 0.5F); - + // Vanilla Void public static final EndBiome END_BARRENS = registerBiome(Biomes.END_BARRENS, BiomeType.VOID, 1F); public static final EndBiome SMALL_END_ISLANDS = registerBiome(Biomes.SMALL_END_ISLANDS, BiomeType.VOID, 1); - + // Better End Land public static final EndBiome FOGGY_MUSHROOMLAND = registerBiome(new FoggyMushroomlandBiome(), BiomeType.LAND); public static final EndBiome CHORUS_FOREST = registerBiome(new ChorusForestBiome(), BiomeType.LAND); @@ -100,39 +101,37 @@ public class EndBiomes { public static final EndBiome DRY_SHRUBLAND = registerBiome(new DryShrublandBiome(), BiomeType.LAND); public static final EndBiome LANTERN_WOODS = registerBiome(new LanternWoodsBiome(), BiomeType.LAND); public static final EndBiome NEON_OASIS = registerSubBiome(new NeonOasisBiome(), DUST_WASTELANDS); - + // Better End Void public static final EndBiome ICE_STARFIELD = registerBiome(new BiomeIceStarfield(), BiomeType.VOID); - + // Better End Caves public static final EndCaveBiome EMPTY_END_CAVE = registerCaveBiome(new EmptyEndCaveBiome()); public static final EndCaveBiome EMPTY_SMARAGDANT_CAVE = registerCaveBiome(new EmptySmaragdantCaveBiome()); public static final EndCaveBiome LUSH_SMARAGDANT_CAVE = registerCaveBiome(new LushSmaragdantCaveBiome()); public static final EndCaveBiome EMPTY_AURORA_CAVE = registerCaveBiome(new EmptyAuroraCaveBiome()); public static final EndCaveBiome LUSH_AURORA_CAVE = registerCaveBiome(new LushAuroraCaveBiome()); - - public static void register() { - } - + + public static void register() {} + public static void mutateRegistry(Registry biomeRegistry) { EndBiomes.biomeRegistry = biomeRegistry; - + LAND_BIOMES.clearMutables(); VOID_BIOMES.clearMutables(); CAVE_BIOMES.clearMutables(); - + if (FABRIC_VOID.isEmpty()) { loadFabricAPIBiomes(); } - + Map configs = Maps.newHashMap(); - + biomeRegistry.forEach((biome) -> { - if (biome.getBiomeCategory() == Biome.BiomeCategory.THEEND) { + if (biome.getBiomeCategory() == BiomeCategory.THEEND) { ResourceLocation id = biomeRegistry.getKey(biome); if (Configs.BIOME_CONFIG.getBoolean(id, "enabled", true)) { - if (!LAND_BIOMES.containsImmutable(id) && !VOID_BIOMES.containsImmutable(id) - && !SUBBIOMES_UNMUTABLES.contains(id)) { + if (!LAND_BIOMES.containsImmutable(id) && !VOID_BIOMES.containsImmutable(id) && !SUBBIOMES_UNMUTABLES.contains(id)) { JsonObject config = configs.get(id.getNamespace()); if (config == null) { config = loadJsonConfig(id.getNamespace()); @@ -153,7 +152,8 @@ public class EndBiomes { if (isVoid) { VOID_BIOMES.addBiomeMutable(endBiome); - } else { + } + else { LAND_BIOMES.addBiomeMutable(endBiome); } ID_MAP.put(id, endBiome); @@ -163,58 +163,58 @@ public class EndBiomes { }); Integrations.addBiomes(); Configs.BIOME_CONFIG.saveChanges(); - + rebuildPicker(LAND_BIOMES, biomeRegistry); rebuildPicker(VOID_BIOMES, biomeRegistry); rebuildPicker(CAVE_BIOMES, biomeRegistry); - + SUBBIOMES.forEach((endBiome) -> { endBiome.updateActualBiomes(biomeRegistry); }); - + CLIENT.clear(); } - + private static void rebuildPicker(BiomePicker picker, Registry biomeRegistry) { picker.rebuild(); picker.getBiomes().forEach((endBiome) -> { endBiome.updateActualBiomes(biomeRegistry); }); } - + private static void loadFabricAPIBiomes() { List> biomes = Lists.newArrayList(); biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS))); biomes.addAll(getBiomes(InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS))); biomes.forEach((key) -> FABRIC_VOID.add(key.location())); - + if (BetterEnd.isDevEnvironment()) { System.out.println("=================================="); System.out.println("Added void biomes from Fabric API:"); - FABRIC_VOID.forEach(System.out::println); + FABRIC_VOID.forEach((id) -> { + System.out.println(id); + }); System.out.println("=================================="); } } - + private static List> getBiomes(WeightedBiomePicker picker) { IBiomeList biomeList = (IBiomeList) (Object) picker; return biomeList == null ? Collections.emptyList() : biomeList.getBiomes(); } - + private static JsonObject loadJsonConfig(String namespace) { - InputStream inputstream = EndBiomes.class - .getResourceAsStream("/data/" + namespace + "/end_biome_properties.json"); + InputStream inputstream = EndBiomes.class.getResourceAsStream("/data/" + namespace + "/end_biome_properties.json"); if (inputstream != null) { return JsonFactory.getJsonObject(inputstream); - } else { + } + else { return EMPTY_JSON; } } - + /** - * Initialize registry if it was not initialized in world generation (when using - * mods/datapacks, that overrides the End generation) - * + * Initialize registry if it was not initialized in world generation (when using mods/datapacks, that overrides the End generation) * @param server - {@link MinecraftServer} */ public static void initRegistry(MinecraftServer server) { @@ -222,28 +222,24 @@ public class EndBiomes { biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); } } - + /** - * Registers new {@link EndBiome} and adds it to picker, can be used to add - * existing mod biomes into the End. - * - * @param biome - {@link Biome} instance - * @param type - {@link BiomeType} + * Registers new {@link EndBiome} and adds it to picker, can be used to add existing mod biomes into the End. + * @param biome - {@link Biome} instance + * @param type - {@link BiomeType} * @param genChance - generation chance [0.0F - Infinity] * @return registered {@link EndBiome} */ public static EndBiome registerBiome(Biome biome, BiomeType type, float genChance) { return registerBiome(biome, type, 1, genChance); } - + /** - * Registers new {@link EndBiome} and adds it to picker, can be used to add - * existing mod biomes into the End. - * - * @param biome - {@link Biome} instance - * @param type - {@link BiomeType} + * Registers new {@link EndBiome} and adds it to picker, can be used to add existing mod biomes into the End. + * @param biome - {@link Biome} instance + * @param type - {@link BiomeType} * @param fogDensity - density of fog (def: 1F) [0.0F - Infinity] - * @param genChance - generation chance [0.0F - Infinity] + * @param genChance - generation chance [0.0F - Infinity] * @return registered {@link EndBiome} */ public static EndBiome registerBiome(Biome biome, BiomeType type, float fogDensity, float genChance) { @@ -253,32 +249,27 @@ public class EndBiomes { } return endBiome; } - + /** - * Registers new {@link EndBiome} from existed {@link Biome} and put as a - * sub-biome into selected parent. - * - * @param biome - {@link Biome} instance - * @param parent - {@link EndBiome} to be linked with + * Registers new {@link EndBiome} from existed {@link Biome} and put as a sub-biome into selected parent. + * @param biome - {@link Biome} instance + * @param parent - {@link EndBiome} to be linked with * @param genChance - generation chance [0.0F - Infinity] * @return registered {@link EndBiome} */ public static EndBiome registerSubBiome(Biome biome, EndBiome parent, float genChance, boolean hasCaves) { return registerSubBiome(biome, parent, 1, genChance, hasCaves); } - + /** - * Registers new {@link EndBiome} from existed {@link Biome} and put as a - * sub-biome into selected parent. - * - * @param biome - {@link Biome} instance - * @param parent - {@link EndBiome} to be linked with + * Registers new {@link EndBiome} from existed {@link Biome} and put as a sub-biome into selected parent. + * @param biome - {@link Biome} instance + * @param parent - {@link EndBiome} to be linked with * @param fogDensity - density of fog (def: 1F) [0.0F - Infinity] - * @param genChance - generation chance [0.0F - Infinity] + * @param genChance - generation chance [0.0F - Infinity] * @return registered {@link EndBiome} */ - public static EndBiome registerSubBiome(Biome biome, EndBiome parent, float fogDensity, float genChance, - boolean hasCaves) { + public static EndBiome registerSubBiome(Biome biome, EndBiome parent, float fogDensity, float genChance, boolean hasCaves) { EndBiome endBiome = new EndBiome(BuiltinRegistries.BIOME.getKey(biome), biome, fogDensity, genChance, hasCaves); if (Configs.BIOME_CONFIG.getBoolean(endBiome.getID(), "enabled", true)) { parent.addSubBiome(endBiome); @@ -288,11 +279,10 @@ public class EndBiomes { } return endBiome; } - + /** * Put existing {@link EndBiome} as a sub-biome into selected parent. - * - * @param biome - {@link EndBiome} instance + * @param biome - {@link EndBiome} instance * @param parent - {@link EndBiome} to be linked with * @return registered {@link EndBiome} */ @@ -307,12 +297,11 @@ public class EndBiomes { } return biome; } - + /** * Registers {@link EndBiome} and adds it into worldgen. - * * @param biome - {@link EndBiome} instance - * @param type - {@link BiomeType} + * @param type - {@link BiomeType} * @return registered {@link EndBiome} */ public static EndBiome registerBiome(EndBiome biome, BiomeType type) { @@ -322,17 +311,16 @@ public class EndBiomes { ID_MAP.put(biome.getID(), biome); if (type == BiomeType.LAND) { addLandBiomeToFabricApi(biome); - } else { + } + else { addVoidBiomeToFabricApi(biome); } } return biome; } - + /** - * Put integration sub-biome {@link EndBiome} into subbiomes list and registers - * it. - * + * Put integration sub-biome {@link EndBiome} into subbiomes list and registers it. * @param biome - {@link EndBiome} instance * @return registered {@link EndBiome} */ @@ -346,11 +334,10 @@ public class EndBiomes { } return biome; } - + /** * Link integration sub-biome with parent. - * - * @param biome - {@link EndBiome} instance + * @param biome - {@link EndBiome} instance * @param parent - {@link ResourceLocation} parent id */ public static void addSubBiomeIntegration(EndBiome biome, ResourceLocation parent) { @@ -361,19 +348,20 @@ public class EndBiomes { } } } - + public static EndBiome registerBiome(ResourceKey key, BiomeType type, float genChance) { return registerBiome(BuiltinRegistries.BIOME.get(key), type, genChance); } - + public static EndBiome registerSubBiome(ResourceKey key, EndBiome parent, float genChance) { return registerSubBiome(BuiltinRegistries.BIOME.get(key), parent, genChance, true); } - + private static void addToPicker(EndBiome biome, BiomeType type) { if (type == BiomeType.LAND) { LAND_BIOMES.addBiome(biome); - } else { + } + else { VOID_BIOMES.addBiome(biome); } } @@ -381,37 +369,36 @@ public class EndBiomes { private static void registerBiomeDirectly(EndBiome biome) { Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); } - + private static void addLandBiomeToFabricApi(EndBiome biome) { float weight = biome.getGenChanceImmutable(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); InternalBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); InternalBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); } - + private static void addVoidBiomeToFabricApi(EndBiome biome) { float weight = biome.getGenChanceImmutable(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); InternalBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); } - + public static EndBiome getFromBiome(Biome biome) { - return ID_MAP.getOrDefault(biomeRegistry.getId(biome), END); + return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), END); } - + @Environment(EnvType.CLIENT) public static EndBiome getRenderBiome(Biome biome) { EndBiome endBiome = CLIENT.get(biome); if (endBiome == null) { Minecraft minecraft = Minecraft.getInstance(); - ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY) - .getKey(biome); + ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); endBiome = id == null ? END : ID_MAP.getOrDefault(id, END); CLIENT.put(biome, endBiome); } return endBiome; } - + public static ResourceLocation getBiomeID(Biome biome) { ResourceLocation id = biomeRegistry.getKey(biome); return id == null ? END.getID() : id; @@ -429,7 +416,7 @@ public class EndBiomes { result.addAll(SUBBIOMES); return result; } - + public static EndCaveBiome registerCaveBiome(EndCaveBiome biome) { if (Configs.BIOME_CONFIG.getBoolean(biome.getID(), "enabled", true)) { registerBiomeDirectly(biome); @@ -438,11 +425,11 @@ public class EndBiomes { } return biome; } - + public static EndCaveBiome getCaveBiome(Random random) { return (EndCaveBiome) CAVE_BIOMES.getBiome(random); } - + public static boolean hasBiome(ResourceLocation biomeID) { return ID_MAP.containsKey(biomeID); } diff --git a/src/main/java/ru/betterend/registry/EndBlockEntities.java b/src/main/java/ru/betterend/registry/EndBlockEntities.java index 96116a09..e722dc94 100644 --- a/src/main/java/ru/betterend/registry/EndBlockEntities.java +++ b/src/main/java/ru/betterend/registry/EndBlockEntities.java @@ -1,14 +1,12 @@ package ru.betterend.registry; import java.util.List; - -import com.google.common.collect.Lists; - +import net.minecraft.core.Registry; +import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.item.BlockItem; -import net.minecraft.core.Registry; +import com.google.common.collect.Lists; import ru.betterend.BetterEnd; import ru.betterend.blocks.EndStoneSmelter; import ru.betterend.blocks.EternalPedestal; @@ -29,35 +27,30 @@ import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.PedestalBlockEntity; public class EndBlockEntities { - public final static BlockEntityType END_STONE_SMELTER = registerBlockEntity( - EndStoneSmelter.ID, - BlockEntityType.Builder.create(EndStoneSmelterBlockEntity::new, EndBlocks.END_STONE_SMELTER)); + public final static BlockEntityType END_STONE_SMELTER = registerBlockEntity(EndStoneSmelter.ID, + BlockEntityType.Builder.of(EndStoneSmelterBlockEntity::new, EndBlocks.END_STONE_SMELTER)); public final static BlockEntityType PEDESTAL = registerBlockEntity("pedestal", - BlockEntityType.Builder.create(PedestalBlockEntity::new, getPedestals())); - public final static BlockEntityType ETERNAL_PEDESTAL = registerBlockEntity( - "eternal_pedestal", BlockEntityType.Builder.create(EternalPedestalEntity::new, EndBlocks.ETERNAL_PEDESTAL)); - public final static BlockEntityType INFUSION_PEDESTAL = registerBlockEntity( - "infusion_pedestal", - BlockEntityType.Builder.create(InfusionPedestalEntity::new, EndBlocks.INFUSION_PEDESTAL)); - public static final BlockEntityType CHEST = registerBlockEntity("chest", - BlockEntityType.Builder.create(EChestBlockEntity::new, getChests())); + BlockEntityType.Builder.of(PedestalBlockEntity::new, getPedestals())); + public final static BlockEntityType ETERNAL_PEDESTAL = registerBlockEntity("eternal_pedestal", + BlockEntityType.Builder.of(EternalPedestalEntity::new, EndBlocks.ETERNAL_PEDESTAL)); + public final static BlockEntityType INFUSION_PEDESTAL = registerBlockEntity("infusion_pedestal", + BlockEntityType.Builder.of(InfusionPedestalEntity::new, EndBlocks.INFUSION_PEDESTAL)); + public static final BlockEntityType CHEST = registerBlockEntity("chest", + BlockEntityType.Builder.of(EChestBlockEntity::new, getChests())); public static final BlockEntityType BARREL = registerBlockEntity("barrel", - BlockEntityType.Builder.create(EBarrelBlockEntity::new, getBarrels())); + BlockEntityType.Builder.of(EBarrelBlockEntity::new, getBarrels())); public static final BlockEntityType SIGN = registerBlockEntity("sign", - BlockEntityType.Builder.create(ESignBlockEntity::new, getSigns())); - public final static BlockEntityType HYDROTHERMAL_VENT = registerBlockEntity( - "hydrother_malvent", - BlockEntityType.Builder.create(BlockEntityHydrothermalVent::new, EndBlocks.HYDROTHERMAL_VENT)); + BlockEntityType.Builder.of(ESignBlockEntity::new, getSigns())); + public final static BlockEntityType HYDROTHERMAL_VENT = registerBlockEntity("hydrother_malvent", + BlockEntityType.Builder.of(BlockEntityHydrothermalVent::new, EndBlocks.HYDROTHERMAL_VENT)); public static final BlockEntityType FURNACE = registerBlockEntity("furnace", - BlockEntityType.Builder.create(EFurnaceBlockEntity::new, getFurnaces())); + BlockEntityType.Builder.of(EFurnaceBlockEntity::new, getFurnaces())); - public static BlockEntityType registerBlockEntity(String id, - BlockEntityType.Builder builder) { + public static BlockEntityType registerBlockEntity(String id, BlockEntityType.Builder builder) { return Registry.register(Registry.BLOCK_ENTITY_TYPE, BetterEnd.makeID(id), builder.build(null)); } - - public static void register() { - } + + public static void register() {} static Block[] getChests() { List result = Lists.newArrayList(); @@ -71,7 +64,7 @@ public class EndBlockEntities { }); return result.toArray(new Block[] {}); } - + static Block[] getBarrels() { List result = Lists.newArrayList(); EndItems.getModBlocks().forEach((item) -> { @@ -84,7 +77,7 @@ public class EndBlockEntities { }); return result.toArray(new Block[] {}); } - + static Block[] getSigns() { List result = Lists.newArrayList(); EndItems.getModBlocks().forEach((item) -> { @@ -97,14 +90,14 @@ public class EndBlockEntities { }); return result.toArray(new Block[] {}); } - + static Block[] getPedestals() { List result = Lists.newArrayList(); EndItems.getModBlocks().forEach((item) -> { if (item instanceof BlockItem) { Block block = ((BlockItem) item).getBlock(); - if (block instanceof EternalPedestal || block instanceof InfusionPedestal) - return; + if (block instanceof EternalPedestal || + block instanceof InfusionPedestal) return; if (block instanceof PedestalBlock) { result.add(block); } @@ -112,7 +105,7 @@ public class EndBlockEntities { }); return result.toArray(new Block[] {}); } - + static Block[] getFurnaces() { List result = Lists.newArrayList(); EndItems.getModBlocks().forEach((item) -> { diff --git a/src/main/java/ru/betterend/registry/EndBlocks.java b/src/main/java/ru/betterend/registry/EndBlocks.java index b21a480a..c1ca660f 100644 --- a/src/main/java/ru/betterend/registry/EndBlocks.java +++ b/src/main/java/ru/betterend/registry/EndBlocks.java @@ -1,13 +1,13 @@ package ru.betterend.registry; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item.Properties; +import net.minecraft.world.item.WaterLilyBlockItem; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.material.MaterialColor; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.Item.Properties; -import net.minecraft.world.item.LilyPadItem; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.blocks.*; import ru.betterend.blocks.basis.EndCropBlock; @@ -39,23 +39,18 @@ import ru.betterend.item.material.EndToolMaterial; public class EndBlocks { // Terrain // public static final Block ENDSTONE_DUST = registerBlock("endstone_dust", new EndstoneDustBlock()); - public static final Block END_MYCELIUM = registerBlock("end_mycelium", - new EndTerrainBlock(MaterialColor.COLOR_LIGHT_BLUE)); + public static final Block END_MYCELIUM = registerBlock("end_mycelium", new EndTerrainBlock(MaterialColor.COLOR_LIGHT_BLUE)); public static final Block END_MOSS = registerBlock("end_moss", new EndTerrainBlock(MaterialColor.COLOR_CYAN)); - public static final Block CHORUS_NYLIUM = registerBlock("chorus_nylium", - new EndTerrainBlock(MaterialColor.COLOR_MAGENTA)); - public static final Block CAVE_MOSS = registerBlock("cave_moss", - new TripleTerrainBlock(MaterialColor.COLOR_PURPLE)); - public static final Block CRYSTAL_MOSS = registerBlock("crystal_moss", - new EndTerrainBlock(MaterialColor.COLOR_PINK)); + public static final Block CHORUS_NYLIUM = registerBlock("chorus_nylium", new EndTerrainBlock(MaterialColor.COLOR_MAGENTA)); + public static final Block CAVE_MOSS = registerBlock("cave_moss", new TripleTerrainBlock(MaterialColor.COLOR_PURPLE)); + public static final Block CRYSTAL_MOSS = registerBlock("crystal_moss", new EndTerrainBlock(MaterialColor.COLOR_PINK)); public static final Block SHADOW_GRASS = registerBlock("shadow_grass", new ShadowGrassBlock()); public static final Block PINK_MOSS = registerBlock("pink_moss", new EndTerrainBlock(MaterialColor.COLOR_PINK)); public static final Block AMBER_MOSS = registerBlock("amber_moss", new EndTerrainBlock(MaterialColor.COLOR_ORANGE)); - public static final Block JUNGLE_MOSS = registerBlock("jungle_moss", - new EndTerrainBlock(MaterialColor.COLOR_GREEN)); + public static final Block JUNGLE_MOSS = registerBlock("jungle_moss", new EndTerrainBlock(MaterialColor.COLOR_GREEN)); public static final Block SANGNUM = registerBlock("sangnum", new EndTerrainBlock(MaterialColor.COLOR_RED)); public static final Block RUTISCUS = registerBlock("rutiscus", new EndTerrainBlock(MaterialColor.COLOR_ORANGE)); - + // Roads // public static final Block END_MYCELIUM_PATH = registerBlock("end_mycelium_path", new EndPathBlock(END_MYCELIUM)); public static final Block END_MOSS_PATH = registerBlock("end_moss_path", new EndPathBlock(END_MOSS)); @@ -68,130 +63,93 @@ public class EndBlocks { public static final Block JUNGLE_MOSS_PATH = registerBlock("jungle_moss_path", new EndPathBlock(JUNGLE_MOSS)); public static final Block SANGNUM_PATH = registerBlock("sangnum_path", new EndPathBlock(SANGNUM)); public static final Block RUTISCUS_PATH = registerBlock("rutiscus_path", new EndPathBlock(RUTISCUS)); - + public static final Block MOSSY_OBSIDIAN = registerBlock("mossy_obsidian", new MossyObsidian()); - public static final Block DRAGON_BONE_BLOCK = registerBlock("dragon_bone_block", - new EndPillarBlock(Blocks.BONE_BLOCK)); - public static final Block DRAGON_BONE_STAIRS = registerBlock("dragon_bone_stairs", - new EndStairsBlock(DRAGON_BONE_BLOCK)); + public static final Block DRAGON_BONE_BLOCK = registerBlock("dragon_bone_block", new EndPillarBlock(Blocks.BONE_BLOCK)); + public static final Block DRAGON_BONE_STAIRS = registerBlock("dragon_bone_stairs", new EndStairsBlock(DRAGON_BONE_BLOCK)); public static final Block DRAGON_BONE_SLAB = registerBlock("dragon_bone_slab", new EndSlabBlock(DRAGON_BONE_BLOCK)); public static final Block MOSSY_DRAGON_BONE = registerBlock("mossy_dragon_bone", new MossyDragonBoneBlock()); - + // Rocks // public static final StoneMaterial FLAVOLITE = new StoneMaterial("flavolite", MaterialColor.SAND); public static final StoneMaterial VIOLECITE = new StoneMaterial("violecite", MaterialColor.COLOR_PURPLE); public static final StoneMaterial SULPHURIC_ROCK = new StoneMaterial("sulphuric_rock", MaterialColor.COLOR_BROWN); public static final StoneMaterial VIRID_jADESTONE = new StoneMaterial("virid_jadestone", MaterialColor.COLOR_GREEN); - public static final StoneMaterial AZURE_jADESTONE = new StoneMaterial("azure_jadestone", - MaterialColor.COLOR_LIGHT_BLUE); - public static final StoneMaterial SANDY_jADESTONE = new StoneMaterial("sandy_jadestone", - MaterialColor.COLOR_YELLOW); + public static final StoneMaterial AZURE_jADESTONE = new StoneMaterial("azure_jadestone", MaterialColor.COLOR_LIGHT_BLUE); + public static final StoneMaterial SANDY_jADESTONE = new StoneMaterial("sandy_jadestone", MaterialColor.COLOR_YELLOW); public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock()); public static final Block SULPHUR_CRYSTAL = registerBlock("sulphur_crystal", new SulphurCrystalBlock()); public static final Block MISSING_TILE = registerBlock("missing_tile", new MissingTileBlock()); - + public static final Block FLAVOLITE_RUNED = registerBlock("flavolite_runed", new RunedFlavolite()); - public static final Block FLAVOLITE_RUNED_ETERNAL = registerBlock("flavolite_runed_eternal", - new EternalRunedFlavolite()); - - public static final Block ANDESITE_PEDESTAL = registerBlock("andesite_pedestal", - new PedestalVanilla(Blocks.ANDESITE)); + public static final Block FLAVOLITE_RUNED_ETERNAL = registerBlock("flavolite_runed_eternal", new EternalRunedFlavolite()); + + public static final Block ANDESITE_PEDESTAL = registerBlock("andesite_pedestal", new PedestalVanilla(Blocks.ANDESITE)); public static final Block DIORITE_PEDESTAL = registerBlock("diorite_pedestal", new PedestalVanilla(Blocks.DIORITE)); public static final Block GRANITE_PEDESTAL = registerBlock("granite_pedestal", new PedestalVanilla(Blocks.GRANITE)); - public static final Block QUARTZ_PEDESTAL = registerBlock("quartz_pedestal", - new PedestalVanilla(Blocks.QUARTZ_BLOCK)); - public static final Block PURPUR_PEDESTAL = registerBlock("purpur_pedestal", - new PedestalVanilla(Blocks.PURPUR_BLOCK)); - + public static final Block QUARTZ_PEDESTAL = registerBlock("quartz_pedestal", new PedestalVanilla(Blocks.QUARTZ_BLOCK)); + public static final Block PURPUR_PEDESTAL = registerBlock("purpur_pedestal", new PedestalVanilla(Blocks.PURPUR_BLOCK)); + public static final Block HYDROTHERMAL_VENT = registerBlock("hydrothermal_vent", new HydrothermalVentBlock()); public static final Block VENT_BUBBLE_COLUMN = registerBlockNI("vent_bubble_column", new VentBubbleColumnBlock()); - + public static final Block DENSE_SNOW = registerBlock("dense_snow", new DenseSnowBlock()); public static final Block EMERALD_ICE = registerBlock("emerald_ice", new EmeraldIceBlock()); public static final Block DENSE_EMERALD_ICE = registerBlock("dense_emerald_ice", new DenseEmeraldIceBlock()); public static final Block ANCIENT_EMERALD_ICE = registerBlock("ancient_emerald_ice", new AncientEmeraldIceBlock()); - - public static final Block END_STONE_STALACTITE = registerBlock("end_stone_stalactite", - new StalactiteBlock(Blocks.END_STONE)); - public static final Block END_STONE_STALACTITE_CAVEMOSS = registerBlock("end_stone_stalactite_cavemoss", - new StalactiteBlock(CAVE_MOSS)); - + + public static final Block END_STONE_STALACTITE = registerBlock("end_stone_stalactite", new StalactiteBlock(Blocks.END_STONE)); + public static final Block END_STONE_STALACTITE_CAVEMOSS = registerBlock("end_stone_stalactite_cavemoss", new StalactiteBlock(CAVE_MOSS)); + // Wooden Materials And Trees // - public static final Block MOSSY_GLOWSHROOM_SAPLING = registerBlock("mossy_glowshroom_sapling", - new MossyGlowshroomSaplingBlock()); - public static final Block MOSSY_GLOWSHROOM_CAP = registerBlock("mossy_glowshroom_cap", - new MossyGlowshroomCapBlock()); - public static final Block MOSSY_GLOWSHROOM_HYMENOPHORE = registerBlock("mossy_glowshroom_hymenophore", - new GlowingHymenophoreBlock()); - public static final Block MOSSY_GLOWSHROOM_FUR = registerBlock("mossy_glowshroom_fur", - new FurBlock(MOSSY_GLOWSHROOM_SAPLING, 15, 16, true)); - public static final WoodenMaterial MOSSY_GLOWSHROOM = new WoodenMaterial("mossy_glowshroom", - MaterialColor.COLOR_GRAY, MaterialColor.WOOD); - - public static final Block PYTHADENDRON_SAPLING = registerBlock("pythadendron_sapling", - new PythadendronSaplingBlock()); - public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", - new EndLeavesBlock(PYTHADENDRON_SAPLING, MaterialColor.COLOR_MAGENTA)); - public static final WoodenMaterial PYTHADENDRON = new WoodenMaterial("pythadendron", MaterialColor.COLOR_MAGENTA, - MaterialColor.COLOR_PURPLE); - + public static final Block MOSSY_GLOWSHROOM_SAPLING = registerBlock("mossy_glowshroom_sapling", new MossyGlowshroomSaplingBlock()); + public static final Block MOSSY_GLOWSHROOM_CAP = registerBlock("mossy_glowshroom_cap", new MossyGlowshroomCapBlock()); + public static final Block MOSSY_GLOWSHROOM_HYMENOPHORE = registerBlock("mossy_glowshroom_hymenophore", new GlowingHymenophoreBlock()); + public static final Block MOSSY_GLOWSHROOM_FUR = registerBlock("mossy_glowshroom_fur", new FurBlock(MOSSY_GLOWSHROOM_SAPLING, 15, 16, true)); + public static final WoodenMaterial MOSSY_GLOWSHROOM = new WoodenMaterial("mossy_glowshroom", MaterialColor.COLOR_GRAY, MaterialColor.WOOD); + + public static final Block PYTHADENDRON_SAPLING = registerBlock("pythadendron_sapling", new PythadendronSaplingBlock()); + public static final Block PYTHADENDRON_LEAVES = registerBlock("pythadendron_leaves", new EndLeavesBlock(PYTHADENDRON_SAPLING, MaterialColor.COLOR_MAGENTA)); + public static final WoodenMaterial PYTHADENDRON = new WoodenMaterial("pythadendron", MaterialColor.COLOR_MAGENTA, MaterialColor.COLOR_PURPLE); + public static final Block END_LOTUS_SEED = registerBlock("end_lotus_seed", new EndLotusSeedBlock()); public static final Block END_LOTUS_STEM = registerBlock("end_lotus_stem", new EndLotusStemBlock()); public static final Block END_LOTUS_LEAF = registerBlockNI("end_lotus_leaf", new EndLotusLeafBlock()); public static final Block END_LOTUS_FLOWER = registerBlockNI("end_lotus_flower", new EndLotusFlowerBlock()); - public static final WoodenMaterial END_LOTUS = new WoodenMaterial("end_lotus", MaterialColor.COLOR_LIGHT_BLUE, - MaterialColor.COLOR_CYAN); - + public static final WoodenMaterial END_LOTUS = new WoodenMaterial("end_lotus", MaterialColor.COLOR_LIGHT_BLUE, MaterialColor.COLOR_CYAN); + public static final Block LACUGROVE_SAPLING = registerBlock("lacugrove_sapling", new LacugroveSaplingBlock()); - public static final Block LACUGROVE_LEAVES = registerBlock("lacugrove_leaves", - new EndLeavesBlock(LACUGROVE_SAPLING, MaterialColor.COLOR_CYAN)); - public static final WoodenMaterial LACUGROVE = new WoodenMaterial("lacugrove", MaterialColor.COLOR_BROWN, - MaterialColor.COLOR_YELLOW); - + public static final Block LACUGROVE_LEAVES = registerBlock("lacugrove_leaves", new EndLeavesBlock(LACUGROVE_SAPLING, MaterialColor.COLOR_CYAN)); + public static final WoodenMaterial LACUGROVE = new WoodenMaterial("lacugrove", MaterialColor.COLOR_BROWN, MaterialColor.COLOR_YELLOW); + public static final Block DRAGON_TREE_SAPLING = registerBlock("dragon_tree_sapling", new DragonTreeSaplingBlock()); - public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", - new EndLeavesBlock(DRAGON_TREE_SAPLING, MaterialColor.COLOR_MAGENTA)); - public static final WoodenMaterial DRAGON_TREE = new WoodenMaterial("dragon_tree", MaterialColor.COLOR_BLACK, - MaterialColor.COLOR_MAGENTA); - + public static final Block DRAGON_TREE_LEAVES = registerBlock("dragon_tree_leaves", new EndLeavesBlock(DRAGON_TREE_SAPLING, MaterialColor.COLOR_MAGENTA)); + public static final WoodenMaterial DRAGON_TREE = new WoodenMaterial("dragon_tree", MaterialColor.COLOR_BLACK, MaterialColor.COLOR_MAGENTA); + public static final Block TENANEA_SAPLING = registerBlock("tenanea_sapling", new TenaneaSaplingBlock()); - public static final Block TENANEA_LEAVES = registerBlock("tenanea_leaves", - new EndLeavesBlock(TENANEA_SAPLING, MaterialColor.COLOR_PINK)); + public static final Block TENANEA_LEAVES = registerBlock("tenanea_leaves", new EndLeavesBlock(TENANEA_SAPLING, MaterialColor.COLOR_PINK)); public static final Block TENANEA_FLOWERS = registerBlock("tenanea_flowers", new TenaneaFlowersBlock()); - public static final Block TENANEA_OUTER_LEAVES = registerBlock("tenanea_outer_leaves", - new FurBlock(TENANEA_SAPLING, 32)); - public static final WoodenMaterial TENANEA = new WoodenMaterial("tenanea", MaterialColor.COLOR_BROWN, - MaterialColor.COLOR_PINK); - + public static final Block TENANEA_OUTER_LEAVES = registerBlock("tenanea_outer_leaves", new FurBlock(TENANEA_SAPLING, 32)); + public static final WoodenMaterial TENANEA = new WoodenMaterial("tenanea", MaterialColor.COLOR_BROWN, MaterialColor.COLOR_PINK); + public static final Block HELIX_TREE_SAPLING = registerBlock("helix_tree_sapling", new HelixTreeSaplingBlock()); public static final Block HELIX_TREE_LEAVES = registerBlock("helix_tree_leaves", new HelixTreeLeavesBlock()); - public static final WoodenMaterial HELIX_TREE = new WoodenMaterial("helix_tree", MaterialColor.COLOR_GRAY, - MaterialColor.COLOR_ORANGE); - - public static final Block UMBRELLA_TREE_SAPLING = registerBlock("umbrella_tree_sapling", - new UmbrellaTreeSaplingBlock()); - public static final Block UMBRELLA_TREE_MEMBRANE = registerBlock("umbrella_tree_membrane", - new UmbrellaTreeMembraneBlock()); - public static final Block UMBRELLA_TREE_CLUSTER = registerBlock("umbrella_tree_cluster", - new UmbrellaTreeClusterBlock()); - public static final Block UMBRELLA_TREE_CLUSTER_EMPTY = registerBlock("umbrella_tree_cluster_empty", - new UmbrellaTreeClusterEmptyBlock()); - public static final WoodenMaterial UMBRELLA_TREE = new WoodenMaterial("umbrella_tree", MaterialColor.COLOR_BLUE, - MaterialColor.COLOR_GREEN); - - public static final Block JELLYSHROOM_CAP_PURPLE = registerBlock("jellyshroom_cap_purple", - new JellyshroomCapBlock(217, 142, 255, 164, 0, 255)); - public static final WoodenMaterial JELLYSHROOM = new WoodenMaterial("jellyshroom", MaterialColor.COLOR_PURPLE, - MaterialColor.COLOR_LIGHT_BLUE); - + public static final WoodenMaterial HELIX_TREE = new WoodenMaterial("helix_tree", MaterialColor.COLOR_GRAY, MaterialColor.COLOR_ORANGE); + + public static final Block UMBRELLA_TREE_SAPLING = registerBlock("umbrella_tree_sapling", new UmbrellaTreeSaplingBlock()); + public static final Block UMBRELLA_TREE_MEMBRANE = registerBlock("umbrella_tree_membrane", new UmbrellaTreeMembraneBlock()); + public static final Block UMBRELLA_TREE_CLUSTER = registerBlock("umbrella_tree_cluster", new UmbrellaTreeClusterBlock()); + public static final Block UMBRELLA_TREE_CLUSTER_EMPTY = registerBlock("umbrella_tree_cluster_empty", new UmbrellaTreeClusterEmptyBlock()); + public static final WoodenMaterial UMBRELLA_TREE = new WoodenMaterial("umbrella_tree", MaterialColor.COLOR_BLUE, MaterialColor.COLOR_GREEN); + + public static final Block JELLYSHROOM_CAP_PURPLE = registerBlock("jellyshroom_cap_purple", new JellyshroomCapBlock(217, 142, 255, 164, 0, 255)); + public static final WoodenMaterial JELLYSHROOM = new WoodenMaterial("jellyshroom", MaterialColor.COLOR_PURPLE, MaterialColor.COLOR_LIGHT_BLUE); + public static final Block LUCERNIA_SAPLING = registerBlock("lucernia_sapling", new TenaneaSaplingBlock()); - public static final Block LUCERNIA_LEAVES = registerBlock("lucernia_leaves", - new EndLeavesBlock(LUCERNIA_SAPLING, MaterialColor.COLOR_ORANGE)); - public static final Block LUCERNIA_OUTER_LEAVES = registerBlock("lucernia_outer_leaves", - new FurBlock(LUCERNIA_SAPLING, 32)); - public static final WoodenMaterial LUCERNIA = new WoodenMaterial("lucernia", MaterialColor.COLOR_ORANGE, - MaterialColor.COLOR_ORANGE); - + public static final Block LUCERNIA_LEAVES = registerBlock("lucernia_leaves", new EndLeavesBlock(LUCERNIA_SAPLING, MaterialColor.COLOR_ORANGE)); + public static final Block LUCERNIA_OUTER_LEAVES = registerBlock("lucernia_outer_leaves", new FurBlock(LUCERNIA_SAPLING, 32)); + public static final WoodenMaterial LUCERNIA = new WoodenMaterial("lucernia", MaterialColor.COLOR_ORANGE, MaterialColor.COLOR_ORANGE); + // Small Plants // public static final Block UMBRELLA_MOSS = registerBlock("umbrella_moss", new UmbrellaMossBlock()); public static final Block UMBRELLA_MOSS_TALL = registerBlock("umbrella_moss_tall", new UmbrellaMossTallBlock()); @@ -202,75 +160,59 @@ public class EndBlocks { public static final Block SHADOW_PLANT = registerBlock("shadow_plant", new TerrainPlantBlock(SHADOW_GRASS)); public static final Block BUSHY_GRASS = registerBlock("bushy_grass", new TerrainPlantBlock(PINK_MOSS)); public static final Block AMBER_GRASS = registerBlock("amber_grass", new TerrainPlantBlock(AMBER_MOSS)); - public static final Block TWISTED_UMBRELLA_MOSS = registerBlock("twisted_umbrella_moss", - new TwistedUmbrellaMossBlock()); - public static final Block TWISTED_UMBRELLA_MOSS_TALL = registerBlock("twisted_umbrella_moss_tall", - new TwistedUmbrellaMossTallBlock()); + public static final Block TWISTED_UMBRELLA_MOSS = registerBlock("twisted_umbrella_moss", new TwistedUmbrellaMossBlock()); + public static final Block TWISTED_UMBRELLA_MOSS_TALL = registerBlock("twisted_umbrella_moss_tall", new TwistedUmbrellaMossTallBlock()); public static final Block JUNGLE_GRASS = registerBlock("jungle_grass", new TerrainPlantBlock(JUNGLE_MOSS)); public static final Block BLOOMING_COOKSONIA = registerBlock("blooming_cooksonia", new TerrainPlantBlock(END_MOSS)); public static final Block SALTEAGO = registerBlock("salteago", new TerrainPlantBlock(END_MOSS)); public static final Block VAIOLUSH_FERN = registerBlock("vaiolush_fern", new TerrainPlantBlock(END_MOSS)); public static final Block FRACTURN = registerBlock("fracturn", new TerrainPlantBlock(END_MOSS)); - public static final Block CLAWFERN = registerBlock("clawfern", - new TerrainPlantBlock(SANGNUM, MOSSY_OBSIDIAN, MOSSY_DRAGON_BONE)); - public static final Block GLOBULAGUS = registerBlock("globulagus", - new TerrainPlantBlock(SANGNUM, MOSSY_OBSIDIAN, MOSSY_DRAGON_BONE)); + public static final Block CLAWFERN = registerBlock("clawfern", new TerrainPlantBlock(SANGNUM, MOSSY_OBSIDIAN, MOSSY_DRAGON_BONE)); + public static final Block GLOBULAGUS = registerBlock("globulagus", new TerrainPlantBlock(SANGNUM, MOSSY_OBSIDIAN, MOSSY_DRAGON_BONE)); public static final Block ORANGO = registerBlock("orango", new TerrainPlantBlock(RUTISCUS)); public static final Block AERIDIUM = registerBlock("aeridium", new TerrainPlantBlock(RUTISCUS)); public static final Block LUTEBUS = registerBlock("lutebus", new TerrainPlantBlock(RUTISCUS)); public static final Block LAMELLARIUM = registerBlock("lamellarium", new TerrainPlantBlock(RUTISCUS)); - + public static final Block BLUE_VINE_SEED = registerBlock("blue_vine_seed", new BlueVineSeedBlock()); public static final Block BLUE_VINE = registerBlockNI("blue_vine", new BlueVineBlock()); public static final Block BLUE_VINE_LANTERN = registerBlock("blue_vine_lantern", new BlueVineLanternBlock()); - public static final Block BLUE_VINE_FUR = registerBlock("blue_vine_fur", - new FurBlock(BLUE_VINE_SEED, 15, 3, false)); - + public static final Block BLUE_VINE_FUR = registerBlock("blue_vine_fur", new FurBlock(BLUE_VINE_SEED, 15, 3, false)); + public static final Block LANCELEAF_SEED = registerBlock("lanceleaf_seed", new LanceleafSeedBlock()); public static final Block LANCELEAF = registerBlockNI("lanceleaf", new LanceleafBlock()); - + public static final Block GLOWING_PILLAR_SEED = registerBlock("glowing_pillar_seed", new GlowingPillarSeedBlock()); - public static final Block GLOWING_PILLAR_ROOTS = registerBlockNI("glowing_pillar_roots", - new GlowingPillarRootsBlock()); - public static final Block GLOWING_PILLAR_LUMINOPHOR = registerBlock("glowing_pillar_luminophor", - new GlowingPillarLuminophorBlock()); - public static final Block GLOWING_PILLAR_LEAVES = registerBlock("glowing_pillar_leaves", - new FurBlock(GLOWING_PILLAR_SEED, 15, 3, false)); - + public static final Block GLOWING_PILLAR_ROOTS = registerBlockNI("glowing_pillar_roots", new GlowingPillarRootsBlock()); + public static final Block GLOWING_PILLAR_LUMINOPHOR = registerBlock("glowing_pillar_luminophor", new GlowingPillarLuminophorBlock()); + public static final Block GLOWING_PILLAR_LEAVES = registerBlock("glowing_pillar_leaves", new FurBlock(GLOWING_PILLAR_SEED, 15, 3, false)); + public static final Block SMALL_JELLYSHROOM = registerBlock("small_jellyshroom", new SmallJellyshroomBlock()); public static final Block BOLUX_MUSHROOM = registerBlock("bolux_mushroom", new BoluxMushroomBlock()); - + public static final Block LUMECORN_SEED = registerBlock("lumecorn_seed", new LumecornSeedBlock()); public static final Block LUMECORN = registerBlockNI("lumecorn", new LumecornBlock()); - - public static final Block SMALL_AMARANITA_MUSHROOM = registerBlock("small_amaranita_mushroom", - new SmallAmaranitaBlock()); - public static final Block LARGE_AMARANITA_MUSHROOM = registerBlockNI("large_amaranita_mushroom", - new LargeAmaranitaBlock()); + + public static final Block SMALL_AMARANITA_MUSHROOM = registerBlock("small_amaranita_mushroom", new SmallAmaranitaBlock()); + public static final Block LARGE_AMARANITA_MUSHROOM = registerBlockNI("large_amaranita_mushroom", new LargeAmaranitaBlock()); public static final Block AMARANITA_STEM = registerBlock("amaranita_stem", new AmaranitaStemBlock()); public static final Block AMARANITA_HYPHAE = registerBlock("amaranita_hyphae", new AmaranitaStemBlock()); - public static final Block AMARANITA_HYMENOPHORE = registerBlock("amaranita_hymenophore", - new AmaranitaHymenophoreBlock()); + public static final Block AMARANITA_HYMENOPHORE = registerBlock("amaranita_hymenophore", new AmaranitaHymenophoreBlock()); public static final Block AMARANITA_LANTERN = registerBlock("amaranita_lantern", new GlowingHymenophoreBlock()); - public static final Block AMARANITA_FUR = registerBlock("amaranita_fur", - new FurBlock(MOSSY_GLOWSHROOM_SAPLING, 15, 4, true)); + public static final Block AMARANITA_FUR = registerBlock("amaranita_fur", new FurBlock(MOSSY_GLOWSHROOM_SAPLING, 15, 4, true)); public static final Block AMARANITA_CAP = registerBlock("amaranita_cap", new AmaranitaCapBlock()); - + public static final Block NEON_CACTUS = registerBlock("neon_cactus", new NeonCactusBlock()); - + // Crops public static final Block SHADOW_BERRY = registerBlock("shadow_berry", new ShadowBerryBlock()); - public static final Block BLOSSOM_BERRY = registerBlock("blossom_berry_seed", - new EndCropBlock(EndItems.BLOSSOM_BERRY, PINK_MOSS)); - public static final Block AMBER_ROOT = registerBlock("amber_root_seed", - new EndCropBlock(EndItems.AMBER_ROOT_RAW, AMBER_MOSS)); - public static final Block CHORUS_MUSHROOM = registerBlock("chorus_mushroom_seed", - new EndCropBlock(EndItems.CHORUS_MUSHROOM_RAW, CHORUS_NYLIUM)); - public static final Block PEARLBERRY = registerBlock("pearlberry_seed", - new EndCropBlock(EndItems.BLOSSOM_BERRY, END_MOSS, END_MYCELIUM)); + public static final Block BLOSSOM_BERRY = registerBlock("blossom_berry_seed", new EndCropBlock(EndItems.BLOSSOM_BERRY, PINK_MOSS)); + public static final Block AMBER_ROOT = registerBlock("amber_root_seed", new EndCropBlock(EndItems.AMBER_ROOT_RAW, AMBER_MOSS)); + public static final Block CHORUS_MUSHROOM = registerBlock("chorus_mushroom_seed", new EndCropBlock(EndItems.CHORUS_MUSHROOM_RAW, CHORUS_NYLIUM)); + public static final Block PEARLBERRY = registerBlock("pearlberry_seed", new EndCropBlock(EndItems.BLOSSOM_BERRY, END_MOSS, END_MYCELIUM)); public static final Block CAVE_PUMPKIN_SEED = registerBlock("cave_pumpkin_seed", new CavePumpkinVineBlock()); public static final Block CAVE_PUMPKIN = registerBlock("cave_pumpkin", new CavePumpkinBlock()); - + // Water plants public static final Block BUBBLE_CORAL = registerBlock("bubble_coral", new BubbleCoralBlock()); public static final Block MENGER_SPONGE = registerBlock("menger_sponge", new MengerSpongeBlock()); @@ -281,26 +223,24 @@ public class EndBlocks { public static final Block CHARNIA_LIGHT_BLUE = registerBlock("charnia_light_blue", new CharniaBlock()); public static final Block CHARNIA_CYAN = registerBlock("charnia_cyan", new CharniaBlock()); public static final Block CHARNIA_GREEN = registerBlock("charnia_green", new CharniaBlock()); - + public static final Block END_LILY = registerBlockNI("end_lily", new EndLilyBlock()); public static final Block END_LILY_SEED = registerBlock("end_lily_seed", new EndLilySeedBlock()); - - public static final Block HYDRALUX_SAPLING = registerBlock("hydralux_sapling", new HydraluxSaplingBlock()); + + public static final Block HYDRALUX_SAPLING = registerBlock("hydralux_sapling", new HydraluxSaplingBlock()); public static final Block HYDRALUX = registerBlockNI("hydralux", new HydraluxBlock()); public static final Block HYDRALUX_PETAL_BLOCK = registerBlock("hydralux_petal_block", new HydraluxPetalBlock()); - public static final ColoredMaterial HYDRALUX_PETAL_BLOCK_COLORED = new ColoredMaterial( - HydraluxPetalColoredBlock::new, HYDRALUX_PETAL_BLOCK, true); - + public static final ColoredMaterial HYDRALUX_PETAL_BLOCK_COLORED = new ColoredMaterial(HydraluxPetalColoredBlock::new, HYDRALUX_PETAL_BLOCK, true); + public static final Block POND_ANEMONE = registerBlock("pond_anemone", new PondAnemoneBlock()); - + public static final Block FLAMAEA = registerBlock("flamaea", new FlamaeaBlock()); - - public static final Block CAVE_BUSH = registerBlock("cave_bush", - new SimpleLeavesBlock(MaterialColor.COLOR_MAGENTA)); - + + public static final Block CAVE_BUSH = registerBlock("cave_bush", new SimpleLeavesBlock(MaterialColor.COLOR_MAGENTA)); + public static final Block MURKWEED = registerBlock("murkweed", new MurkweedBlock()); public static final Block NEEDLEGRASS = registerBlock("needlegrass", new NeedlegrassBlock()); - + // Wall Plants // public static final Block PURPLE_POLYPORE = registerBlock("purple_polypore", new WallMushroomBlock(13)); public static final Block AURANT_POLYPORE = registerBlock("aurant_polypore", new WallMushroomBlock(13)); @@ -311,7 +251,7 @@ public class EndBlocks { public static final Block BULB_MOSS = registerBlock("bulb_moss", new EndWallPlantBlock(12)); public static final Block JUNGLE_FERN = registerBlock("jungle_fern", new EndWallPlantBlock()); public static final Block RUSCUS = registerBlock("ruscus", new EndWallPlantBlock()); - + // Vines // public static final Block DENSE_VINE = registerBlock("dense_vine", new VineBlock(15, true)); public static final Block TWISTED_VINE = registerBlock("twisted_vine", new VineBlock()); @@ -323,71 +263,57 @@ public class EndBlocks { public static final Block FILALUX = registerBlock("filalux", new FilaluxBlock()); public static final Block FILALUX_WINGS = registerBlock("filalux_wings", new FilaluxWingsBlock()); public static final Block FILALUX_LANTERN = registerBlock("filalux_lantern", new FilaluxLanternBlock()); - + // Mob-Related public static final Block SILK_MOTH_NEST = registerBlock("silk_moth_nest", new SilkMothNestBlock()); public static final Block SILK_MOTH_HIVE = registerBlock("silk_moth_hive", new SilkMothHiveBlock()); - + // Ores // public static final Block ENDER_ORE = registerBlock("ender_ore", new EndOreBlock(EndItems.ENDER_SHARD, 1, 3, 5)); public static final Block AMBER_ORE = registerBlock("amber_ore", new EndOreBlock(EndItems.RAW_AMBER, 1, 2, 4)); - + // Materials // - public static final MetalMaterial THALLASIUM = MetalMaterial.makeNormal("thallasium", MaterialColor.COLOR_BLUE, - EndToolMaterial.THALLASIUM, EndArmorMaterial.THALLASIUM); - public static final MetalMaterial TERMINITE = MetalMaterial.makeOreless("terminite", MaterialColor.field_25708, 7F, - 9F, EndToolMaterial.TERMINITE, EndArmorMaterial.TERMINITE); + public static final MetalMaterial THALLASIUM = MetalMaterial.makeNormal("thallasium", MaterialColor.COLOR_BLUE, EndToolMaterial.THALLASIUM, EndArmorMaterial.THALLASIUM); + public static final MetalMaterial TERMINITE = MetalMaterial.makeOreless("terminite", MaterialColor.WARPED_WART_BLOCK, 7F, 9F, EndToolMaterial.TERMINITE, EndArmorMaterial.TERMINITE); public static final Block AETERNIUM_BLOCK = registerBlock("aeternium_block", new AeterniumBlock()); public static final Block CHARCOAL_BLOCK = registerBlock("charcoal_block", new CharcoalBlock()); - + public static final Block ENDER_BLOCK = registerBlock("ender_block", new EnderBlock()); public static final Block AURORA_CRYSTAL = registerBlock("aurora_crystal", new AuroraCrystalBlock()); public static final Block AMBER_BLOCK = registerBlock("amber_block", new AmberBlock()); public static final Block SMARAGDANT_CRYSTAL = registerBlock("smaragdant_crystal", new SmaragdantCrystalBlock()); - public static final CrystalSubblocksMaterial SMARAGDANT_SUBBLOCKS = new CrystalSubblocksMaterial( - "smaragdant_crystal", SMARAGDANT_CRYSTAL); - public static final Block SMARAGDANT_CRYSTAL_SHARD = registerBlock("smaragdant_crystal_shard", - new SmaragdantCrystalShardBlock()); - + public static final CrystalSubblocksMaterial SMARAGDANT_SUBBLOCKS = new CrystalSubblocksMaterial("smaragdant_crystal", SMARAGDANT_CRYSTAL); + public static final Block SMARAGDANT_CRYSTAL_SHARD = registerBlock("smaragdant_crystal_shard", new SmaragdantCrystalShardBlock()); + public static final Block RESPAWN_OBELISK = registerBlock("respawn_obelisk", new RespawnObeliskBlock()); - + // Lanterns - public static final Block ANDESITE_LANTERN = registerBlock("andesite_lantern", - new StoneLanternBlock(Blocks.ANDESITE)); + public static final Block ANDESITE_LANTERN = registerBlock("andesite_lantern", new StoneLanternBlock(Blocks.ANDESITE)); public static final Block DIORITE_LANTERN = registerBlock("diorite_lantern", new StoneLanternBlock(Blocks.DIORITE)); public static final Block GRANITE_LANTERN = registerBlock("granite_lantern", new StoneLanternBlock(Blocks.GRANITE)); - public static final Block QUARTZ_LANTERN = registerBlock("quartz_lantern", - new StoneLanternBlock(Blocks.QUARTZ_BLOCK)); - public static final Block PURPUR_LANTERN = registerBlock("purpur_lantern", - new StoneLanternBlock(Blocks.PURPUR_BLOCK)); - public static final Block END_STONE_LANTERN = registerBlock("end_stone_lantern", - new StoneLanternBlock(Blocks.END_STONE)); - public static final Block BLACKSTONE_LANTERN = registerBlock("blackstone_lantern", - new StoneLanternBlock(Blocks.BLACKSTONE)); - + public static final Block QUARTZ_LANTERN = registerBlock("quartz_lantern", new StoneLanternBlock(Blocks.QUARTZ_BLOCK)); + public static final Block PURPUR_LANTERN = registerBlock("purpur_lantern", new StoneLanternBlock(Blocks.PURPUR_BLOCK)); + public static final Block END_STONE_LANTERN = registerBlock("end_stone_lantern", new StoneLanternBlock(Blocks.END_STONE)); + public static final Block BLACKSTONE_LANTERN = registerBlock("blackstone_lantern", new StoneLanternBlock(Blocks.BLACKSTONE)); + public static final Block IRON_BULB_LANTERN = registerBlock("iron_bulb_lantern", new BulbVineLanternBlock()); - public static final ColoredMaterial IRON_BULB_LANTERN_COLORED = new ColoredMaterial( - BulbVineLanternColoredBlock::new, IRON_BULB_LANTERN, false); - - public static final Block IRON_CHANDELIER = EndBlocks.registerBlock("iron_chandelier", - new ChandelierBlock(Blocks.GOLD_BLOCK)); - public static final Block GOLD_CHANDELIER = EndBlocks.registerBlock("gold_chandelier", - new ChandelierBlock(Blocks.GOLD_BLOCK)); - + public static final ColoredMaterial IRON_BULB_LANTERN_COLORED = new ColoredMaterial(BulbVineLanternColoredBlock::new, IRON_BULB_LANTERN, false); + + public static final Block IRON_CHANDELIER = EndBlocks.registerBlock("iron_chandelier", new ChandelierBlock(Blocks.GOLD_BLOCK)); + public static final Block GOLD_CHANDELIER = EndBlocks.registerBlock("gold_chandelier", new ChandelierBlock(Blocks.GOLD_BLOCK)); + // Blocks With Entity // - public static final Block END_STONE_FURNACE = registerBlock("end_stone_furnace", - new EndFurnaceBlock(Blocks.END_STONE)); + public static final Block END_STONE_FURNACE = registerBlock("end_stone_furnace", new EndFurnaceBlock(Blocks.END_STONE)); public static final Block END_STONE_SMELTER = registerBlock("end_stone_smelter", new EndStoneSmelter()); public static final Block ETERNAL_PEDESTAL = registerBlock("eternal_pedestal", new EternalPedestal()); public static final Block INFUSION_PEDESTAL = registerBlock("infusion_pedestal", new InfusionPedestal()); public static final Block AETERNIUM_ANVIL = registerBlock("aeternium_anvil", new AeterniumAnvil()); - + // Technical public static final Block END_PORTAL_BLOCK = registerBlockNI("end_portal_block", new EndPortalBlock()); - - public static void register() { - } - + + public static void register() {} + public static Block registerBlock(ResourceLocation id, Block block) { if (!Configs.BLOCK_CONFIG.getBooleanRoot(id.getPath(), true)) { return block; @@ -402,17 +328,18 @@ public class EndBlocks { } Properties item = EndItems.makeBlockItemSettings().stacksTo(maxCount); if (placeOnWater) { - EndItems.registerBlockItem(id, new LilyPadItem(block, item)); - } else { + EndItems.registerBlockItem(id, new WaterLilyBlockItem(block, item)); + } + else { EndItems.registerBlockItem(id, new BlockItem(block, item)); } return block; } - + public static Block registerBlock(String name, Block block) { return registerBlock(BetterEnd.makeID(name), block); } - + public static Block registerBlockNI(String name, Block block) { return Registry.register(Registry.BLOCK, BetterEnd.makeID(name), block); } diff --git a/src/main/java/ru/betterend/registry/EndEntities.java b/src/main/java/ru/betterend/registry/EndEntities.java index a7864691..11e15d55 100644 --- a/src/main/java/ru/betterend/registry/EndEntities.java +++ b/src/main/java/ru/betterend/registry/EndEntities.java @@ -2,15 +2,15 @@ package ru.betterend.registry; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType.EntityFactory; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.SpawnGroup; -import net.minecraft.world.entity.attribute.DefaultAttributeContainer.Builder; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.ai.attributes.AttributeSupplier.Builder; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; import ru.betterend.entity.CubozoaEntity; @@ -23,25 +23,13 @@ import ru.betterend.util.MHelper; import ru.betterend.util.SpawnHelper; public class EndEntities { - public static final EntityType DRAGONFLY = register("dragonfly", SpawnGroup.AMBIENT, 0.6F, 0.5F, - DragonflyEntity::new, DragonflyEntity.createMobAttributes(), true, MHelper.color(32, 42, 176), - MHelper.color(115, 225, 249)); - public static final EntityType END_SLIME = register("end_slime", SpawnGroup.MONSTER, 2F, 2F, - EndSlimeEntity::new, EndSlimeEntity.createMobAttributes(), false, MHelper.color(28, 28, 28), - MHelper.color(99, 11, 99)); - public static final EntityType END_FISH = register("end_fish", SpawnGroup.WATER_AMBIENT, 0.5F, 0.5F, - EndFishEntity::new, EndFishEntity.createMobAttributes(), true, MHelper.color(3, 50, 76), - MHelper.color(120, 206, 255)); - public static final EntityType SHADOW_WALKER = register("shadow_walker", SpawnGroup.MONSTER, - 0.6F, 1.95F, ShadowWalkerEntity::new, ShadowWalkerEntity.createMobAttributes(), true, - MHelper.color(30, 30, 30), MHelper.color(5, 5, 5)); - public static final EntityType CUBOZOA = register("cubozoa", SpawnGroup.WATER_AMBIENT, 0.6F, 1F, - CubozoaEntity::new, CubozoaEntity.createMobAttributes(), true, MHelper.color(151, 77, 181), - MHelper.color(93, 176, 238)); - public static final EntityType SILK_MOTH = register("silk_moth", SpawnGroup.AMBIENT, 0.6F, 0.6F, - SilkMothEntity::new, SilkMothEntity.createMobAttributes(), true, MHelper.color(198, 138, 204), - MHelper.color(242, 220, 236)); - + public static final EntityType DRAGONFLY = register("dragonfly", MobCategory.AMBIENT, 0.6F, 0.5F, DragonflyEntity::new, DragonflyEntity.createMobAttributes(), true, MHelper.color(32, 42, 176), MHelper.color(115, 225, 249)); + public static final EntityType END_SLIME = register("end_slime", MobCategory.MONSTER, 2F, 2F, EndSlimeEntity::new, EndSlimeEntity.createMobAttributes(), false, MHelper.color(28, 28, 28), MHelper.color(99, 11, 99)); + public static final EntityType END_FISH = register("end_fish", MobCategory.WATER_AMBIENT, 0.5F, 0.5F, EndFishEntity::new, EndFishEntity.createMobAttributes(), true, MHelper.color(3, 50, 76), MHelper.color(120, 206, 255)); + public static final EntityType SHADOW_WALKER = register("shadow_walker", MobCategory.MONSTER, 0.6F, 1.95F, ShadowWalkerEntity::new, ShadowWalkerEntity.createMobAttributes(), true, MHelper.color(30, 30, 30), MHelper.color(5, 5, 5)); + public static final EntityType CUBOZOA = register("cubozoa", MobCategory.WATER_AMBIENT, 0.6F, 1F, CubozoaEntity::new, CubozoaEntity.createMobAttributes(), true, MHelper.color(151, 77, 181), MHelper.color(93, 176, 238)); + public static final EntityType SILK_MOTH = register("silk_moth", MobCategory.AMBIENT, 0.6F, 0.6F, SilkMothEntity::new, SilkMothEntity.createMobAttributes(), true, MHelper.color(198, 138, 204), MHelper.color(242, 220, 236)); + public static void register() { SpawnHelper.restrictionAir(DRAGONFLY, DragonflyEntity::canSpawn); SpawnHelper.restrictionLand(END_SLIME, EndSlimeEntity::canSpawn); @@ -50,25 +38,19 @@ public class EndEntities { SpawnHelper.restrictionWater(CUBOZOA, CubozoaEntity::canSpawn); SpawnHelper.restrictionAir(SILK_MOTH, SilkMothEntity::canSpawn); } - - protected static EntityType register(String name, SpawnGroup group, float width, float height, - EntityFactory entity) { + + protected static EntityType register(String name, MobCategory group, float width, float height, EntityFactory entity) { ResourceLocation id = BetterEnd.makeID(name); - EntityType type = FabricEntityTypeBuilder.create(group, entity) - .dimensions(EntityDimensions.fixed(width, height)).build(); + EntityType type = FabricEntityTypeBuilder.create(group, entity).dimensions(EntityDimensions.fixed(width, height)).build(); if (Configs.ENTITY_CONFIG.getBooleanRoot(id.getPath(), true)) { return Registry.register(Registry.ENTITY_TYPE, id, type); } return type; } - - private static EntityType register(String name, SpawnGroup group, float width, - float height, EntityFactory entity, Builder attributes, boolean fixedSize, int eggColor, int dotsColor) { + + private static EntityType register(String name, MobCategory group, float width, float height, EntityFactory entity, Builder attributes, boolean fixedSize, int eggColor, int dotsColor) { ResourceLocation id = BetterEnd.makeID(name); - EntityType type = FabricEntityTypeBuilder.create(group, entity) - .dimensions( - fixedSize ? EntityDimensions.fixed(width, height) : EntityDimensions.changing(width, height)) - .build(); + EntityType type = FabricEntityTypeBuilder.create(group, entity).dimensions(fixedSize ? EntityDimensions.fixed(width, height) : EntityDimensions.scalable(width, height)).build(); if (Configs.ENTITY_CONFIG.getBooleanRoot(id.getPath(), true)) { FabricDefaultAttributeRegistry.register(type, attributes); EndItems.registerEgg("spawn_egg_" + name, type, eggColor, dotsColor); diff --git a/src/main/java/ru/betterend/registry/EndEntitiesRenders.java b/src/main/java/ru/betterend/registry/EndEntitiesRenders.java index 5719b6f8..30384554 100644 --- a/src/main/java/ru/betterend/registry/EndEntitiesRenders.java +++ b/src/main/java/ru/betterend/registry/EndEntitiesRenders.java @@ -3,8 +3,8 @@ package ru.betterend.registry; import java.util.function.Function; import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; -import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.MobEntityRenderer; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.world.entity.EntityType; import ru.betterend.entity.render.RendererEntityCubozoa; import ru.betterend.entity.render.RendererEntityDragonfly; @@ -14,7 +14,7 @@ import ru.betterend.entity.render.RendererEntityShadowWalker; import ru.betterend.entity.render.SilkMothEntityRenderer; public class EndEntitiesRenders { - + public static void register() { register(EndEntities.DRAGONFLY, RendererEntityDragonfly::new); register(EndEntities.END_SLIME, RendererEntityEndSlime::new); @@ -23,8 +23,8 @@ public class EndEntitiesRenders { register(EndEntities.CUBOZOA, RendererEntityCubozoa::new); register(EndEntities.SILK_MOTH, SilkMothEntityRenderer::new); } - - private static void register(EntityType type, Function> render) { + + private static void register(EntityType type, Function> render) { EntityRendererRegistry.INSTANCE.register(type, (entityRenderDispatcher, context) -> { return render.apply(entityRenderDispatcher); }); diff --git a/src/main/java/ru/betterend/registry/EndFeatures.java b/src/main/java/ru/betterend/registry/EndFeatures.java index 1003ed6f..10fba6ad 100644 --- a/src/main/java/ru/betterend/registry/EndFeatures.java +++ b/src/main/java/ru/betterend/registry/EndFeatures.java @@ -2,14 +2,12 @@ package ru.betterend.registry; import java.util.List; import java.util.function.Supplier; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.Blocks; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import com.google.common.collect.Lists; import ru.betterend.BetterEnd; import ru.betterend.world.biome.BiomeDefinition; import ru.betterend.world.biome.EndBiome; @@ -74,263 +72,170 @@ import ru.betterend.world.generator.GeneratorOptions; public class EndFeatures { // Trees // - public static final EndFeature MOSSY_GLOWSHROOM = new EndFeature("mossy_glowshroom", new MossyGlowshroomFeature(), - 3); - public static final EndFeature PYTHADENDRON_TREE = new EndFeature("pythadendron_tree", - new PythadendronTreeFeature(), 2); + public static final EndFeature MOSSY_GLOWSHROOM = new EndFeature("mossy_glowshroom", new MossyGlowshroomFeature(), 3); + public static final EndFeature PYTHADENDRON_TREE = new EndFeature("pythadendron_tree", new PythadendronTreeFeature(), 2); public static final EndFeature LACUGROVE = new EndFeature("lacugrove", new LacugroveFeature(), 4); public static final EndFeature DRAGON_TREE = new EndFeature("dragon_tree", new DragonTreeFeature(), 3); public static final EndFeature TENANEA = new EndFeature("tenanea", new TenaneaFeature(), 3); public static final EndFeature HELIX_TREE = new EndFeature("helix_tree", new HelixTreeFeature(), 2); public static final EndFeature UMBRELLA_TREE = new EndFeature("umbrella_tree", new UmbrellaTreeFeature(), 4); public static final EndFeature JELLYSHROOM = new EndFeature("jellyshroom", new JellyshroomFeature(), 3); - public static final EndFeature GIGANTIC_AMARANITA = new EndFeature("gigantic_amaranita", - new GiganticAmaranitaFeature(), 1); + public static final EndFeature GIGANTIC_AMARANITA = new EndFeature("gigantic_amaranita", new GiganticAmaranitaFeature(), 1); public static final EndFeature LUCERNIA = new EndFeature("lucernia", new LucerniaFeature(), 3); - + // Bushes // - public static final EndFeature PYTHADENDRON_BUSH = new EndFeature("pythadendron_bush", - new BushFeature(EndBlocks.PYTHADENDRON_LEAVES, EndBlocks.PYTHADENDRON.bark), 4); - public static final EndFeature DRAGON_TREE_BUSH = new EndFeature("dragon_tree_bush", - new BushFeature(EndBlocks.DRAGON_TREE_LEAVES, EndBlocks.DRAGON_TREE.bark), 15); + public static final EndFeature PYTHADENDRON_BUSH = new EndFeature("pythadendron_bush", new BushFeature(EndBlocks.PYTHADENDRON_LEAVES, EndBlocks.PYTHADENDRON.bark), 4); + public static final EndFeature DRAGON_TREE_BUSH = new EndFeature("dragon_tree_bush", new BushFeature(EndBlocks.DRAGON_TREE_LEAVES, EndBlocks.DRAGON_TREE.bark), 15); public static final EndFeature TENANEA_BUSH = new EndFeature("tenanea_bush", new TenaneaBushFeature(), 10); public static final EndFeature LUMECORN = new EndFeature("lumecorn", new Lumecorn(), 5); public static final EndFeature LARGE_AMARANITA = new EndFeature("large_amaranita", new LargeAmaranitaFeature(), 5); - public static final EndFeature LUCERNIA_BUSH = new EndFeature("lucernia_bush", new BushWithOuterFeature( - EndBlocks.LUCERNIA_LEAVES, EndBlocks.LUCERNIA_OUTER_LEAVES, EndBlocks.LUCERNIA.bark), 10); + public static final EndFeature LUCERNIA_BUSH = new EndFeature("lucernia_bush", new BushWithOuterFeature(EndBlocks.LUCERNIA_LEAVES, EndBlocks.LUCERNIA_OUTER_LEAVES, EndBlocks.LUCERNIA.bark), 10); public static final EndFeature NEON_CACTUS = new EndFeature("neon_cactus", new NeonCactusFeature(), 2); - + // Plants // - public static final EndFeature UMBRELLA_MOSS = new EndFeature("umbrella_moss", - new DoublePlantFeature(EndBlocks.UMBRELLA_MOSS, EndBlocks.UMBRELLA_MOSS_TALL, 5), 5); - public static final EndFeature CREEPING_MOSS = new EndFeature("creeping_moss", - new SinglePlantFeature(EndBlocks.CREEPING_MOSS, 5), 5); + public static final EndFeature UMBRELLA_MOSS = new EndFeature("umbrella_moss", new DoublePlantFeature(EndBlocks.UMBRELLA_MOSS, EndBlocks.UMBRELLA_MOSS_TALL, 5), 5); + public static final EndFeature CREEPING_MOSS = new EndFeature("creeping_moss", new SinglePlantFeature(EndBlocks.CREEPING_MOSS, 5), 5); public static final EndFeature BLUE_VINE = new EndFeature("blue_vine", new BlueVineFeature(), 1); - public static final EndFeature CHORUS_GRASS = new EndFeature("chorus_grass", - new SinglePlantFeature(EndBlocks.CHORUS_GRASS, 4), 5); - public static final EndFeature CRYSTAL_GRASS = new EndFeature("crystal_grass", - new SinglePlantFeature(EndBlocks.CRYSTAL_GRASS, 8, false), 5); - public static final EndFeature SHADOW_PLANT = new EndFeature("shadow_plant", - new SinglePlantFeature(EndBlocks.SHADOW_PLANT, 6), 9); - public static final EndFeature MURKWEED = new EndFeature("murkweed", new SinglePlantFeature(EndBlocks.MURKWEED, 3), - 2); - public static final EndFeature NEEDLEGRASS = new EndFeature("needlegrass", - new SinglePlantFeature(EndBlocks.NEEDLEGRASS, 3), 2); - public static final EndFeature SHADOW_BERRY = new EndFeature("shadow_berry", - new SinglePlantFeature(EndBlocks.SHADOW_BERRY, 2), 1); - public static final EndFeature BUSHY_GRASS = new EndFeature("bushy_grass", - new SinglePlantFeature(EndBlocks.BUSHY_GRASS, 8, false), 20); - public static final EndFeature BUSHY_GRASS_WG = new EndFeature("bushy_grass_wg", - new SinglePlantFeature(EndBlocks.BUSHY_GRASS, 5), 10); - public static final EndFeature AMBER_GRASS = new EndFeature("amber_grass", - new SinglePlantFeature(EndBlocks.AMBER_GRASS, 6), 9); + public static final EndFeature CHORUS_GRASS = new EndFeature("chorus_grass", new SinglePlantFeature(EndBlocks.CHORUS_GRASS, 4), 5); + public static final EndFeature CRYSTAL_GRASS = new EndFeature("crystal_grass", new SinglePlantFeature(EndBlocks.CRYSTAL_GRASS, 8, false), 5); + public static final EndFeature SHADOW_PLANT = new EndFeature("shadow_plant", new SinglePlantFeature(EndBlocks.SHADOW_PLANT, 6), 9); + public static final EndFeature MURKWEED = new EndFeature("murkweed", new SinglePlantFeature(EndBlocks.MURKWEED, 3), 2); + public static final EndFeature NEEDLEGRASS = new EndFeature("needlegrass", new SinglePlantFeature(EndBlocks.NEEDLEGRASS, 3), 2); + public static final EndFeature SHADOW_BERRY = new EndFeature("shadow_berry", new SinglePlantFeature(EndBlocks.SHADOW_BERRY, 2), 1); + public static final EndFeature BUSHY_GRASS = new EndFeature("bushy_grass", new SinglePlantFeature(EndBlocks.BUSHY_GRASS, 8, false), 20); + public static final EndFeature BUSHY_GRASS_WG = new EndFeature("bushy_grass_wg", new SinglePlantFeature(EndBlocks.BUSHY_GRASS, 5), 10); + public static final EndFeature AMBER_GRASS = new EndFeature("amber_grass", new SinglePlantFeature(EndBlocks.AMBER_GRASS, 6), 9); public static final EndFeature LANCELEAF = new EndFeature("lanceleaf", new LanceleafFeature(), 3); public static final EndFeature GLOW_PILLAR = new EndFeature("glow_pillar", new GlowPillarFeature(), 1); - public static final EndFeature TWISTED_UMBRELLA_MOSS = new EndFeature("twisted_umbrella_moss", - new DoublePlantFeature(EndBlocks.TWISTED_UMBRELLA_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS_TALL, 6), 5); - public static final EndFeature JUNGLE_GRASS = new EndFeature("jungle_grass", - new SinglePlantFeature(EndBlocks.JUNGLE_GRASS, 7, 3), 8); - public static final EndFeature SMALL_JELLYSHROOM_FLOOR = new EndFeature("small_jellyshroom_floor", - new SinglePlantFeature(EndBlocks.SMALL_JELLYSHROOM, 5, 5), 4); - public static final EndFeature BLOSSOM_BERRY = new EndFeature("blossom_berry", - new SinglePlantFeature(EndBlocks.BLOSSOM_BERRY, 3, 3), 2); - public static final EndFeature BLOOMING_COOKSONIA = new EndFeature("blooming_cooksonia", - new SinglePlantFeature(EndBlocks.BLOOMING_COOKSONIA, 5), 5); - public static final EndFeature SALTEAGO = new EndFeature("salteago", new SinglePlantFeature(EndBlocks.SALTEAGO, 5), - 5); - public static final EndFeature VAIOLUSH_FERN = new EndFeature("vaiolush_fern", - new SinglePlantFeature(EndBlocks.VAIOLUSH_FERN, 5), 5); - public static final EndFeature FRACTURN = new EndFeature("fracturn", new SinglePlantFeature(EndBlocks.FRACTURN, 5), - 5); - public static final EndFeature UMBRELLA_MOSS_RARE = new EndFeature("umbrella_moss_rare", - new SinglePlantFeature(EndBlocks.UMBRELLA_MOSS, 3), 2); - public static final EndFeature CREEPING_MOSS_RARE = new EndFeature("creeping_moss_rare", - new SinglePlantFeature(EndBlocks.CREEPING_MOSS, 3), 2); - public static final EndFeature TWISTED_UMBRELLA_MOSS_RARE = new EndFeature("twisted_umbrella_moss_rare", - new SinglePlantFeature(EndBlocks.TWISTED_UMBRELLA_MOSS, 3), 2); + public static final EndFeature TWISTED_UMBRELLA_MOSS = new EndFeature("twisted_umbrella_moss", new DoublePlantFeature(EndBlocks.TWISTED_UMBRELLA_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS_TALL, 6), 5); + public static final EndFeature JUNGLE_GRASS = new EndFeature("jungle_grass", new SinglePlantFeature(EndBlocks.JUNGLE_GRASS, 7, 3), 8); + public static final EndFeature SMALL_JELLYSHROOM_FLOOR = new EndFeature("small_jellyshroom_floor", new SinglePlantFeature(EndBlocks.SMALL_JELLYSHROOM, 5, 5), 4); + public static final EndFeature BLOSSOM_BERRY = new EndFeature("blossom_berry", new SinglePlantFeature(EndBlocks.BLOSSOM_BERRY, 3, 3), 2); + public static final EndFeature BLOOMING_COOKSONIA = new EndFeature("blooming_cooksonia", new SinglePlantFeature(EndBlocks.BLOOMING_COOKSONIA, 5), 5); + public static final EndFeature SALTEAGO = new EndFeature("salteago", new SinglePlantFeature(EndBlocks.SALTEAGO, 5), 5); + public static final EndFeature VAIOLUSH_FERN = new EndFeature("vaiolush_fern", new SinglePlantFeature(EndBlocks.VAIOLUSH_FERN, 5), 5); + public static final EndFeature FRACTURN = new EndFeature("fracturn", new SinglePlantFeature(EndBlocks.FRACTURN, 5), 5); + public static final EndFeature UMBRELLA_MOSS_RARE = new EndFeature("umbrella_moss_rare", new SinglePlantFeature(EndBlocks.UMBRELLA_MOSS, 3), 2); + public static final EndFeature CREEPING_MOSS_RARE = new EndFeature("creeping_moss_rare", new SinglePlantFeature(EndBlocks.CREEPING_MOSS, 3), 2); + public static final EndFeature TWISTED_UMBRELLA_MOSS_RARE = new EndFeature("twisted_umbrella_moss_rare", new SinglePlantFeature(EndBlocks.TWISTED_UMBRELLA_MOSS, 3), 2); public static final EndFeature ORANGO = new EndFeature("orango", new SinglePlantFeature(EndBlocks.ORANGO, 5), 6); - public static final EndFeature AERIDIUM = new EndFeature("aeridium", - new SinglePlantFeature(EndBlocks.AERIDIUM, 5, 4), 5); - public static final EndFeature LUTEBUS = new EndFeature("lutebus", new SinglePlantFeature(EndBlocks.LUTEBUS, 5, 2), - 5); - public static final EndFeature LAMELLARIUM = new EndFeature("lamellarium", - new SinglePlantFeature(EndBlocks.LAMELLARIUM, 5), 6); - public static final EndFeature SMALL_AMARANITA = new EndFeature("small_amaranita", - new SinglePlantFeature(EndBlocks.SMALL_AMARANITA_MUSHROOM, 5, 5), 4); - public static final EndFeature GLOBULAGUS = new EndFeature("globulagus", - new SinglePlantFeature(EndBlocks.GLOBULAGUS, 5, 3), 6); - public static final EndFeature CLAWFERN = new EndFeature("clawfern", - new SinglePlantFeature(EndBlocks.CLAWFERN, 5, 4), 5); - public static final EndFeature BOLUX_MUSHROOM = new EndFeature("bolux_mushroom", - new SinglePlantFeature(EndBlocks.BOLUX_MUSHROOM, 5, 5), 2); - public static final EndFeature CHORUS_MUSHROOM = new EndFeature("chorus_mushroom", - new SinglePlantFeature(EndBlocks.CHORUS_MUSHROOM, 5, 5), 1); - public static final EndFeature AMBER_ROOT = new EndFeature("amber_root", - new SinglePlantFeature(EndBlocks.AMBER_ROOT, 5, 5), 1); - public static final EndFeature PEARLBERRY = new EndFeature("pearlberry", - new SinglePlantFeature(EndBlocks.PEARLBERRY, 5, 5), 1); - + public static final EndFeature AERIDIUM = new EndFeature("aeridium", new SinglePlantFeature(EndBlocks.AERIDIUM, 5, 4), 5); + public static final EndFeature LUTEBUS = new EndFeature("lutebus", new SinglePlantFeature(EndBlocks.LUTEBUS, 5, 2), 5); + public static final EndFeature LAMELLARIUM = new EndFeature("lamellarium", new SinglePlantFeature(EndBlocks.LAMELLARIUM, 5), 6); + public static final EndFeature SMALL_AMARANITA = new EndFeature("small_amaranita", new SinglePlantFeature(EndBlocks.SMALL_AMARANITA_MUSHROOM, 5, 5), 4); + public static final EndFeature GLOBULAGUS = new EndFeature("globulagus", new SinglePlantFeature(EndBlocks.GLOBULAGUS, 5, 3), 6); + public static final EndFeature CLAWFERN = new EndFeature("clawfern", new SinglePlantFeature(EndBlocks.CLAWFERN, 5, 4), 5); + public static final EndFeature BOLUX_MUSHROOM = new EndFeature("bolux_mushroom", new SinglePlantFeature(EndBlocks.BOLUX_MUSHROOM, 5, 5), 2); + public static final EndFeature CHORUS_MUSHROOM = new EndFeature("chorus_mushroom", new SinglePlantFeature(EndBlocks.CHORUS_MUSHROOM, 5, 5), 1); + public static final EndFeature AMBER_ROOT = new EndFeature("amber_root", new SinglePlantFeature(EndBlocks.AMBER_ROOT, 5, 5), 1); + public static final EndFeature PEARLBERRY = new EndFeature("pearlberry", new SinglePlantFeature(EndBlocks.PEARLBERRY, 5, 5), 1); + // Vines // - public static final EndFeature DENSE_VINE = new EndFeature("dense_vine", new VineFeature(EndBlocks.DENSE_VINE, 24), - 3); - public static final EndFeature TWISTED_VINE = new EndFeature("twisted_vine", - new VineFeature(EndBlocks.TWISTED_VINE, 24), 3); + public static final EndFeature DENSE_VINE = new EndFeature("dense_vine", new VineFeature(EndBlocks.DENSE_VINE, 24), 3); + public static final EndFeature TWISTED_VINE = new EndFeature("twisted_vine", new VineFeature(EndBlocks.TWISTED_VINE, 24), 3); public static final EndFeature BULB_VINE = new EndFeature("bulb_vine", new VineFeature(EndBlocks.BULB_VINE, 24), 5); - public static final EndFeature JUNGLE_VINE = new EndFeature("jungle_vine", - new VineFeature(EndBlocks.JUNGLE_VINE, 24), 5); - + public static final EndFeature JUNGLE_VINE = new EndFeature("jungle_vine", new VineFeature(EndBlocks.JUNGLE_VINE, 24), 5); + // Ceil plants - public static final EndFeature SMALL_JELLYSHROOM_CEIL = new EndFeature("small_jellyshroom_ceil", - new SingleInvertedScatterFeature(EndBlocks.SMALL_JELLYSHROOM, 8), 8); - + public static final EndFeature SMALL_JELLYSHROOM_CEIL = new EndFeature("small_jellyshroom_ceil", new SingleInvertedScatterFeature(EndBlocks.SMALL_JELLYSHROOM, 8), 8); + // Wall Plants // - public static final EndFeature PURPLE_POLYPORE = new EndFeature("purple_polypore", - new WallPlantOnLogFeature(EndBlocks.PURPLE_POLYPORE, 3), 5); - public static final EndFeature AURANT_POLYPORE = new EndFeature("aurant_polypore", - new WallPlantOnLogFeature(EndBlocks.AURANT_POLYPORE, 3), 5); - public static final EndFeature TAIL_MOSS = new EndFeature("tail_moss", new WallPlantFeature(EndBlocks.TAIL_MOSS, 3), - 15); - public static final EndFeature CYAN_MOSS = new EndFeature("cyan_moss", new WallPlantFeature(EndBlocks.CYAN_MOSS, 3), - 15); - public static final EndFeature TAIL_MOSS_WOOD = new EndFeature("tail_moss_wood", - new WallPlantOnLogFeature(EndBlocks.TAIL_MOSS, 4), 25); - public static final EndFeature CYAN_MOSS_WOOD = new EndFeature("cyan_moss_wood", - new WallPlantOnLogFeature(EndBlocks.CYAN_MOSS, 4), 25); - public static final EndFeature TWISTED_MOSS = new EndFeature("twisted_moss", - new WallPlantFeature(EndBlocks.TWISTED_MOSS, 6), 15); - public static final EndFeature TWISTED_MOSS_WOOD = new EndFeature("twisted_moss_wood", - new WallPlantOnLogFeature(EndBlocks.TWISTED_MOSS, 6), 25); - public static final EndFeature BULB_MOSS = new EndFeature("bulb_moss", new WallPlantFeature(EndBlocks.BULB_MOSS, 6), - 1); - public static final EndFeature BULB_MOSS_WOOD = new EndFeature("bulb_moss_wood", - new WallPlantOnLogFeature(EndBlocks.BULB_MOSS, 6), 15); - public static final EndFeature SMALL_JELLYSHROOM_WALL = new EndFeature("small_jellyshroom_wall", - new WallPlantFeature(EndBlocks.SMALL_JELLYSHROOM, 4), 4); - public static final EndFeature SMALL_JELLYSHROOM_WOOD = new EndFeature("small_jellyshroom_wood", - new WallPlantOnLogFeature(EndBlocks.SMALL_JELLYSHROOM, 4), 8); - public static final EndFeature JUNGLE_FERN_WOOD = new EndFeature("jungle_fern_wood", - new WallPlantOnLogFeature(EndBlocks.JUNGLE_FERN, 3), 12); + public static final EndFeature PURPLE_POLYPORE = new EndFeature("purple_polypore", new WallPlantOnLogFeature(EndBlocks.PURPLE_POLYPORE, 3), 5); + public static final EndFeature AURANT_POLYPORE = new EndFeature("aurant_polypore", new WallPlantOnLogFeature(EndBlocks.AURANT_POLYPORE, 3), 5); + public static final EndFeature TAIL_MOSS = new EndFeature("tail_moss", new WallPlantFeature(EndBlocks.TAIL_MOSS, 3), 15); + public static final EndFeature CYAN_MOSS = new EndFeature("cyan_moss", new WallPlantFeature(EndBlocks.CYAN_MOSS, 3), 15); + public static final EndFeature TAIL_MOSS_WOOD = new EndFeature("tail_moss_wood", new WallPlantOnLogFeature(EndBlocks.TAIL_MOSS, 4), 25); + public static final EndFeature CYAN_MOSS_WOOD = new EndFeature("cyan_moss_wood", new WallPlantOnLogFeature(EndBlocks.CYAN_MOSS, 4), 25); + public static final EndFeature TWISTED_MOSS = new EndFeature("twisted_moss", new WallPlantFeature(EndBlocks.TWISTED_MOSS, 6), 15); + public static final EndFeature TWISTED_MOSS_WOOD = new EndFeature("twisted_moss_wood", new WallPlantOnLogFeature(EndBlocks.TWISTED_MOSS, 6), 25); + public static final EndFeature BULB_MOSS = new EndFeature("bulb_moss", new WallPlantFeature(EndBlocks.BULB_MOSS, 6), 1); + public static final EndFeature BULB_MOSS_WOOD = new EndFeature("bulb_moss_wood", new WallPlantOnLogFeature(EndBlocks.BULB_MOSS, 6), 15); + public static final EndFeature SMALL_JELLYSHROOM_WALL = new EndFeature("small_jellyshroom_wall", new WallPlantFeature(EndBlocks.SMALL_JELLYSHROOM, 4), 4); + public static final EndFeature SMALL_JELLYSHROOM_WOOD = new EndFeature("small_jellyshroom_wood", new WallPlantOnLogFeature(EndBlocks.SMALL_JELLYSHROOM, 4), 8); + public static final EndFeature JUNGLE_FERN_WOOD = new EndFeature("jungle_fern_wood", new WallPlantOnLogFeature(EndBlocks.JUNGLE_FERN, 3), 12); public static final EndFeature RUSCUS = new EndFeature("ruscus", new WallPlantFeature(EndBlocks.RUSCUS, 6), 10); - public static final EndFeature RUSCUS_WOOD = new EndFeature("ruscus_wood", - new WallPlantOnLogFeature(EndBlocks.RUSCUS, 6), 10); - + public static final EndFeature RUSCUS_WOOD = new EndFeature("ruscus_wood", new WallPlantOnLogFeature(EndBlocks.RUSCUS, 6), 10); + // Sky plants public static final EndFeature FILALUX = new EndFeature("filalux", new FilaluxFeature(), 1); - + // Water // - public static final EndFeature BUBBLE_CORAL = new EndFeature("bubble_coral", - new UnderwaterPlantFeature(EndBlocks.BUBBLE_CORAL, 6), 10); - public static final EndFeature BUBBLE_CORAL_RARE = new EndFeature("bubble_coral_rare", - new UnderwaterPlantFeature(EndBlocks.BUBBLE_CORAL, 3), 4); + public static final EndFeature BUBBLE_CORAL = new EndFeature("bubble_coral", new UnderwaterPlantFeature(EndBlocks.BUBBLE_CORAL, 6), 10); + public static final EndFeature BUBBLE_CORAL_RARE = new EndFeature("bubble_coral_rare", new UnderwaterPlantFeature(EndBlocks.BUBBLE_CORAL, 3), 4); public static final EndFeature END_LILY = new EndFeature("end_lily", new EndLilyFeature(6), 10); public static final EndFeature END_LILY_RARE = new EndFeature("end_lily_rare", new EndLilyFeature(3), 4); public static final EndFeature END_LOTUS = new EndFeature("end_lotus", new EndLotusFeature(7), 5); public static final EndFeature END_LOTUS_LEAF = new EndFeature("end_lotus_leaf", new EndLotusLeafFeature(20), 25); public static final EndFeature HYDRALUX = new EndFeature("hydralux", new HydraluxFeature(5), 5); - public static final EndFeature POND_ANEMONE = new EndFeature("pond_anemone", - new UnderwaterPlantFeature(EndBlocks.POND_ANEMONE, 6), 10); - - public static final EndFeature CHARNIA_RED = new EndFeature("charnia_red", - new CharniaFeature(EndBlocks.CHARNIA_RED), 10); - public static final EndFeature CHARNIA_PURPLE = new EndFeature("charnia_purple", - new CharniaFeature(EndBlocks.CHARNIA_PURPLE), 10); - public static final EndFeature CHARNIA_CYAN = new EndFeature("charnia_cyan", - new CharniaFeature(EndBlocks.CHARNIA_CYAN), 10); - public static final EndFeature CHARNIA_LIGHT_BLUE = new EndFeature("charnia_light_blue", - new CharniaFeature(EndBlocks.CHARNIA_LIGHT_BLUE), 10); - public static final EndFeature CHARNIA_ORANGE = new EndFeature("charnia_orange", - new CharniaFeature(EndBlocks.CHARNIA_ORANGE), 10); - public static final EndFeature CHARNIA_GREEN = new EndFeature("charnia_green", - new CharniaFeature(EndBlocks.CHARNIA_GREEN), 10); + public static final EndFeature POND_ANEMONE = new EndFeature("pond_anemone", new UnderwaterPlantFeature(EndBlocks.POND_ANEMONE, 6), 10); + + public static final EndFeature CHARNIA_RED = new EndFeature("charnia_red", new CharniaFeature(EndBlocks.CHARNIA_RED), 10); + public static final EndFeature CHARNIA_PURPLE = new EndFeature("charnia_purple", new CharniaFeature(EndBlocks.CHARNIA_PURPLE), 10); + public static final EndFeature CHARNIA_CYAN = new EndFeature("charnia_cyan", new CharniaFeature(EndBlocks.CHARNIA_CYAN), 10); + public static final EndFeature CHARNIA_LIGHT_BLUE = new EndFeature("charnia_light_blue", new CharniaFeature(EndBlocks.CHARNIA_LIGHT_BLUE), 10); + public static final EndFeature CHARNIA_ORANGE = new EndFeature("charnia_orange", new CharniaFeature(EndBlocks.CHARNIA_ORANGE), 10); + public static final EndFeature CHARNIA_GREEN = new EndFeature("charnia_green", new CharniaFeature(EndBlocks.CHARNIA_GREEN), 10); public static final EndFeature MENGER_SPONGE = new EndFeature("menger_sponge", new MengerSpongeFeature(5), 1); - public static final EndFeature CHARNIA_RED_RARE = new EndFeature("charnia_red_rare", - new CharniaFeature(EndBlocks.CHARNIA_RED), 2); - public static final EndFeature BIOME_ISLAND = EndFeature.makeFeatureConfigured("overworld_island", - new BiomeIslandFeature()); - public static final EndFeature FLAMAEA = new EndFeature("flamaea", - new SinglePlantFeature(EndBlocks.FLAMAEA, 12, false, 5), 20); - + public static final EndFeature CHARNIA_RED_RARE = new EndFeature("charnia_red_rare", new CharniaFeature(EndBlocks.CHARNIA_RED), 2); + public static final EndFeature BIOME_ISLAND = EndFeature.makeFeatureConfigured("overworld_island", new BiomeIslandFeature()); + public static final EndFeature FLAMAEA = new EndFeature("flamaea", new SinglePlantFeature(EndBlocks.FLAMAEA, 12, false, 5), 20); + // Terrain // public static final EndFeature END_LAKE = EndFeature.makeLakeFeature("end_lake", new EndLakeFeature(), 4); - public static final EndFeature END_LAKE_NORMAL = EndFeature.makeLakeFeature("end_lake_normal", new EndLakeFeature(), - 20); - public static final EndFeature END_LAKE_RARE = EndFeature.makeLakeFeature("end_lake_rare", new EndLakeFeature(), - 40); + public static final EndFeature END_LAKE_NORMAL = EndFeature.makeLakeFeature("end_lake_normal", new EndLakeFeature(), 20); + public static final EndFeature END_LAKE_RARE = EndFeature.makeLakeFeature("end_lake_rare", new EndLakeFeature(), 40); public static final EndFeature ROUND_CAVE = EndFeature.makeRawGenFeature("round_cave", new RoundCaveFeature(), 2); public static final EndFeature SPIRE = EndFeature.makeRawGenFeature("spire", new SpireFeature(), 2); - public static final EndFeature FLOATING_SPIRE = EndFeature.makeRawGenFeature("floating_spire", - new FloatingSpireFeature(), 8); + public static final EndFeature FLOATING_SPIRE = EndFeature.makeRawGenFeature("floating_spire", new FloatingSpireFeature(), 8); public static final EndFeature GEYSER = EndFeature.makeRawGenFeature("geyser", new GeyserFeature(), 8); - public static final EndFeature SULPHURIC_LAKE = EndFeature.makeLakeFeature("sulphuric_lake", - new SulphuricLakeFeature(), 8); - public static final EndFeature SULPHURIC_CAVE = EndFeature.makeCountRawFeature("sulphuric_cave", - new SulphuricCaveFeature(), 2); - public static final EndFeature ICE_STAR = EndFeature.makeRawGenFeature("ice_star", - new IceStarFeature(5, 15, 10, 25), 15); - public static final EndFeature ICE_STAR_SMALL = EndFeature.makeRawGenFeature("ice_star_small", - new IceStarFeature(3, 5, 7, 12), 8); - public static final EndFeature SURFACE_VENT = EndFeature.makeChansedFeature("surface_vent", - new SurfaceVentFeature(), 4); - public static final EndFeature SULPHUR_HILL = EndFeature.makeChansedFeature("sulphur_hill", - new SulphurHillFeature(), 8); - public static final EndFeature OBSIDIAN_PILLAR_BASEMENT = EndFeature.makeChansedFeature("obsidian_pillar_basement", - new ObsidianPillarBasementFeature(), 8); - public static final EndFeature OBSIDIAN_BOULDER = EndFeature.makeChansedFeature("obsidian_boulder", - new ObsidianBoulderFeature(), 10); - public static final EndFeature FALLEN_PILLAR = EndFeature.makeChansedFeature("fallen_pillar", - new FallenPillarFeature(), 20); + public static final EndFeature SULPHURIC_LAKE = EndFeature.makeLakeFeature("sulphuric_lake", new SulphuricLakeFeature(), 8); + public static final EndFeature SULPHURIC_CAVE = EndFeature.makeCountRawFeature("sulphuric_cave", new SulphuricCaveFeature(), 2); + public static final EndFeature ICE_STAR = EndFeature.makeRawGenFeature("ice_star", new IceStarFeature(5, 15, 10, 25), 15); + public static final EndFeature ICE_STAR_SMALL = EndFeature.makeRawGenFeature("ice_star_small", new IceStarFeature(3, 5, 7, 12), 8); + public static final EndFeature SURFACE_VENT = EndFeature.makeChansedFeature("surface_vent", new SurfaceVentFeature(), 4); + public static final EndFeature SULPHUR_HILL = EndFeature.makeChansedFeature("sulphur_hill", new SulphurHillFeature(), 8); + public static final EndFeature OBSIDIAN_PILLAR_BASEMENT = EndFeature.makeChansedFeature("obsidian_pillar_basement", new ObsidianPillarBasementFeature(), 8); + public static final EndFeature OBSIDIAN_BOULDER = EndFeature.makeChansedFeature("obsidian_boulder", new ObsidianBoulderFeature(), 10); + public static final EndFeature FALLEN_PILLAR = EndFeature.makeChansedFeature("fallen_pillar", new FallenPillarFeature(), 20); public static final EndFeature TUNEL_CAVE = EndFeature.makeRawGenFeature("tunel_cave", new TunelCaveFeature(), 2); - + // Ores // - public static final EndFeature THALLASIUM_ORE = EndFeature.makeOreFeature("thallasium_ore", - EndBlocks.THALLASIUM.ore, 12, 6, 0, 16, 128); - public static final EndFeature ENDER_ORE = EndFeature.makeOreFeature("ender_ore", EndBlocks.ENDER_ORE, 8, 3, 0, 16, - 128); - public static final EndFeature AMBER_ORE = EndFeature.makeOreFeature("amber_ore", EndBlocks.AMBER_ORE, 12, 6, 0, 16, - 128); - public static final EndFeature VIOLECITE_LAYER = EndFeature.makeLayerFeature("violecite_layer", EndBlocks.VIOLECITE, - 15, 16, 128, 8); - public static final EndFeature FLAVOLITE_LAYER = EndFeature.makeLayerFeature("flavolite_layer", EndBlocks.FLAVOLITE, - 12, 16, 128, 6); - + public static final EndFeature THALLASIUM_ORE = EndFeature.makeOreFeature("thallasium_ore", EndBlocks.THALLASIUM.ore, 12, 6, 0, 16, 128); + public static final EndFeature ENDER_ORE = EndFeature.makeOreFeature("ender_ore", EndBlocks.ENDER_ORE, 8, 3, 0, 16, 128); + public static final EndFeature AMBER_ORE = EndFeature.makeOreFeature("amber_ore", EndBlocks.AMBER_ORE, 12, 6, 0, 16, 128); + public static final EndFeature VIOLECITE_LAYER = EndFeature.makeLayerFeature("violecite_layer", EndBlocks.VIOLECITE, 15, 16, 128, 8); + public static final EndFeature FLAVOLITE_LAYER = EndFeature.makeLayerFeature("flavolite_layer", EndBlocks.FLAVOLITE, 12, 16, 128, 6); + // Buildings - public static final EndFeature CRASHED_SHIP = EndFeature.makeChansedFeature("crashed_ship", - new CrashedShipFeature(), 500); - + public static final EndFeature CRASHED_SHIP = EndFeature.makeChansedFeature("crashed_ship", new CrashedShipFeature(), 500); + // Mobs - public static final EndFeature SILK_MOTH_NEST = EndFeature.makeChansedFeature("silk_moth_nest", - new SilkMothNestFeature(), 2); - + public static final EndFeature SILK_MOTH_NEST = EndFeature.makeChansedFeature("silk_moth_nest", new SilkMothNestFeature(), 2); + // Caves public static final DefaultFeature SMARAGDANT_CRYSTAL = new SmaragdantCrystalFeature(); - public static final DefaultFeature SMARAGDANT_CRYSTAL_SHARD = new SingleBlockFeature( - EndBlocks.SMARAGDANT_CRYSTAL_SHARD); + public static final DefaultFeature SMARAGDANT_CRYSTAL_SHARD = new SingleBlockFeature(EndBlocks.SMARAGDANT_CRYSTAL_SHARD); public static final DefaultFeature BIG_AURORA_CRYSTAL = new BigAuroraCrystalFeature(); public static final DefaultFeature CAVE_BUSH = new BushFeature(EndBlocks.CAVE_BUSH, EndBlocks.CAVE_BUSH); public static final DefaultFeature CAVE_GRASS = new SingleBlockFeature(EndBlocks.CAVE_GRASS); public static final DefaultFeature RUBINEA = new VineFeature(EndBlocks.RUBINEA, 8); public static final DefaultFeature MAGNULA = new VineFeature(EndBlocks.MAGNULA, 8); - public static final DefaultFeature END_STONE_STALACTITE = new StalactiteFeature(true, - EndBlocks.END_STONE_STALACTITE, Blocks.END_STONE); - public static final DefaultFeature END_STONE_STALAGMITE = new StalactiteFeature(false, - EndBlocks.END_STONE_STALACTITE, Blocks.END_STONE); - public static final DefaultFeature END_STONE_STALACTITE_CAVEMOSS = new StalactiteFeature(true, - EndBlocks.END_STONE_STALACTITE_CAVEMOSS, Blocks.END_STONE, EndBlocks.CAVE_MOSS); - public static final DefaultFeature END_STONE_STALAGMITE_CAVEMOSS = new StalactiteFeature(false, - EndBlocks.END_STONE_STALACTITE_CAVEMOSS, EndBlocks.CAVE_MOSS); + public static final DefaultFeature END_STONE_STALACTITE = new StalactiteFeature(true, EndBlocks.END_STONE_STALACTITE, Blocks.END_STONE); + public static final DefaultFeature END_STONE_STALAGMITE = new StalactiteFeature(false, EndBlocks.END_STONE_STALACTITE, Blocks.END_STONE); + public static final DefaultFeature END_STONE_STALACTITE_CAVEMOSS = new StalactiteFeature(true, EndBlocks.END_STONE_STALACTITE_CAVEMOSS, Blocks.END_STONE, EndBlocks.CAVE_MOSS); + public static final DefaultFeature END_STONE_STALAGMITE_CAVEMOSS = new StalactiteFeature(false, EndBlocks.END_STONE_STALACTITE_CAVEMOSS, EndBlocks.CAVE_MOSS); public static final DefaultFeature CAVE_PUMPKIN = new CavePumpkinFeature(); - - public static void registerBiomeFeatures(ResourceLocation id, Biome biome, - List>>> features) { + + public static void registerBiomeFeatures(ResourceLocation id, Biome biome, List>>> features) { if (id.getNamespace().equals(BetterEnd.MOD_ID)) { return; } - + if (GeneratorOptions.removeChorusFromVanillaBiomes()) { if (id.getNamespace().equals("minecraft")) { String path = id.getPath(); if (path.equals("end_highlands") || path.equals("end_midlands") || path.equals("small_end_islands")) { - int pos = GenerationStep.Feature.VEGETAL_DECORATION.ordinal(); + int pos = GenerationStep.Decoration.VEGETAL_DECORATION.ordinal(); if (pos < features.size()) { List>> list = features.get(pos); // If only chorus plants are enabled @@ -341,43 +246,44 @@ public class EndFeatures { } } } - + addFeature(FLAVOLITE_LAYER, features); addFeature(THALLASIUM_ORE, features); addFeature(ENDER_ORE, features); addFeature(CRASHED_SHIP, features); - + if (EndBiomes.getBiome(id).hasCaves()) { addFeature(ROUND_CAVE, features); addFeature(TUNEL_CAVE, features); } - + EndBiome endBiome = EndBiomes.getBiome(id); EndFeature feature = endBiome.getStructuresFeature(); if (feature != null) { addFeature(feature, features); } } - + public static void addDefaultFeatures(BiomeDefinition def) { def.addFeature(FLAVOLITE_LAYER); def.addFeature(THALLASIUM_ORE); def.addFeature(ENDER_ORE); def.addFeature(CRASHED_SHIP); - + if (def.hasCaves()) { def.addFeature(ROUND_CAVE); def.addFeature(TUNEL_CAVE); } } - + private static void addFeature(EndFeature feature, List>>> features) { int index = feature.getFeatureStep().ordinal(); if (features.size() > index) { features.get(index).add(() -> { return feature.getFeatureConfigured(); }); - } else { + } + else { List>> newFeature = Lists.newArrayList(); newFeature.add(() -> { return feature.getFeatureConfigured(); @@ -385,7 +291,6 @@ public class EndFeatures { features.add(newFeature); } } - - public static void register() { - } + + public static void register() {} } diff --git a/src/main/java/ru/betterend/registry/EndItems.java b/src/main/java/ru/betterend/registry/EndItems.java index cae4b4ed..0b35f495 100644 --- a/src/main/java/ru/betterend/registry/EndItems.java +++ b/src/main/java/ru/betterend/registry/EndItems.java @@ -5,23 +5,34 @@ import java.util.List; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.core.dispenser.DispenseItemBehavior; +import net.minecraft.core.BlockSource; +import net.minecraft.core.Direction; +import net.minecraft.core.Registry; +import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; +import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; +import net.minecraft.tags.Tag; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.food.FoodProperties; import net.minecraft.world.food.Foods; -import net.minecraft.world.item.*; -import net.minecraft.world.level.block.DispenserBlock; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.FishBucketItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Item.Properties; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Direction; -import net.minecraft.core.Registry; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.Rarity; +import net.minecraft.world.item.ShovelItem; +import net.minecraft.world.item.SpawnEggItem; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.TieredItem; +import net.minecraft.world.item.Tiers; +import net.minecraft.world.level.block.DispenserBlock; +import net.minecraft.world.level.material.Fluids; import ru.betterend.BetterEnd; import ru.betterend.config.Configs; import ru.betterend.item.DrinkItem; @@ -45,7 +56,7 @@ import ru.betterend.util.TagHelper; public class EndItems { private static final List MOD_BLOCKS = Lists.newArrayList(); private static final List MOD_ITEMS = Lists.newArrayList(); - + // Materials // public final static Item ENDER_DUST = registerItem("ender_dust"); public final static Item ENDER_SHARD = registerItem("ender_shard"); @@ -66,43 +77,28 @@ public class EndItems { public final static Item SILK_FIBER = registerItem("silk_fiber"); public final static Item LUMECORN_ROD = registerItem("lumecorn_rod"); public final static Item SILK_MOTH_MATRIX = registerItem("silk_moth_matrix"); - + // Music Discs - public final static Item MUSIC_DISC_STRANGE_AND_ALIEN = registerDisc("music_disc_strange_and_alien", 0, - EndSounds.STRANGE_AND_ALIEN); - + public final static Item MUSIC_DISC_STRANGE_AND_ALIEN = registerDisc("music_disc_strange_and_alien", 0, EndSounds.STRANGE_AND_ALIEN); + // Armor // - public static final Item AETERNIUM_HELMET = registerItem("aeternium_helmet", - new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.HEAD, makeItemSettings().fireResistant())); - public static final Item AETERNIUM_CHESTPLATE = registerItem("aeternium_chestplate", - new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.CHEST, makeItemSettings().fireResistant())); - public static final Item AETERNIUM_LEGGINGS = registerItem("aeternium_leggings", - new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.LEGS, makeItemSettings().fireResistant())); - public static final Item AETERNIUM_BOOTS = registerItem("aeternium_boots", - new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.FEET, makeItemSettings().fireResistant())); - public static final Item CRYSTALITE_HELMET = registerItem("crystalite_helmet", new EndArmorItem( - EndArmorMaterial.CRYSTALITE, EquipmentSlot.HEAD, makeItemSettings().rarity(Rarity.UNCOMMON))); - public static final Item CRYSTALITE_CHESTPLATE = registerItem("crystalite_chestplate", new EndArmorItem( - EndArmorMaterial.CRYSTALITE, EquipmentSlot.CHEST, makeItemSettings().rarity(Rarity.UNCOMMON))); - public static final Item CRYSTALITE_LEGGINGS = registerItem("crystalite_leggings", new EndArmorItem( - EndArmorMaterial.CRYSTALITE, EquipmentSlot.LEGS, makeItemSettings().rarity(Rarity.UNCOMMON))); - public static final Item CRYSTALITE_BOOTS = registerItem("crystalite_boots", new EndArmorItem( - EndArmorMaterial.CRYSTALITE, EquipmentSlot.FEET, makeItemSettings().rarity(Rarity.UNCOMMON))); - + public static final Item AETERNIUM_HELMET = registerItem("aeternium_helmet", new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.HEAD, makeItemSettings().fireResistant())); + public static final Item AETERNIUM_CHESTPLATE = registerItem("aeternium_chestplate", new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.CHEST, makeItemSettings().fireResistant())); + public static final Item AETERNIUM_LEGGINGS = registerItem("aeternium_leggings", new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.LEGS, makeItemSettings().fireResistant())); + public static final Item AETERNIUM_BOOTS = registerItem("aeternium_boots", new EndArmorItem(EndArmorMaterial.AETERNIUM, EquipmentSlot.FEET, makeItemSettings().fireResistant())); + public static final Item CRYSTALITE_HELMET = registerItem("crystalite_helmet", new EndArmorItem(EndArmorMaterial.CRYSTALITE, EquipmentSlot.HEAD, makeItemSettings().rarity(Rarity.UNCOMMON))); + public static final Item CRYSTALITE_CHESTPLATE = registerItem("crystalite_chestplate", new EndArmorItem(EndArmorMaterial.CRYSTALITE, EquipmentSlot.CHEST, makeItemSettings().rarity(Rarity.UNCOMMON))); + public static final Item CRYSTALITE_LEGGINGS = registerItem("crystalite_leggings", new EndArmorItem(EndArmorMaterial.CRYSTALITE, EquipmentSlot.LEGS, makeItemSettings().rarity(Rarity.UNCOMMON))); + public static final Item CRYSTALITE_BOOTS = registerItem("crystalite_boots", new EndArmorItem(EndArmorMaterial.CRYSTALITE, EquipmentSlot.FEET, makeItemSettings().rarity(Rarity.UNCOMMON))); + // Tools // - public static final TieredItem AETERNIUM_SHOVEL = registerTool("aeternium_shovel", - new EndShovelItem(EndToolMaterial.AETERNIUM, 1.5F, -3.0F, makeItemSettings().fireResistant())); - public static final TieredItem AETERNIUM_SWORD = registerTool("aeternium_sword", - new EndSwordItem(EndToolMaterial.AETERNIUM, 3, -2.4F, makeItemSettings().fireResistant())); - public static final TieredItem AETERNIUM_PICKAXE = registerTool("aeternium_pickaxe", - new EndPickaxeItem(EndToolMaterial.AETERNIUM, 1, -2.8F, makeItemSettings().fireResistant())); - public static final TieredItem AETERNIUM_AXE = registerTool("aeternium_axe", - new EndAxeItem(EndToolMaterial.AETERNIUM, 5.0F, -3.0F, makeItemSettings().fireResistant())); - public static final TieredItem AETERNIUM_HOE = registerTool("aeternium_hoe", - new EndHoeItem(EndToolMaterial.AETERNIUM, -3, 0.0F, makeItemSettings().fireResistant())); - public static final TieredItem AETERNIUM_HAMMER = registerTool("aeternium_hammer", - new EndHammerItem(EndToolMaterial.AETERNIUM, 6.0F, -3.0F, 0.3D, makeItemSettings().fireResistant())); - + public static final TieredItem AETERNIUM_SHOVEL = registerTool("aeternium_shovel", new EndShovelItem(EndToolMaterial.AETERNIUM, 1.5F, -3.0F, makeItemSettings().fireResistant())); + public static final TieredItem AETERNIUM_SWORD = registerTool("aeternium_sword", new EndSwordItem(EndToolMaterial.AETERNIUM, 3, -2.4F, makeItemSettings().fireResistant())); + public static final TieredItem AETERNIUM_PICKAXE = registerTool("aeternium_pickaxe", new EndPickaxeItem(EndToolMaterial.AETERNIUM, 1, -2.8F, makeItemSettings().fireResistant())); + public static final TieredItem AETERNIUM_AXE = registerTool("aeternium_axe", new EndAxeItem(EndToolMaterial.AETERNIUM, 5.0F, -3.0F, makeItemSettings().fireResistant())); + public static final TieredItem AETERNIUM_HOE = registerTool("aeternium_hoe", new EndHoeItem(EndToolMaterial.AETERNIUM, -3, 0.0F, makeItemSettings().fireResistant())); + public static final TieredItem AETERNIUM_HAMMER = registerTool("aeternium_hammer", new EndHammerItem(EndToolMaterial.AETERNIUM, 6.0F, -3.0F, 0.3D, makeItemSettings().fireResistant())); + // Toolparts // public final static Item AETERNIUM_SHOVEL_HEAD = registerItem("aeternium_shovel_head"); public final static Item AETERNIUM_PICKAXE_HEAD = registerItem("aeternium_pickaxe_head"); @@ -113,47 +109,41 @@ public class EndItems { public final static Item AETERNIUM_SWORD_HANDLE = registerItem("aeternium_sword_handle"); // Hammers // - public static final TieredItem IRON_HAMMER = registerTool("iron_hammer", - new EndHammerItem(Tiers.IRON, 5.0F, -3.2F, 0.2D, makeItemSettings())); - public static final TieredItem GOLDEN_HAMMER = registerTool("golden_hammer", - new EndHammerItem(Tiers.GOLD, 4.5F, -3.4F, 0.3D, makeItemSettings())); - public static final TieredItem DIAMOND_HAMMER = registerTool("diamond_hammer", - new EndHammerItem(Tiers.DIAMOND, 5.5F, -3.1F, 0.2D, makeItemSettings())); - public static final TieredItem NETHERITE_HAMMER = registerTool("netherite_hammer", - new EndHammerItem(Tiers.NETHERITE, 5.0F, -3.0F, 0.2D, makeItemSettings().fireResistant())); - + public static final TieredItem IRON_HAMMER = registerTool("iron_hammer", new EndHammerItem(Tiers.IRON, 5.0F, -3.2F, 0.2D, makeItemSettings())); + public static final TieredItem GOLDEN_HAMMER = registerTool("golden_hammer", new EndHammerItem(Tiers.GOLD, 4.5F, -3.4F, 0.3D, makeItemSettings())); + public static final TieredItem DIAMOND_HAMMER = registerTool("diamond_hammer", new EndHammerItem(Tiers.DIAMOND, 5.5F, -3.1F, 0.2D, makeItemSettings())); + public static final TieredItem NETHERITE_HAMMER = registerTool("netherite_hammer", new EndHammerItem(Tiers.NETHERITE, 5.0F, -3.0F, 0.2D, makeItemSettings().fireResistant())); + // Food // public final static Item SHADOW_BERRY_RAW = registerFood("shadow_berry_raw", 4, 0.5F); public final static Item SHADOW_BERRY_COOKED = registerFood("shadow_berry_cooked", 6, 0.7F); public final static Item END_FISH_RAW = registerFood("end_fish_raw", Foods.SALMON); public final static Item END_FISH_COOKED = registerFood("end_fish_cooked", Foods.COOKED_SALMON); - public final static Item BUCKET_END_FISH = registerItem("bucket_end_fish", - new FishBucketItem(EndEntities.END_FISH, Fluids.WATER, makeItemSettings().stacksTo(1))); + public final static Item BUCKET_END_FISH = registerItem("bucket_end_fish", new FishBucketItem(EndEntities.END_FISH, Fluids.WATER, makeItemSettings().stacksTo(1))); public final static Item SWEET_BERRY_JELLY = registerFood("sweet_berry_jelly", 6, 0.75F); - public final static Item SHADOW_BERRY_JELLY = registerFood("shadow_berry_jelly", 7, 0.75F, - new MobEffectInstance(MobEffects.NIGHT_VISION, 400)); + public final static Item SHADOW_BERRY_JELLY = registerFood("shadow_berry_jelly", 7, 0.75F, new MobEffectInstance(MobEffects.NIGHT_VISION, 400)); public final static Item BLOSSOM_BERRY = registerFood("blossom_berry", Foods.APPLE); public final static Item AMBER_ROOT_RAW = registerFood("amber_root_raw", 2, 0.8F); public final static Item CHORUS_MUSHROOM_RAW = registerFood("chorus_mushroom_raw", 3, 0.5F); public final static Item CHORUS_MUSHROOM_COOKED = registerFood("chorus_mushroom_cooked", Foods.MUSHROOM_STEW); public final static Item BOLUX_MUSHROOM_COOKED = registerFood("bolux_mushroom_cooked", Foods.MUSHROOM_STEW); public final static Item CAVE_PUMPKIN_PIE = registerFood("cave_pumpkin_pie", Foods.PUMPKIN_PIE); - + // Drinks // public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice", 5, 0.7F); - + public static Item registerDisc(String name, int power, SoundEvent sound) { return registerItem(BetterEnd.makeID(name), new PatternedDiscItem(power, sound, makeItemSettings())); } - + public static Item registerItem(String name) { return registerItem(BetterEnd.makeID(name), new PatternedItem(makeItemSettings())); } - + public static Item registerItem(String name, Item item) { return registerItem(BetterEnd.makeID(name), item); } - + public static Item registerItem(ResourceLocation id, Item item) { if (item instanceof ArmorItem) { return registerArmor(id, item); @@ -164,19 +154,19 @@ public class EndItems { registerItem(id, item, MOD_ITEMS); return item; } - + public static Item registerBlockItem(ResourceLocation id, Item item) { registerItem(id, item, MOD_BLOCKS); return item; } - + private static void registerItem(ResourceLocation id, Item item, List registry) { if (item != Items.AIR) { Registry.register(Registry.ITEM, id, item); registry.add(item); } } - + private static Item registerArmor(ResourceLocation id, Item item) { if (!Configs.ITEM_CONFIG.getBoolean("armor", id.getPath(), true)) { return item; @@ -184,14 +174,14 @@ public class EndItems { registerItem(id, item, MOD_ITEMS); return item; } - + public static TieredItem registerTool(String name, TieredItem item) { ResourceLocation id = BetterEnd.makeID(name); if (!Configs.ITEM_CONFIG.getBoolean("tools", id.getPath(), true)) { return item; } registerItem(id, item, MOD_ITEMS); - + if (item instanceof ShovelItem) { TagHelper.addTag((Tag.Named) FabricToolTags.SHOVELS, item); } else if (item instanceof SwordItem) { @@ -205,44 +195,45 @@ public class EndItems { } else if (item instanceof EndHammerItem) { TagHelper.addTag((Tag.Named) EndTags.HAMMERS, item); } - + return item; } - + public static Item registerEgg(String name, EntityType type, int background, int dots) { SpawnEggItem item = new EndSpawnEggItem(type, background, dots, makeItemSettings()); - DispenseItemBehavior behavior = (pointer, stack) -> { - Direction direction = pointer.getBlockState().getValue(DispenserBlock.FACING); - EntityType entityType = ((SpawnEggItem) stack.getItem()).getType(stack.getTag()); - entityType.spawn(pointer.getLevel(), stack, null, pointer.getPos().relative(direction), - MobSpawnType.DISPENSER, direction != Direction.UP, false); - stack.shrink(1); - return stack; + DefaultDispenseItemBehavior behavior = new DefaultDispenseItemBehavior() { + public ItemStack execute(BlockSource pointer, ItemStack stack) { + Direction direction = pointer.getBlockState().getValue(DispenserBlock.FACING); + EntityType entityType = ((SpawnEggItem) stack.getItem()).getType(stack.getTag()); + entityType.spawn(pointer.getLevel(), stack, null, pointer.getPos().relative(direction), MobSpawnType.DISPENSER, direction != Direction.UP, false); + stack.shrink(1); + return stack; + } }; DispenserBlock.registerBehavior(item, behavior); return registerItem(name, item); } - + public static Item registerFood(String name, int hunger, float saturation, MobEffectInstance... effects) { FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation); - for (MobEffectInstance effect : effects) { + for (MobEffectInstance effect: effects) { builder.effect(effect, 1F); } return registerFood(name, builder.build()); } - + public static Item registerFood(String name, FoodProperties foodComponent) { return registerItem(name, new PatternedItem(makeItemSettings().food(foodComponent))); } - + public static Item registerDrink(String name) { return registerItem(name, new DrinkItem(makeItemSettings().stacksTo(1))); } - + public static Item registerDrink(String name, FoodProperties foodComponent) { return registerItem(name, new DrinkItem(makeItemSettings().stacksTo(1).food(foodComponent))); } - + public static Item registerDrink(String name, int hunger, float saturation) { FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation); return registerDrink(name, builder.build()); @@ -251,14 +242,13 @@ public class EndItems { public static Properties makeItemSettings() { return new Item.Properties().tab(CreativeTabs.TAB_ITEMS); } - + public static Properties makeBlockItemSettings() { return new Item.Properties().tab(CreativeTabs.TAB_BLOCKS); } - public static void register() { - } - + public static void register() {} + public static List getModBlocks() { return MOD_BLOCKS; } diff --git a/src/main/java/ru/betterend/registry/EndParticles.java b/src/main/java/ru/betterend/registry/EndParticles.java index b08ef032..2fb673a6 100644 --- a/src/main/java/ru/betterend/registry/EndParticles.java +++ b/src/main/java/ru/betterend/registry/EndParticles.java @@ -2,10 +2,10 @@ package ru.betterend.registry; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.SimpleParticleType; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.particle.FireflyParticle; import ru.betterend.particle.InfusionParticle; @@ -23,8 +23,7 @@ import ru.betterend.particle.SmaragdantParticle; public class EndParticles { public static final SimpleParticleType GLOWING_SPHERE = register("glowing_sphere"); public static final SimpleParticleType PORTAL_SPHERE = register("portal_sphere"); - public static final ParticleType INFUSION = register("infusion", - FabricParticleTypes.complex(InfusionParticleType.PARAMETERS_FACTORY)); + public static final ParticleType INFUSION = register("infusion", FabricParticleTypes.complex(InfusionParticleType.PARAMETERS_FACTORY)); public static final SimpleParticleType SULPHUR_PARTICLE = register("sulphur_particle"); public static final SimpleParticleType GEYSER_PARTICLE = registerFar("geyser_particle"); public static final SimpleParticleType SNOWFLAKE = register("snowflake"); @@ -34,7 +33,7 @@ public class EndParticles { public static final SimpleParticleType JUNGLE_SPORE = register("jungle_spore"); public static final SimpleParticleType FIREFLY = register("firefly"); public static final SimpleParticleType SMARAGDANT = register("smaragdant_particle"); - + public static void register() { ParticleFactoryRegistry.getInstance().register(GLOWING_SPHERE, ParticleGlowingSphere.FactoryGlowingSphere::new); ParticleFactoryRegistry.getInstance().register(PORTAL_SPHERE, PaticlePortalSphere.FactoryPortalSphere::new); @@ -49,15 +48,15 @@ public class EndParticles { ParticleFactoryRegistry.getInstance().register(FIREFLY, FireflyParticle.FireflyParticleFactory::new); ParticleFactoryRegistry.getInstance().register(SMARAGDANT, SmaragdantParticle.SmaragdantParticleFactory::new); } - + private static SimpleParticleType register(String name) { return Registry.register(Registry.PARTICLE_TYPE, BetterEnd.makeID(name), FabricParticleTypes.simple()); } - + private static SimpleParticleType registerFar(String name) { return Registry.register(Registry.PARTICLE_TYPE, BetterEnd.makeID(name), FabricParticleTypes.simple(true)); } - + private static ParticleType register(String name, ParticleType type) { return Registry.register(Registry.PARTICLE_TYPE, BetterEnd.makeID(name), type); } diff --git a/src/main/java/ru/betterend/registry/EndPortals.java b/src/main/java/ru/betterend/registry/EndPortals.java index 1e7cce4b..81710747 100644 --- a/src/main/java/ru/betterend/registry/EndPortals.java +++ b/src/main/java/ru/betterend/registry/EndPortals.java @@ -4,10 +4,9 @@ import java.io.File; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; import ru.betterend.BetterEnd; import ru.betterend.config.ConfigWriter; @@ -16,10 +15,10 @@ import ru.betterend.util.MHelper; public class EndPortals { - public final static ResourceLocation OVERWORLD_ID = Level.OVERWORLD.getValue(); + public final static ResourceLocation OVERWORLD_ID = Level.OVERWORLD.location(); private static PortalInfo[] portals; - + public static void loadPortals() { File file = new File(ConfigWriter.MOD_CONFIG_DIR, "portals.json"); JsonObject json; @@ -42,16 +41,16 @@ public class EndPortals { portals[i] = new PortalInfo(array.get(i).getAsJsonObject()); } } - + public static int getCount() { return MHelper.max(portals.length - 1, 1); } - - public static ServerLevel getLevel(MinecraftServer server, int portalId) { + + public static ServerLevel getWorld(MinecraftServer server, int portalId) { if (portalId < 0 || portalId >= portals.length) { - return server.getOverworld(); + return server.overworld(); } - return portals[portalId].getLevel(server); + return portals[portalId].getWorld(server); } public static ResourceLocation getWorldId(int portalId) { @@ -60,7 +59,7 @@ public class EndPortals { } return portals[portalId].dimension; } - + public static int getPortalIdByItem(ResourceLocation item) { for (int i = 0; i < portals.length; i++) { if (portals[i].item.equals(item)) { @@ -69,7 +68,6 @@ public class EndPortals { } return 0; } - public static int getPortalIdByWorld(ResourceLocation world) { for (int i = 0; i < portals.length; i++) { if (portals[i].dimension.equals(world)) { @@ -78,11 +76,11 @@ public class EndPortals { } return 0; } - + public static int getColor(int state) { return portals[state].color; } - + public static boolean isAvailableItem(ResourceLocation item) { for (PortalInfo portal : portals) { if (portal.item.equals(item)) { @@ -91,7 +89,7 @@ public class EndPortals { } return false; } - + private static JsonObject makeDefault(File file) { JsonObject jsonObject = new JsonObject(); JsonFactory.storeJson(file, jsonObject); @@ -101,44 +99,46 @@ public class EndPortals { JsonFactory.storeJson(file, jsonObject); return jsonObject; } - + private static PortalInfo makeDefault() { - return new PortalInfo(new ResourceLocation("minecraft:overworld"), BetterEnd.makeID("eternal_crystal"), 255, - 255, 255); + return new PortalInfo(new ResourceLocation("minecraft:overworld"), BetterEnd.makeID("eternal_crystal"), 255, 255, 255); } - + private static class PortalInfo { private final ResourceLocation dimension; private final ResourceLocation item; private final int color; private ServerLevel world; - + PortalInfo(JsonObject obj) { - this(new ResourceLocation(JsonFactory.getString(obj, "dimension", "minecraft:overworld")), - new ResourceLocation(JsonFactory.getString(obj, "item", "betterend:eternal_crystal")), - JsonFactory.getInt(obj, "colorRed", 255), JsonFactory.getInt(obj, "colorGreen", 255), - JsonFactory.getInt(obj, "colorBlue", 255)); + this( + new ResourceLocation(JsonFactory.getString(obj, "dimension", "minecraft:overworld")), + new ResourceLocation(JsonFactory.getString(obj, "item", "betterend:eternal_crystal")), + JsonFactory.getInt(obj, "colorRed", 255), + JsonFactory.getInt(obj, "colorGreen", 255), + JsonFactory.getInt(obj, "colorBlue", 255) + ); } - + PortalInfo(ResourceLocation dimension, ResourceLocation item, int r, int g, int b) { this.dimension = dimension; this.item = item; this.color = MHelper.color(r, g, b); } - - ServerLevel getLevel(MinecraftServer server) { + + ServerLevel getWorld(MinecraftServer server) { if (world != null) { return world; } - for (ServerLevel world : server.getWorlds()) { + for (ServerLevel world : server.getAllLevels()) { if (world.dimension().location().equals(dimension)) { this.world = world; return world; } } - return server.getOverworld(); + return server.overworld(); } - + JsonObject toJson() { JsonObject obj = new JsonObject(); obj.addProperty("dimension", dimension.toString()); diff --git a/src/main/java/ru/betterend/registry/EndSounds.java b/src/main/java/ru/betterend/registry/EndSounds.java index b5962beb..7110cd17 100644 --- a/src/main/java/ru/betterend/registry/EndSounds.java +++ b/src/main/java/ru/betterend/registry/EndSounds.java @@ -1,7 +1,7 @@ package ru.betterend.registry; -import net.minecraft.sounds.SoundEvent; import net.minecraft.core.Registry; +import net.minecraft.sounds.SoundEvent; import ru.betterend.BetterEnd; public class EndSounds { @@ -10,7 +10,7 @@ public class EndSounds { public static final SoundEvent MUSIC_WATER = register("music", "water"); public static final SoundEvent MUSIC_DARK = register("music", "dark"); public static final SoundEvent MUSIC_OPENSPACE = register("music", "openspace"); - + // Ambient public static final SoundEvent AMBIENT_FOGGY_MUSHROOMLAND = register("ambient", "foggy_mushroomland"); public static final SoundEvent AMBIENT_CHORUS_FOREST = register("ambient", "chorus_forest"); @@ -21,19 +21,18 @@ public class EndSounds { public static final SoundEvent AMBIENT_SULPHUR_SPRINGS = register("ambient", "sulphur_springs"); public static final SoundEvent AMBIENT_UMBRELLA_JUNGLE = register("ambient", "umbrella_jungle"); public static final SoundEvent AMBIENT_GLOWING_GRASSLANDS = register("ambient", "glowing_grasslands"); - + // Entity public static final SoundEvent ENTITY_DRAGONFLY = register("entity", "dragonfly"); public static final SoundEvent ENTITY_SHADOW_WALKER = register("entity", "shadow_walker"); public static final SoundEvent ENTITY_SHADOW_WALKER_DAMAGE = register("entity", "shadow_walker_damage"); public static final SoundEvent ENTITY_SHADOW_WALKER_DEATH = register("entity", "shadow_walker_death"); - + // Records public static final SoundEvent STRANGE_AND_ALIEN = register("record", "strange_and_alien"); - - public static void register() { - } - + + public static void register() {} + private static SoundEvent register(String type, String id) { id = "betterend." + type + "." + id; return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(BetterEnd.makeID(id))); diff --git a/src/main/java/ru/betterend/registry/EndStructures.java b/src/main/java/ru/betterend/registry/EndStructures.java index bc11e4da..08d1b32a 100644 --- a/src/main/java/ru/betterend/registry/EndStructures.java +++ b/src/main/java/ru/betterend/registry/EndStructures.java @@ -2,13 +2,12 @@ package ru.betterend.registry; import java.util.Collection; import java.util.function.Supplier; - -import net.minecraft.structure.StructurePieceType; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.gen.GenerationStep.Feature; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.feature.StructurePieceType; import ru.betterend.BetterEnd; import ru.betterend.world.structures.EndStructureFeature; import ru.betterend.world.structures.features.EternalPortalStructure; @@ -30,43 +29,30 @@ public class EndStructures { public static final StructurePieceType MOUNTAIN_PIECE = register("mountain_piece", CrystalMountainPiece::new); public static final StructurePieceType CAVE_PIECE = register("cave_piece", CavePiece::new); public static final StructurePieceType LAKE_PIECE = register("lake_piece", LakePiece::new); - public static final StructurePieceType PAINTED_MOUNTAIN_PIECE = register("painted_mountain_piece", - PaintedMountainPiece::new); + public static final StructurePieceType PAINTED_MOUNTAIN_PIECE = register("painted_mountain_piece", PaintedMountainPiece::new); public static final StructurePieceType NBT_PIECE = register("nbt_piece", NBTPiece::new); - - public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", - new GiantMossyGlowshroomStructure(), Feature.SURFACE_STRUCTURES, 16, 8); - public static final EndStructureFeature MEGALAKE = new EndStructureFeature("megalake", new MegaLakeStructure(), - Feature.RAW_GENERATION, 4, 1); - public static final EndStructureFeature MEGALAKE_SMALL = new EndStructureFeature("megalake_small", - new MegaLakeSmallStructure(), Feature.RAW_GENERATION, 4, 1); - public static final EndStructureFeature MOUNTAIN = new EndStructureFeature("mountain", new MountainStructure(), - Feature.RAW_GENERATION, 3, 2); - public static final EndStructureFeature PAINTED_MOUNTAIN = new EndStructureFeature("painted_mountain", - new PaintedMountainStructure(), Feature.RAW_GENERATION, 3, 2); - public static final EndStructureFeature ETERNAL_PORTAL = new EndStructureFeature("eternal_portal", - new EternalPortalStructure(), Feature.SURFACE_STRUCTURES, 16, 6); - public static final EndStructureFeature GIANT_ICE_STAR = new EndStructureFeature("giant_ice_star", - new GiantIceStarStructure(), Feature.SURFACE_STRUCTURES, 16, 8); - - public static void register() { - } - + + public static final EndStructureFeature GIANT_MOSSY_GLOWSHROOM = new EndStructureFeature("giant_mossy_glowshroom", new GiantMossyGlowshroomStructure(), Decoration.SURFACE_STRUCTURES, 16, 8); + public static final EndStructureFeature MEGALAKE = new EndStructureFeature("megalake", new MegaLakeStructure(), Decoration.RAW_GENERATION, 4, 1); + public static final EndStructureFeature MEGALAKE_SMALL = new EndStructureFeature("megalake_small", new MegaLakeSmallStructure(), Decoration.RAW_GENERATION, 4, 1); + public static final EndStructureFeature MOUNTAIN = new EndStructureFeature("mountain", new MountainStructure(), Decoration.RAW_GENERATION, 3, 2); + public static final EndStructureFeature PAINTED_MOUNTAIN = new EndStructureFeature("painted_mountain", new PaintedMountainStructure(), Decoration.RAW_GENERATION, 3, 2); + public static final EndStructureFeature ETERNAL_PORTAL = new EndStructureFeature("eternal_portal", new EternalPortalStructure(), Decoration.SURFACE_STRUCTURES, 16, 6); + public static final EndStructureFeature GIANT_ICE_STAR = new EndStructureFeature("giant_ice_star", new GiantIceStarStructure(), Decoration.SURFACE_STRUCTURES, 16, 8); + + public static void register() {} + private static StructurePieceType register(String id, StructurePieceType pieceType) { return Registry.register(Registry.STRUCTURE_PIECE, BetterEnd.makeID(id), pieceType); } - - public static void registerBiomeStructures(ResourceLocation id, Biome biome, - Collection>> structures) { + + public static void registerBiomeStructures(ResourceLocation id, Biome biome, Collection>> structures) { if (!id.getPath().contains("mountain") && !id.getPath().contains("lake")) { addStructure(ETERNAL_PORTAL, structures); } } - - private static void addStructure(EndStructureFeature feature, - Collection>> structures) { - structures.add(() -> { - return feature.getFeatureConfigured(); - }); + + private static void addStructure(EndStructureFeature feature, Collection>> structures) { + structures.add(() -> { return feature.getFeatureConfigured(); }); } } diff --git a/src/main/java/ru/betterend/registry/EndTags.java b/src/main/java/ru/betterend/registry/EndTags.java index 46f7283f..e5238040 100644 --- a/src/main/java/ru/betterend/registry/EndTags.java +++ b/src/main/java/ru/betterend/registry/EndTags.java @@ -5,22 +5,22 @@ import java.util.Arrays; import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; import net.fabricmc.fabric.impl.tool.attribute.handlers.ModdedToolsVanillaBlocksToolHandler; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.food.FoodProperties; -import net.minecraft.world.item.Item; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; import net.minecraft.tags.Tag.Named; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.Category; -import net.minecraft.world.gen.surfacebuilder.SurfaceConfig; +import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.BetterEnd; import ru.betterend.blocks.EndTerrainBlock; import ru.betterend.blocks.basis.PedestalBlock; @@ -32,7 +32,7 @@ import ru.betterend.util.TagHelper; public class EndTags { // Table with common (c) tags: // https://fabricmc.net/wiki/tutorial:tags - + // Block Tags public static final Tag.Named BOOKSHELVES = makeCommonBlockTag("bookshelves"); public static final Tag.Named GEN_TERRAIN = makeBlockTag("gen_terrain"); @@ -41,114 +41,122 @@ public class EndTags { public static final Tag.Named BLOCK_CHEST = makeCommonBlockTag("chest"); public static final Tag.Named END_STONES = makeCommonBlockTag("end_stones"); public static final Tag.Named DRAGON_IMMUNE = getMCBlockTag("dragon_immune"); - + // Item Tags public static final Tag.Named ITEM_CHEST = makeCommonItemTag("chest"); public static final Tag.Named IRON_INGOTS = makeCommonItemTag("iron_ingots"); public static final Tag.Named FURNACES = makeCommonItemTag("furnaces"); public final static Tag HAMMERS = registerFabricItemTag("hammers"); - + public static Tag.Named makeBlockTag(String name) { ResourceLocation id = BetterEnd.makeID(name); - Tag tag = BlockTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.block(id) : (Identified) tag; + Tag tag = BlockTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; } - + public static Tag.Named makeItemTag(String name) { ResourceLocation id = BetterEnd.makeID(name); - Tag tag = ItemTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.item(id) : (Identified) tag; + Tag tag = ItemTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; } - + public static Tag.Named makeCommonBlockTag(String name) { ResourceLocation id = new ResourceLocation("c", name); - Tag tag = BlockTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.block(id) : (Identified) tag; + Tag tag = BlockTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; } - + public static Tag.Named makeCommonItemTag(String name) { ResourceLocation id = new ResourceLocation("c", name); - Tag tag = ItemTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.item(id) : (Identified) tag; + Tag tag = ItemTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; } - + public static Tag.Named getMCBlockTag(String name) { ResourceLocation id = new ResourceLocation(name); - Tag tag = BlockTags.getTagGroup().getTag(id); - return tag == null ? (Identified) TagRegistry.block(id) : (Identified) tag; + Tag tag = BlockTags.getAllTags().getTag(id); + return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; } - + public static void register() { addSurfaceBlock(Blocks.END_STONE); addSurfaceBlock(EndBlocks.THALLASIUM.ore); addSurfaceBlock(EndBlocks.ENDSTONE_DUST); addSurfaceBlock(EndBlocks.AMBER_ORE); - + EndItems.getModBlocks().forEach((item) -> { Block block = ((BlockItem) item).getBlock(); if (block instanceof EndTerrainBlock) { addSurfaceBlock(block); TagHelper.addTag(BlockTags.NYLIUM, block); - } else if (block instanceof LeavesBlock || block instanceof SimpleLeavesBlock) { + } + else if (block instanceof LeavesBlock || block instanceof SimpleLeavesBlock) { TagHelper.addTag(BlockTags.LEAVES, block); ComposterBlockAccessor.callRegisterCompostableItem(0.3F, block); - } else if (block instanceof VineBlock) { + } + else if (block instanceof VineBlock) { TagHelper.addTag(BlockTags.CLIMBABLE, block); - } else if (block instanceof PedestalBlock) { + } + else if (block instanceof PedestalBlock) { TagHelper.addTag(PEDESTALS, block); } - + Material mat = block.defaultBlockState().getMaterial(); if (mat.equals(Material.PLANT) || mat.equals(Material.REPLACEABLE_PLANT)) { ComposterBlockAccessor.callRegisterCompostableItem(0.1F, block); } }); - + EndItems.getModItems().forEach((item) -> { - if (item.isFood()) { - FoodProperties food = item.getFoodComponent(); - float compost = food.getHunger() * food.getSaturationModifier() * 0.18F; + if (item.isEdible()) { + FoodProperties food = item.getFoodProperties(); + float compost = food.getNutrition() * food.getSaturationModifier() * 0.18F; ComposterBlockAccessor.callRegisterCompostableItem(compost, item); } }); - - TagHelper.addTag(GEN_TERRAIN, EndBlocks.ENDER_ORE, EndBlocks.FLAVOLITE.stone, EndBlocks.VIOLECITE.stone, - EndBlocks.SULPHURIC_ROCK.stone, EndBlocks.BRIMSTONE); + + TagHelper.addTag(GEN_TERRAIN, EndBlocks.ENDER_ORE, EndBlocks.FLAVOLITE.stone, EndBlocks.VIOLECITE.stone, EndBlocks.SULPHURIC_ROCK.stone, EndBlocks.BRIMSTONE); TagHelper.addTag(END_GROUND, EndBlocks.SULPHURIC_ROCK.stone, EndBlocks.BRIMSTONE); - ToolManagerImpl.tag(HAMMERS) - .register(new ModdedToolsVanillaBlocksToolHandler(Arrays.asList(EndItems.IRON_HAMMER, - EndItems.GOLDEN_HAMMER, EndItems.DIAMOND_HAMMER, EndItems.NETHERITE_HAMMER, - EndItems.AETERNIUM_HAMMER, EndBlocks.THALLASIUM.hammer, EndBlocks.TERMINITE.hammer))); - + ToolManagerImpl.tag(HAMMERS).register(new ModdedToolsVanillaBlocksToolHandler( + Arrays.asList( + EndItems.IRON_HAMMER, + EndItems.GOLDEN_HAMMER, + EndItems.DIAMOND_HAMMER, + EndItems.NETHERITE_HAMMER, + EndItems.AETERNIUM_HAMMER, + EndBlocks.THALLASIUM.hammer, + EndBlocks.TERMINITE.hammer + ) + )); + TagHelper.addTag(FURNACES, Blocks.FURNACE); TagHelper.addTag(BlockTags.ANVIL, EndBlocks.AETERNIUM_ANVIL); - + TagHelper.addTag(BlockTags.BEACON_BASE_BLOCKS, EndBlocks.AETERNIUM_BLOCK); TagHelper.addTag(ItemTags.BEACON_PAYMENT_ITEMS, EndItems.AETERNIUM_INGOT); - - TagHelper.addTag(EndTags.DRAGON_IMMUNE, EndBlocks.ENDER_ORE, EndBlocks.ETERNAL_PEDESTAL, - EndBlocks.FLAVOLITE_RUNED_ETERNAL, EndBlocks.FLAVOLITE_RUNED); + + TagHelper.addTag(EndTags.DRAGON_IMMUNE, EndBlocks.ENDER_ORE, EndBlocks.ETERNAL_PEDESTAL, EndBlocks.FLAVOLITE_RUNED_ETERNAL, EndBlocks.FLAVOLITE_RUNED); } - + public static void addSurfaceBlock(Block block) { TagHelper.addTag(END_GROUND, block); TagHelper.addTag(GEN_TERRAIN, block); } - + public static void addTerrainTags(Registry biomeRegistry) { biomeRegistry.forEach((biome) -> { - if (biome.getCategory() == Category.THEEND) { - SurfaceConfig config = biome.getGenerationSettings().getSurfaceBuilderConfig(); + if (biome.getBiomeCategory() == BiomeCategory.THEEND) { + SurfaceBuilderConfiguration config = biome.getGenerationSettings().getSurfaceBuilderConfig(); Block under = config.getUnderMaterial().getBlock(); Block surface = config.getTopMaterial().getBlock(); TagHelper.addTag(GEN_TERRAIN, under, surface); TagHelper.addTag(END_GROUND, surface); } }); - END_STONES.values().forEach(EndTags::addSurfaceBlock); + END_STONES.getValues().forEach(EndTags::addSurfaceBlock); } - + public static Tag registerFabricItemTag(String name) { return TagRegistry.item(new ResourceLocation("fabric", name)); } diff --git a/src/main/java/ru/betterend/registry/FilaluxBlock.java b/src/main/java/ru/betterend/registry/FilaluxBlock.java index eeb40f93..4ca2c82f 100644 --- a/src/main/java/ru/betterend/registry/FilaluxBlock.java +++ b/src/main/java/ru/betterend/registry/FilaluxBlock.java @@ -1,15 +1,15 @@ package ru.betterend.registry; -import net.minecraft.world.level.block.AbstractBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import ru.betterend.blocks.basis.VineBlock; public class FilaluxBlock extends VineBlock { public FilaluxBlock() { super(15, true); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } } diff --git a/src/main/java/ru/betterend/registry/FilaluxWingsBlock.java b/src/main/java/ru/betterend/registry/FilaluxWingsBlock.java index 12a8e20b..12b7f789 100644 --- a/src/main/java/ru/betterend/registry/FilaluxWingsBlock.java +++ b/src/main/java/ru/betterend/registry/FilaluxWingsBlock.java @@ -6,43 +6,42 @@ import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.util.shape.VoxelShape; -import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.client.render.ERenderLayer; import ru.betterend.interfaces.IRenderTypeable; public class FilaluxWingsBlock extends AttachedBlock implements IRenderTypeable { private static final EnumMap BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); - + public FilaluxWingsBlock() { - super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS) - .noCollision()); + super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sound(SoundType.WET_GRASS).noCollission()); } @Override public ERenderLayer getRenderLayer() { return ERenderLayer.CUTOUT; } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return BOUNDING_SHAPES.get(state.getValue(FACING)); } - + static { - BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)); - BOUNDING_SHAPES.put(Direction.DOWN, VoxelShapes.cuboid(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.NORTH, VoxelShapes.cuboid(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.SOUTH, VoxelShapes.cuboid(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); - BOUNDING_SHAPES.put(Direction.WEST, VoxelShapes.cuboid(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); - BOUNDING_SHAPES.put(Direction.EAST, VoxelShapes.cuboid(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.UP, Shapes.box(0.0, 0.0, 0.0, 1.0, 0.5, 1.0)); + BOUNDING_SHAPES.put(Direction.DOWN, Shapes.box(0.0, 0.5, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(0.0, 0.0, 0.5, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.SOUTH, Shapes.box(0.0, 0.0, 0.0, 1.0, 1.0, 0.5)); + BOUNDING_SHAPES.put(Direction.WEST, Shapes.box(0.5, 0.0, 0.0, 1.0, 1.0, 1.0)); + BOUNDING_SHAPES.put(Direction.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0)); } } diff --git a/src/main/java/ru/betterend/registry/PondAnemoneBlock.java b/src/main/java/ru/betterend/registry/PondAnemoneBlock.java index 8b6073cb..4ac7e185 100644 --- a/src/main/java/ru/betterend/registry/PondAnemoneBlock.java +++ b/src/main/java/ru/betterend/registry/PondAnemoneBlock.java @@ -6,30 +6,34 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; -import net.minecraft.world.level.block.AbstractBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.block.ShapeContext; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.level.block.SoundType; import net.minecraft.core.BlockPos; -import net.minecraft.util.shape.VoxelShape; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import ru.betterend.blocks.basis.UnderwaterPlantBlock; public class PondAnemoneBlock extends UnderwaterPlantBlock { - private static final VoxelShape SHAPE = Block.createCuboidShape(2, 0, 2, 14, 14, 14); - + private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); + public PondAnemoneBlock() { - super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) - .sounds(SoundType.CORAL).breakByHand(true).luminance(13).noCollision()); + super(FabricBlockSettings.of(Material.WATER_PLANT) + .breakByTool(FabricToolTags.SHEARS) + .breakByHand(true) + .luminance(13) + .sound(SoundType.CORAL_BLOCK) + .noCollission()); } - + @Override - public AbstractBlock.OffsetType getOffsetType() { - return AbstractBlock.OffsetType.NONE; + public BlockBehaviour.OffsetType getOffsetType() { + return BlockBehaviour.OffsetType.NONE; } @Environment(EnvType.CLIENT) @@ -39,19 +43,19 @@ public class PondAnemoneBlock extends UnderwaterPlantBlock { double z = pos.getZ() + random.nextDouble(); world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D); } - + @Override - public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { + public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override - public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) { + public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return false; } @Override - public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return false; } } diff --git a/src/main/java/ru/betterend/rituals/EternalRitual.java b/src/main/java/ru/betterend/rituals/EternalRitual.java index 964cef7c..56e58413 100644 --- a/src/main/java/ru/betterend/rituals/EternalRitual.java +++ b/src/main/java/ru/betterend/rituals/EternalRitual.java @@ -8,35 +8,34 @@ import java.util.Set; import java.util.function.Predicate; import com.google.common.collect.Lists; -import net.minecraft.world.chunk.ChunkSection; -import net.minecraft.world.chunk.WorldChunk; import org.jetbrains.annotations.Nullable; import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.item.Item; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.core.particles.BlockStateParticleEffect; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.resources.ResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; -import net.minecraft.world.Heightmap; +import net.minecraft.core.particles.BlockParticleOption; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.data.worldgen.Features; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeatures; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.material.Material; import ru.betterend.BetterEnd; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.EndPortalBlock; @@ -47,15 +46,22 @@ import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndPortals; public class EternalRitual { - private final static Set STRUCTURE_MAP = Sets.newHashSet(new Point(-4, -5), new Point(-4, 5), - new Point(-6, 0), new Point(4, -5), new Point(4, 5), new Point(6, 0)); - private final static Set FRAME_MAP = Sets.newHashSet(new Point(0, 0), new Point(0, 6), new Point(1, 0), - new Point(1, 6), new Point(2, 1), new Point(2, 5), new Point(3, 2), new Point(3, 3), new Point(3, 4)); - private final static Set PORTAL_MAP = Sets.newHashSet(new Point(0, 0), new Point(0, 1), new Point(0, 2), - new Point(0, 3), new Point(0, 4), new Point(1, 0), new Point(1, 1), new Point(1, 2), new Point(1, 3), - new Point(1, 4), new Point(2, 1), new Point(2, 2), new Point(2, 3)); - private final static Set BASE_MAP = Sets.newHashSet(new Point(3, 0), new Point(2, 0), new Point(2, 1), - new Point(1, 1), new Point(1, 2), new Point(0, 1), new Point(0, 2)); + private final static Set STRUCTURE_MAP = Sets.newHashSet( + new Point(-4, -5), new Point(-4, 5), new Point(-6, 0), + new Point(4, -5), new Point(4, 5), new Point(6, 0)); + private final static Set FRAME_MAP = Sets.newHashSet( + new Point(0, 0), new Point(0, 6), new Point(1, 0), + new Point(1, 6), new Point(2, 1), new Point(2, 5), + new Point(3, 2), new Point(3, 3), new Point(3, 4)); + private final static Set PORTAL_MAP = Sets.newHashSet( + new Point(0, 0), new Point(0, 1), new Point(0, 2), + new Point(0, 3), new Point(0, 4), new Point(1, 0), + new Point(1, 1), new Point(1, 2), new Point(1, 3), + new Point(1, 4), new Point(2, 1), new Point(2, 2), + new Point(2, 3)); + private final static Set BASE_MAP = Sets.newHashSet( + new Point(3, 0), new Point(2, 0), new Point(2, 1), new Point(1, 1), + new Point(1, 2), new Point(0, 1), new Point(0, 2)); private final static Block BASE = EndBlocks.FLAVOLITE.tiles; private final static Block PEDESTAL = EndBlocks.ETERNAL_PEDESTAL; @@ -91,17 +97,18 @@ public class EternalRitual { } private boolean isInvalid() { - return world == null || world.isClientSide() || center == null || axis == null; + return world == null || world.isClientSide() || + center == null || axis == null; } public void checkStructure() { - if (isInvalid()) - return; + if (isInvalid()) return; Direction moveX, moveY; if (Direction.Axis.X == axis) { moveX = Direction.EAST; moveY = Direction.NORTH; - } else { + } + else { moveX = Direction.SOUTH; moveY = Direction.EAST; } @@ -114,7 +121,7 @@ public class EternalRitual { if (valid) { EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(checkPos); if (pedestal != null) { - Item pItem = pedestal.getStack(0).getItem(); + Item pItem = pedestal.getItem(0).getItem(); if (item == null) { item = pItem; } else if (!item.equals(pItem)) { @@ -147,9 +154,8 @@ public class EternalRitual { } private void activatePortal(Item keyItem) { - if (active) - return; - ResourceLocation itemId = Registry.ITEM.getId(keyItem); + if (active) return; + ResourceLocation itemId = Registry.ITEM.getKey(keyItem); int portalId = EndPortals.getPortalIdByItem(itemId); Level targetWorld = getTargetWorld(portalId); ResourceLocation worldId = targetWorld.dimension().location(); @@ -186,66 +192,59 @@ public class EternalRitual { if (Direction.Axis.X == axis) { moveX = Direction.EAST; moveY = Direction.NORTH; - } else { + } + else { moveX = Direction.SOUTH; moveY = Direction.EAST; } for (Point pos : STRUCTURE_MAP) { BlockPos.MutableBlockPos p = center.mutable(); p.move(moveX, pos.x).move(moveY, pos.y); - serverWorld.sendParticles(ParticleTypes.PORTAL, p.getX() + 0.5, p.getY() + 1.5, p.getZ() + 0.5, 20, 0, 0, 0, - 1); - serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, p.getX() + 0.5, p.getY() + 1.5, p.getZ() + 0.5, 20, - 0, 0, 0, 0.3); + serverWorld.sendParticles(ParticleTypes.PORTAL, p.getX() + 0.5, p.getY() + 1.5, p.getZ() + 0.5, 20, 0, 0, 0, 1); + serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, p.getX() + 0.5, p.getY() + 1.5, p.getZ() + 0.5, 20, 0, 0, 0, 0.3); } - serverWorld.playSound(null, center, SoundEvents.BLOCK_END_PORTAL_SPAWN, SoundSource.NEUTRAL, 16, 1); + serverWorld.playSound(null, center, SoundEvents.END_PORTAL_SPAWN, SoundSource.NEUTRAL, 16, 1); } private void activatePortal(Level world, BlockPos center, int portalId) { BlockPos framePos = center.below(); Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST; - BlockState frame = FRAME.defaultBlockState().with(ACTIVE, true); + BlockState frame = FRAME.defaultBlockState().setValue(ACTIVE, true); FRAME_MAP.forEach(point -> { BlockPos pos = framePos.mutable().move(moveDir, point.x).move(Direction.UP, point.y); BlockState state = world.getBlockState(pos); - if (state.contains(ACTIVE) && !state.getValue(ACTIVE)) { + if (state.hasProperty(ACTIVE) && !state.getValue(ACTIVE)) { world.setBlockAndUpdate(pos, frame); } pos = framePos.mutable().move(moveDir, -point.x).move(Direction.UP, point.y); state = world.getBlockState(pos); - if (state.contains(ACTIVE) && !state.getValue(ACTIVE)) { + if (state.hasProperty(ACTIVE) && !state.getValue(ACTIVE)) { world.setBlockAndUpdate(pos, frame); } }); Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X; - BlockState portal = PORTAL.defaultBlockState().with(EndPortalBlock.AXIS, portalAxis).with(EndPortalBlock.PORTAL, - portalId); - ParticleOptions effect = new BlockStateParticleEffect(ParticleTypes.BLOCK, portal); + BlockState portal = PORTAL.defaultBlockState().setValue(EndPortalBlock.AXIS, portalAxis).setValue(EndPortalBlock.PORTAL, portalId); + ParticleOptions effect = new BlockParticleOption(ParticleTypes.BLOCK, portal); ServerLevel serverWorld = (ServerLevel) world; PORTAL_MAP.forEach(point -> { BlockPos pos = center.mutable().move(moveDir, point.x).move(Direction.UP, point.y); if (!world.getBlockState(pos).is(PORTAL)) { world.setBlockAndUpdate(pos, portal); - serverWorld.sendParticles(effect, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, - 0.5, 0.1); - serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, pos.getX() + 0.5, pos.getY() + 0.5, - pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.3); + serverWorld.sendParticles(effect, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.1); + serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.3); } pos = center.mutable().move(moveDir, -point.x).move(Direction.UP, point.y); if (!world.getBlockState(pos).is(PORTAL)) { world.setBlockAndUpdate(pos, portal); - serverWorld.sendParticles(effect, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, - 0.5, 0.1); - serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, pos.getX() + 0.5, pos.getY() + 0.5, - pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.3); + serverWorld.sendParticles(effect, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.1); + serverWorld.sendParticles(ParticleTypes.REVERSE_PORTAL, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.5, 0.5, 0.5, 0.3); } }); } public void disablePortal(int state) { - if (!active || isInvalid()) - return; + if (!active || isInvalid()) return; removePortal(getTargetWorld(state), exit); removePortal(world, center); } @@ -257,12 +256,12 @@ public class EternalRitual { BlockPos pos = framePos.mutable().move(moveDir, point.x).move(Direction.UP, point.y); BlockState state = world.getBlockState(pos); if (state.is(FRAME) && state.getValue(ACTIVE)) { - world.setBlockAndUpdate(pos, state.with(ACTIVE, false)); + world.setBlockAndUpdate(pos, state.setValue(ACTIVE, false)); } pos = framePos.mutable().move(moveDir, -point.x).move(Direction.UP, point.y); state = world.getBlockState(pos); if (state.is(FRAME) && state.getValue(ACTIVE)) { - world.setBlockAndUpdate(pos, state.with(ACTIVE, false)); + world.setBlockAndUpdate(pos, state.setValue(ACTIVE, false)); } }); PORTAL_MAP.forEach(point -> { @@ -281,8 +280,8 @@ public class EternalRitual { @Nullable private BlockPos findFrame(Level world, BlockPos.MutableBlockPos startPos) { List foundPos = findAllBlockPos(world, startPos, (SEARCH_RADIUS >> 4) + 1, FRAME, - blockState -> blockState.is(FRAME) && !blockState.get(ACTIVE)); - for (BlockPos.MutableBlockPos testPos : foundPos) { + blockState -> blockState.is(FRAME) && !blockState.getValue(ACTIVE)); + for(BlockPos.MutableBlockPos testPos : foundPos) { if (checkFrame(world, testPos)) { return testPos; } @@ -295,14 +294,13 @@ public class EternalRitual { ServerLevel targetWorld = (ServerLevel) getTargetWorld(portalId); Registry registry = Objects.requireNonNull(server).registryAccess().dimensionTypes(); double multiplier = Objects.requireNonNull(registry.get(targetWorldId)).coordinateScale(); - BlockPos.MutableBlockPos basePos = center.mutable().set(center.getX() / multiplier, center.getY(), - center.getZ() / multiplier); + BlockPos.MutableBlockPos basePos = center.mutable().set(center.getX() / multiplier, center.getY(), center.getZ() / multiplier); BlockPos framePos = findFrame(targetWorld, basePos.mutable()); if (framePos != null) { - return framePos.up(); + return framePos.above(); } Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X; - int worldCeil = targetWorld.getDimensionHeight() - 1; + int worldCeil = targetWorld.getHeight() - 1; if (checkIsAreaValid(targetWorld, basePos, portalAxis)) { generatePortal(targetWorld, basePos, portalAxis, portalId); return basePos.immutable(); @@ -312,18 +310,15 @@ public class EternalRitual { int radius = (int) ((SEARCH_RADIUS / multiplier) + 1); for (int step = 1; step < radius; step++) { for (int i = 0; i < (step >> 1); i++) { - Chunk chunk = targetWorld.getChunk(checkPos); + ChunkAccess chunk = targetWorld.getChunk(checkPos); if (chunk != null) { - int surfaceY = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, - checkPos.getZ() & 15); - int motionY = chunk.sampleHeightmap(Heightmap.Type.MOTION_BLOCKING, checkPos.getX() & 15, - checkPos.getZ() & 15); + int surfaceY = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15); + int motionY = chunk.getHeight(Heightmap.Types.MOTION_BLOCKING, checkPos.getX() & 15, checkPos.getZ() & 15); int ceil = Math.min(Math.max(surfaceY, motionY) + 1, worldCeil); - if (ceil < 5) - continue; + if (ceil < 5) continue; checkPos.setY(ceil); while (checkPos.getY() >= 5) { - if (checkIsAreaValid(targetWorld, checkPos, portalAxis)) { + if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) { generatePortal(targetWorld, checkPos, portalAxis, portalId); return checkPos.immutable(); } @@ -336,44 +331,40 @@ public class EternalRitual { } } if (targetWorld.dimension() == Level.END) { - ConfiguredFeatures.END_ISLAND.generate(targetWorld, targetWorld.getChunkManager().getChunkGenerator(), - new Random(basePos.asLong()), basePos.below()); + Features.END_ISLAND.place(targetWorld, targetWorld.getChunkSource().getGenerator(), new Random(basePos.asLong()), basePos.below()); } else if (targetWorld.dimension() == Level.OVERWORLD) { - basePos.setY(targetWorld.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, basePos.getX(), - basePos.getZ()) + 1); + basePos.setY(targetWorld.getChunk(basePos).getHeight(Heightmap.Types.WORLD_SURFACE, basePos.getX(), basePos.getZ()) + 1); } - EndFeatures.BIOME_ISLAND.getFeatureConfigured().generate(targetWorld, - targetWorld.getChunkManager().getChunkGenerator(), new Random(basePos.asLong()), basePos.below()); + EndFeatures.BIOME_ISLAND.getFeatureConfigured().place(targetWorld, targetWorld.getChunkSource().getGenerator(), new Random(basePos.asLong()), basePos.below()); generatePortal(targetWorld, basePos, portalAxis, portalId); return basePos.immutable(); } private Level getTargetWorld(int state) { if (world.dimension() == Level.END) { - return EndPortals.getLevel(world.getServer(), state); + return EndPortals.getWorld(world.getServer(), state); } return Objects.requireNonNull(world.getServer()).getLevel(Level.END); } private boolean checkIsAreaValid(Level world, BlockPos pos, Direction.Axis axis) { - if (pos.getY() >= world.getDimensionHeight() - 1) - return false; - if (!isBaseValid(world, pos, axis)) - return false; + if (pos.getY() >= world.getHeight() - 1) return false; + if (!isBaseValid(world, pos, axis)) return false; return EternalRitual.checkArea(world, pos, axis); } private boolean isBaseValid(Level world, BlockPos pos, Direction.Axis axis) { boolean solid = true; if (axis.equals(Direction.Axis.X)) { - pos = pos.below().add(0, 0, -3); + pos = pos.below().offset(0, 0, -3); for (int i = 0; i < 7; i++) { BlockPos checkPos = pos.offset(0, 0, i); BlockState state = world.getBlockState(checkPos); solid &= validBlock(world, checkPos, state); } - } else { - pos = pos.below().add(-3, 0, 0); + } + else { + pos = pos.below().offset(-3, 0, 0); for (int i = 0; i < 7; i++) { BlockPos checkPos = pos.offset(i, 0, 0); BlockState state = world.getBlockState(checkPos); @@ -384,7 +375,7 @@ public class EternalRitual { } private boolean validBlock(Level world, BlockPos pos, BlockState state) { - return state.isSolidBlock(world, pos) && state.isFullCube(world, pos); + return state.isRedstoneConductor(world, pos) && state.isCollisionShapeFullBlock(world, pos); } public void configure(BlockPos initial) { @@ -481,24 +472,24 @@ public class EternalRitual { } public CompoundTag toTag(CompoundTag tag) { - tag.put("center", NbtHelper.fromBlockPos(center)); + tag.put("center", NbtUtils.writeBlockPos(center)); tag.putString("axis", axis.getName()); tag.putBoolean("active", active); if (targetWorldId != null) { tag.putString("key_item", targetWorldId.toString()); } if (exit != null) { - tag.put("exit", NbtHelper.fromBlockPos(exit)); + tag.put("exit", NbtUtils.writeBlockPos(exit)); } return tag; } public void fromTag(CompoundTag tag) { - axis = Direction.Axis.fromName(tag.getString("axis")); - center = NbtHelper.toBlockPos(tag.getCompound("center")); + axis = Direction.Axis.byName(tag.getString("axis")); + center = NbtUtils.readBlockPos(tag.getCompound("center")); active = tag.getBoolean("active"); if (tag.contains("exit")) { - exit = NbtHelper.toBlockPos(tag.getCompound("exit")); + exit = NbtUtils.readBlockPos(tag.getCompound("exit")); } if (tag.contains("key_item")) { targetWorldId = new ResourceLocation(tag.getString("key_item")); @@ -507,26 +498,25 @@ public class EternalRitual { @Override public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; EternalRitual ritual = (EternalRitual) o; - return world.equals(ritual.world) && Objects.equals(center, ritual.center) && Objects.equals(exit, ritual.exit); + return world.equals(ritual.world) && + Objects.equals(center, ritual.center) && + Objects.equals(exit, ritual.exit); } public static void generatePortal(Level world, BlockPos center, Direction.Axis axis, int portalId) { BlockPos framePos = center.below(); Direction moveDir = Direction.Axis.X == axis ? Direction.EAST : Direction.NORTH; - BlockState frame = FRAME.defaultBlockState().with(ACTIVE, true); + BlockState frame = FRAME.defaultBlockState().setValue(ACTIVE, true); FRAME_MAP.forEach(point -> { BlockPos pos = framePos.mutable().move(moveDir, point.x).move(Direction.UP, point.y); world.setBlockAndUpdate(pos, frame); pos = framePos.mutable().move(moveDir, -point.x).move(Direction.UP, point.y); world.setBlockAndUpdate(pos, frame); }); - BlockState portal = PORTAL.defaultBlockState().with(EndPortalBlock.AXIS, axis).with(EndPortalBlock.PORTAL, - portalId); + BlockState portal = PORTAL.defaultBlockState().setValue(EndPortalBlock.AXIS, axis).setValue(EndPortalBlock.PORTAL, portalId); PORTAL_MAP.forEach(point -> { BlockPos pos = center.mutable().move(moveDir, point.x).move(Direction.UP, point.y); world.setBlockAndUpdate(pos, portal); @@ -553,57 +543,50 @@ public class EternalRitual { public static boolean checkArea(Level world, BlockPos center, Direction.Axis axis) { Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST; - for (BlockPos checkPos : BlockPos.iterate(center.offset(moveDir.getClockWise()), - center.offset(moveDir.rotateYCounterclockwise()))) { + for (BlockPos checkPos : BlockPos.betweenClosed(center.relative(moveDir.getClockWise()), center.relative(moveDir.getCounterClockWise()))) { for (Point point : PORTAL_MAP) { BlockPos pos = checkPos.mutable().move(moveDir, point.x).move(Direction.UP, point.y); BlockState state = world.getBlockState(pos); - if (isStateInvalid(state)) - return false; + if (isStateInvalid(state)) return false; pos = checkPos.mutable().move(moveDir, -point.x).move(Direction.UP, point.y); state = world.getBlockState(pos); - if (isStateInvalid(state)) - return false; + if (isStateInvalid(state)) return false; } } return true; } private static boolean isStateInvalid(BlockState state) { - if (!state.getFluidState().isEmpty()) - return true; + if (!state.getFluidState().isEmpty()) return true; Material material = state.getMaterial(); return !material.isReplaceable() && !material.equals(Material.PLANT); } /** - * @param world Level for search - * @param checkPos Start search position - * @param radius Search radius + * @param world World for search + * @param checkPos Start search position + * @param radius Search radius * @param searchBlock Target block - * @param condition Predicate for test block states in the chunk section + * @param condition Predicate for test block states in the chunk section * * @return Position of the first found block or null. */ @Nullable - public static BlockPos.MutableBlockPos findBlockPos(Level world, BlockPos.MutableBlockPos checkPos, int radius, - Block searchBlock, Predicate condition) { + public static BlockPos.MutableBlockPos findBlockPos(Level world, BlockPos.MutableBlockPos checkPos, int radius, Block searchBlock, Predicate condition) { Direction moveDirection = Direction.EAST; for (int step = 1; step < radius; step++) { for (int i = 0; i < (step >> 1); i++) { - Chunk chunk = world.getChunk(checkPos); - if (!(chunk instanceof WorldChunk) || ((WorldChunk) chunk).isEmpty()) - continue; - for (ChunkSection section : chunk.getSectionArray()) { - if (section == null || !section.getContainer().hasAny(condition)) - continue; + ChunkAccess chunk = world.getChunk(checkPos); + if (!(chunk instanceof LevelChunk) || ((LevelChunk) chunk).isEmpty()) continue; + for (LevelChunkSection section : chunk.getSections()) { + if (section == null || !section.getStates().maybeHas(condition)) continue; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { + for(int z = 0; z < 16; z++) { BlockState checkState = section.getBlockState(x, y, z); if (checkState.is(searchBlock)) { int worldX = (chunk.getPos().x << 4) + x; - int worldY = section.getYOffset() + y; + int worldY = section.bottomBlockY() + y; int worldZ = (chunk.getPos().z << 4) + z; checkPos.set(worldX, worldY, worldZ); return checkPos; @@ -620,33 +603,30 @@ public class EternalRitual { } /** - * @param world Level for search - * @param checkPos Start search position - * @param radius Search radius + * @param world World for search + * @param checkPos Start search position + * @param radius Search radius * @param searchBlock Target block - * @param condition Predicate for test block states in the chunk section + * @param condition Predicate for test block states in the chunk section * * @return List of positions of the all found blocks or empty list. */ - public static List findAllBlockPos(Level world, BlockPos.MutableBlockPos checkPos, - int radius, Block searchBlock, Predicate condition) { + public static List findAllBlockPos(Level world, BlockPos.MutableBlockPos checkPos, int radius, Block searchBlock, Predicate condition) { List posFound = Lists.newArrayList(); Direction moveDirection = Direction.EAST; for (int step = 1; step < radius; step++) { for (int i = 0; i < (step >> 1); i++) { - Chunk chunk = world.getChunk(checkPos); - if (!(chunk instanceof WorldChunk) || ((WorldChunk) chunk).isEmpty()) - continue; - for (ChunkSection section : chunk.getSectionArray()) { - if (section == null || !section.getContainer().hasAny(condition)) - continue; + ChunkAccess chunk = world.getChunk(checkPos); + if (!(chunk instanceof LevelChunk) || ((LevelChunk) chunk).isEmpty()) continue; + for (LevelChunkSection section : chunk.getSections()) { + if (section == null || !section.getStates().maybeHas(condition)) continue; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { + for(int z = 0; z < 16; z++) { BlockState checkState = section.getBlockState(x, y, z); if (checkState.is(searchBlock)) { int worldX = (chunk.getPos().x << 4) + x; - int worldY = section.getYOffset() + y; + int worldY = section.bottomBlockY() + y; int worldZ = (chunk.getPos().z << 4) + z; checkPos.set(worldX, worldY, worldZ); posFound.add(checkPos.mutable()); diff --git a/src/main/java/ru/betterend/rituals/InfusionRitual.java b/src/main/java/ru/betterend/rituals/InfusionRitual.java index fc589e14..9939c3cf 100644 --- a/src/main/java/ru/betterend/rituals/InfusionRitual.java +++ b/src/main/java/ru/betterend/rituals/InfusionRitual.java @@ -1,24 +1,25 @@ package ru.betterend.rituals; import java.awt.Point; - -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.inventory.Inventory; -import net.minecraft.world.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.level.ServerLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.PedestalBlockEntity; import ru.betterend.particle.InfusionParticleType; import ru.betterend.recipe.builders.InfusionRecipe; -public class InfusionRitual implements Inventory { - private static final Point[] PEDESTALS_MAP = new Point[] { new Point(0, 3), new Point(2, 2), new Point(3, 0), - new Point(2, -2), new Point(0, -3), new Point(-2, -2), new Point(-3, 0), new Point(-2, 2) }; +public class InfusionRitual implements Container { + private static final Point[] PEDESTALS_MAP = new Point[] { + new Point(0, 3), new Point(2, 2), new Point(3, 0), new Point(2, -2), + new Point(0, -3), new Point(-2, -2), new Point(-3, 0), new Point(-2, 2) + }; private Level world; private BlockPos worldPos; @@ -27,31 +28,29 @@ public class InfusionRitual implements Inventory { private boolean hasRecipe = false; private int progress = 0; private int time = 0; - + private InfusionPedestalEntity input; private final PedestalBlockEntity[] catalysts = new PedestalBlockEntity[8]; - + public InfusionRitual(Level world, BlockPos pos) { this.world = world; this.worldPos = pos; this.configure(); } - + public static Point[] getMap() { return PEDESTALS_MAP; } - + public void configure() { - if (world == null || world.isClientSide || worldPos == null) - return; + if (world == null || world.isClientSide || worldPos == null) return; BlockEntity inputEntity = world.getBlockEntity(worldPos); if (inputEntity instanceof InfusionPedestalEntity) { input = (InfusionPedestalEntity) inputEntity; } int i = 0; - for (Point point : PEDESTALS_MAP) { - BlockPos.MutableBlockPos checkPos = worldPos.mutable().move(Direction.EAST, point.x).move(Direction.NORTH, - point.y); + for(Point point : PEDESTALS_MAP) { + BlockPos.MutableBlockPos checkPos = worldPos.mutable().move(Direction.EAST, point.x).move(Direction.NORTH, point.y); BlockEntity catalystEntity = world.getBlockEntity(checkPos); if (catalystEntity instanceof PedestalBlockEntity) { catalysts[i] = (PedestalBlockEntity) catalystEntity; @@ -61,11 +60,10 @@ public class InfusionRitual implements Inventory { } } } - + public boolean checkRecipe() { - if (!isValid()) - return false; - InfusionRecipe recipe = world.getRecipeManager().getFirstMatch(InfusionRecipe.TYPE, this, world).orElse(null); + if (!isValid()) return false; + InfusionRecipe recipe = world.getRecipeManager().getRecipeFor(InfusionRecipe.TYPE, this, world).orElse(null); if (hasRecipe()) { if (recipe == null) { stop(); @@ -74,7 +72,7 @@ public class InfusionRitual implements Inventory { activeRecipe = recipe; time = activeRecipe.getInfusionTime(); progress = 0; - markDirty(); + setChanged(); } else if (activeRecipe == null) { activeRecipe = recipe; } @@ -85,47 +83,45 @@ public class InfusionRitual implements Inventory { time = activeRecipe.getInfusionTime(); hasRecipe = true; progress = 0; - markDirty(); + setChanged(); return true; } return false; } - + public void stop() { activeRecipe = null; hasRecipe = false; progress = 0; time = 0; - markDirty(); + setChanged(); } - + public void tick() { if (isDirty) { configure(); isDirty = false; } - if (!isValid() || !hasRecipe()) - return; - if (!checkRecipe()) - return; + if (!isValid() || !hasRecipe()) return; + if (!checkRecipe()) return; progress++; if (progress == time) { - input.removeStack(0); - input.setStack(0, activeRecipe.craft(this)); + input.removeItemNoUpdate(0); + input.setItem(0, activeRecipe.assemble(this)); for (PedestalBlockEntity catalyst : catalysts) { - catalyst.removeStack(0); + catalyst.removeItemNoUpdate(0); } stop(); } else { ServerLevel world = (ServerLevel) this.world; - BlockPos target = worldPos.up(); + BlockPos target = worldPos.above(); double tx = target.getX() + 0.5; double ty = target.getY() + 0.5; double tz = target.getZ() + 0.5; for (PedestalBlockEntity catalyst : catalysts) { - ItemStack stack = catalyst.getStack(0); + ItemStack stack = catalyst.getItem(0); if (!stack.isEmpty()) { - BlockPos start = catalyst.getPos(); + BlockPos start = catalyst.getBlockPos(); double sx = start.getX() + 0.5; double sy = start.getY() + 1.25; double sz = start.getZ() + 0.5; @@ -133,24 +129,22 @@ public class InfusionRitual implements Inventory { } } } - + } - + @Override - public boolean isValid(int slot, ItemStack stack) { + public boolean canPlaceItem(int slot, ItemStack stack) { return isValid(); } - + public boolean isValid() { - if (world == null || world.isClientSide || worldPos == null || input == null) - return false; + if (world == null || world.isClientSide || worldPos == null || input == null) return false; for (PedestalBlockEntity catalyst : catalysts) { - if (catalyst == null) - return false; + if (catalyst == null) return false; } return true; } - + public boolean hasRecipe() { return hasRecipe; } @@ -162,17 +156,16 @@ public class InfusionRitual implements Inventory { } @Override - public void clear() { - if (!isValid()) - return; - input.clear(); + public void clearContent() { + if (!isValid()) return; + input.clearContent(); for (PedestalBlockEntity catalyst : catalysts) { - catalyst.clear(); + catalyst.clearContent(); } } @Override - public int size() { + public int getContainerSize() { return 9; } @@ -182,58 +175,55 @@ public class InfusionRitual implements Inventory { } @Override - public ItemStack getStack(int slot) { - if (slot > 8) - return ItemStack.EMPTY; + public ItemStack getItem(int slot) { + if (slot > 8) return ItemStack.EMPTY; if (slot == 0) { - return input.getStack(0); + return input.getItem(0); } else { - return catalysts[slot - 1].getStack(0); + return catalysts[slot - 1].getItem(0); } } @Override - public ItemStack removeStack(int slot, int amount) { - return removeStack(slot); + public ItemStack removeItem(int slot, int amount) { + return removeItemNoUpdate(slot); } @Override - public ItemStack removeStack(int slot) { - if (slot > 8) - return ItemStack.EMPTY; + public ItemStack removeItemNoUpdate(int slot) { + if (slot > 8) return ItemStack.EMPTY; if (slot == 0) { - return input.removeStack(0); + return input.removeItemNoUpdate(0); } else { - return catalysts[slot - 1].removeStack(0); + return catalysts[slot - 1].removeItemNoUpdate(0); } } @Override - public void setStack(int slot, ItemStack stack) { - if (slot > 8) - return; + public void setItem(int slot, ItemStack stack) { + if (slot > 8) return; if (slot == 0) { - input.setStack(0, stack); + input.setItem(0, stack); } else { - catalysts[slot - 1].setStack(0, stack); + catalysts[slot - 1].setItem(0, stack); } } @Override - public void markDirty() { + public void setChanged() { if (isValid()) { - input.markDirty(); + input.setChanged(); for (PedestalBlockEntity catalyst : catalysts) { - catalyst.markDirty(); + catalyst.setChanged(); } } } @Override - public boolean canPlayerUse(Player player) { + public boolean stillValid(Player player) { return true; } - + public void fromTag(CompoundTag tag) { if (tag.contains("recipe")) { hasRecipe = tag.getBoolean("recipe"); diff --git a/src/main/java/ru/betterend/util/BlocksHelper.java b/src/main/java/ru/betterend/util/BlocksHelper.java index 580a5b7e..84e3ec12 100644 --- a/src/main/java/ru/betterend/util/BlocksHelper.java +++ b/src/main/java/ru/betterend/util/BlocksHelper.java @@ -5,24 +5,22 @@ import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.Set; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.FallingBlock; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.Property; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Vec3i; +import net.minecraft.tags.BlockTags; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FallingBlock; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.Property; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import ru.betterend.blocks.BlueVineBlock; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.blocks.basis.FurBlock; @@ -32,9 +30,9 @@ import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; public class BlocksHelper { - public static final BooleanProperty ROOTS = BooleanProperty.of("roots"); + public static final BooleanProperty ROOTS = BooleanProperty.create("roots"); private static final Map COLOR_BY_BLOCK = Maps.newHashMap(); - + public static final int FLAG_UPDATE_BLOCK = 1; public static final int FLAG_SEND_CLIENT_CHANGES = 2; public static final int FLAG_NO_RERENDER = 4; @@ -45,92 +43,97 @@ public class BlocksHelper { public static final int SET_OBSERV = FLAG_UPDATE_BLOCK | FLAG_SEND_CLIENT_CHANGES; public static final Direction[] HORIZONTAL = makeHorizontal(); public static final Direction[] DIRECTIONS = Direction.values(); - + private static final MutableBlockPos POS = new MutableBlockPos(); protected static final BlockState AIR = Blocks.AIR.defaultBlockState(); protected static final BlockState WATER = Blocks.WATER.defaultBlockState(); - private static final Vec3i[] OFFSETS = new Vec3i[] { new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), - new Vec3i(-1, -1, 1), new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), new Vec3i(-1, 1, -1), - new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1), + private static final Vec3i[] OFFSETS = new Vec3i[] { + new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1), + new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), + new Vec3i(-1, 1, -1), new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1), - new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), - new Vec3i(0, 0, 1), new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1), - - new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), - new Vec3i(1, 0, 1), new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) }; + new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), + new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), new Vec3i(0, 0, 1), + new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1), + new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), + new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1), + new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) + }; + public static void addBlockColor(Block block, int color) { COLOR_BY_BLOCK.put(block, color); } - + public static int getBlockColor(Block block) { return COLOR_BY_BLOCK.getOrDefault(block, 0xFF000000); } public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, BlockState state) { - world.setBlockAndUpdate(pos, state, SET_SILENT); + world.setBlock(pos, state, SET_SILENT); } - + public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, Block block) { - world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_SILENT); + world.setBlock(pos, block.defaultBlockState(), SET_SILENT); } - + public static void setWithUpdate(LevelAccessor world, BlockPos pos, BlockState state) { - world.setBlockAndUpdate(pos, state, SET_OBSERV); + world.setBlock(pos, state, SET_OBSERV); } - + public static void setWithUpdate(LevelAccessor world, BlockPos pos, Block block) { - world.setBlockAndUpdate(pos, block.defaultBlockState(), SET_OBSERV); + world.setBlock(pos, block.defaultBlockState(), SET_OBSERV); } public static int upRay(LevelAccessor world, BlockPos pos, int maxDist) { int length = 0; - for (int j = 1; j < maxDist && (world.isAir(pos.up(j))); j++) + for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.above(j))); j++) length++; return length; } public static int downRay(LevelAccessor world, BlockPos pos, int maxDist) { int length = 0; - for (int j = 1; j < maxDist && (world.isAir(pos.down(j))); j++) + for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.below(j))); j++) length++; return length; } - + public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) { POS.set(pos); - for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { + for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) + { POS.setY(POS.getY() - 1); } return pos.getY() - POS.getY(); } - + public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) { POS.set(pos); - for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { + for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) + { POS.move(dx, dy, dz); } - return (int) pos.getSquaredDistance(POS); + return (int) pos.distSqr(POS); } public static BlockState rotateHorizontal(BlockState state, Rotation rotation, Property facing) { - return state.with(facing, rotation.rotate(state.getValue(facing))); + return state.setValue(facing, rotation.rotate(state.getValue(facing))); } - public static BlockState mirrorHorizontal(BlockState state, BlockMirror mirror, Property facing) { + public static BlockState mirrorHorizontal(BlockState state, Mirror mirror, Property facing) { return state.rotate(mirror.getRotation(state.getValue(facing))); } public static int getLengthDown(LevelAccessor world, BlockPos pos, Block block) { int count = 1; - while (world.getBlockState(pos.down(count)).getBlock() == block) + while (world.getBlockState(pos.below(count)).getBlock() == block) count++; return count; } - public static void cover(LevelAccessor world, BlockPos center, Block ground, BlockState cover, int radius, - Random random) { + public static void cover(LevelAccessor world, BlockPos center, Block ground, BlockState cover, int radius, Random random) { HashSet points = new HashSet(); HashSet points2 = new HashSet(); if (world.getBlockState(center).getBlock() == ground) { @@ -159,7 +162,7 @@ public class BlocksHelper { } } } - + public static void fixBlocks(LevelAccessor world, BlockPos start, BlockPos end) { BlockState state; Set doubleCheck = Sets.newHashSet(); @@ -170,17 +173,17 @@ public class BlocksHelper { for (int y = start.getY(); y <= end.getY(); y++) { POS.setY(y); state = world.getBlockState(POS); - + if (state.getBlock() instanceof FurBlock) { doubleCheck.add(POS.immutable()); } // Liquids else if (!state.getFluidState().isEmpty()) { - if (!state.canPlaceAt(world, POS)) { + if (!state.canSurvive(world, POS)) { setWithoutUpdate(world, POS, WATER); POS.setY(POS.getY() - 1); state = world.getBlockState(POS); - while (!state.canPlaceAt(world, POS)) { + while (!state.canSurvive(world, POS)) { state = state.getFluidState().isEmpty() ? AIR : WATER; setWithoutUpdate(world, POS, state); POS.setY(POS.getY() - 1); @@ -188,7 +191,7 @@ public class BlocksHelper { } } POS.setY(y - 1); - if (world.isAir(POS)) { + if (world.isEmptyBlock(POS)) { POS.setY(y); while (!world.getFluidState(POS).isEmpty()) { setWithoutUpdate(world, POS, AIR); @@ -197,14 +200,15 @@ public class BlocksHelper { continue; } for (Direction dir : HORIZONTAL) { - if (world.isAir(POS.offset(dir))) { - world.getFluidTickScheduler().schedule(POS, state.getFluidState().getFluid(), 0); + if (world.isEmptyBlock(POS.relative(dir))) { + world.getLiquidTicks().scheduleTick(POS, state.getFluidState().getType(), 0); break; } } - } else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) { + } + else if (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) { POS.setY(POS.getY() - 1); - if (world.isAir(POS)) { + if (world.isEmptyBlock(POS)) { POS.setY(POS.getY() + 1); while (state.is(EndBlocks.SMARAGDANT_CRYSTAL)) { setWithoutUpdate(world, POS, AIR); @@ -212,15 +216,17 @@ public class BlocksHelper { state = world.getBlockState(POS); } } - } else if (state.getBlock() instanceof StalactiteBlock) { - if (!state.canPlaceAt(world, POS)) { - if (world.getBlockState(POS.up()).getBlock() instanceof StalactiteBlock) { + } + else if (state.getBlock() instanceof StalactiteBlock) { + if (!state.canSurvive(world, POS)) { + if (world.getBlockState(POS.above()).getBlock() instanceof StalactiteBlock) { while (state.getBlock() instanceof StalactiteBlock) { setWithoutUpdate(world, POS, AIR); POS.setY(POS.getY() + 1); state = world.getBlockState(POS); } - } else { + } + else { while (state.getBlock() instanceof StalactiteBlock) { setWithoutUpdate(world, POS, AIR); POS.setY(POS.getY() - 1); @@ -228,11 +234,13 @@ public class BlocksHelper { } } } - } else if (state.is(EndBlocks.CAVE_PUMPKIN)) { - if (!world.getBlockState(POS.up()).is(EndBlocks.CAVE_PUMPKIN_SEED)) { + } + else if (state.is(EndBlocks.CAVE_PUMPKIN)) { + if (!world.getBlockState(POS.above()).is(EndBlocks.CAVE_PUMPKIN_SEED)) { setWithoutUpdate(world, POS, AIR); } - } else if (!state.canPlaceAt(world, POS)) { + } + else if (!state.canSurvive(world, POS)) { // Chorus if (state.is(Blocks.CHORUS_PLANT)) { Set ends = Sets.newHashSet(); @@ -245,15 +253,13 @@ public class BlocksHelper { for (Direction dir : HORIZONTAL) { BlockPos p = pos.relative(dir); BlockState st = world.getBlockState(p); - if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) - && !st.canPlaceAt(world, p)) { + if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(world, p)) { add.add(p); } } - BlockPos p = pos.up(); + BlockPos p = pos.above(); BlockState st = world.getBlockState(p); - if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) - && !st.canPlaceAt(world, p)) { + if ((st.is(Blocks.CHORUS_PLANT) || st.is(Blocks.CHORUS_FLOWER)) && !st.canSurvive(world, p)) { add.add(p); } }); @@ -284,11 +290,12 @@ public class BlocksHelper { state = world.getBlockState(POS); BlocksHelper.setWithoutUpdate(world, POS, Blocks.END_STONE.defaultBlockState()); } - } else { + } + else { POS.setY(y); BlockState replacement = AIR; for (Direction dir : HORIZONTAL) { - state = world.getBlockState(POS.offset(dir)); + state = world.getBlockState(POS.relative(dir)); if (!state.getFluidState().isEmpty()) { replacement = state; break; @@ -303,8 +310,7 @@ public class BlocksHelper { else { // Blue Vine if (state.getBlock() instanceof BlueVineBlock) { - while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN) - || state.is(EndBlocks.BLUE_VINE_FUR)) { + while (state.is(EndBlocks.BLUE_VINE) || state.is(EndBlocks.BLUE_VINE_LANTERN) || state.is(EndBlocks.BLUE_VINE_FUR)) { BlocksHelper.setWithoutUpdate(world, POS, AIR); POS.setY(POS.getY() + 1); state = world.getBlockState(POS); @@ -325,34 +331,34 @@ public class BlocksHelper { } } } - + doubleCheck.forEach((pos) -> { - if (!world.getBlockState(pos).canPlaceAt(world, pos)) { + if (!world.getBlockState(pos).canSurvive(world, pos)) { BlocksHelper.setWithoutUpdate(world, pos, AIR); } }); } - + private static BlockState getAirOrFluid(BlockState state) { - return state.getFluidState().isEmpty() ? AIR : state.getFluidState().getBlockState(); + return state.getFluidState().isEmpty() ? AIR : state.getFluidState().createLegacyBlock(); } - + public static boolean isEndNylium(Block block) { - return block.isIn(BlockTags.NYLIUM) && block.isIn(EndTags.END_GROUND); + return block.is(BlockTags.NYLIUM) && block.is(EndTags.END_GROUND); } - + public static boolean isEndNylium(BlockState state) { return isEndNylium(state.getBlock()); } - + public static Direction[] makeHorizontal() { return new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST }; } - + public static Direction randomHorizontal(Random random) { return HORIZONTAL[random.nextInt(4)]; } - + public static Direction randomDirection(Random random) { return DIRECTIONS[random.nextInt(6)]; } diff --git a/src/main/java/ru/betterend/util/BonemealUtil.java b/src/main/java/ru/betterend/util/BonemealUtil.java index cbf685ec..dae14b5b 100644 --- a/src/main/java/ru/betterend/util/BonemealUtil.java +++ b/src/main/java/ru/betterend/util/BonemealUtil.java @@ -3,12 +3,10 @@ package ru.betterend.util; import java.util.List; import java.util.Map; import java.util.Random; - +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; import com.google.common.collect.Lists; import com.google.common.collect.Maps; - -import net.minecraft.world.level.block.Block; -import net.minecraft.resources.ResourceLocation; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBlocks; import ru.betterend.world.biome.EndBiome; @@ -16,59 +14,59 @@ import ru.betterend.world.biome.EndBiome; public class BonemealUtil { private static final Map> GRASS_BIOMES = Maps.newHashMap(); private static final Map GRASS_TYPES = Maps.newHashMap(); - + public static void init() { addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.CREEPING_MOSS); addBonemealGrass(EndBlocks.END_MOSS, EndBlocks.UMBRELLA_MOSS); addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.CREEPING_MOSS); addBonemealGrass(EndBlocks.END_MYCELIUM, EndBlocks.UMBRELLA_MOSS); - + addBonemealGrass(EndBlocks.CAVE_MOSS, EndBlocks.CAVE_GRASS); addBonemealGrass(EndBlocks.CHORUS_NYLIUM, EndBlocks.CHORUS_GRASS); addBonemealGrass(EndBlocks.CRYSTAL_MOSS, EndBlocks.CRYSTAL_GRASS); addBonemealGrass(EndBlocks.SHADOW_GRASS, EndBlocks.SHADOW_PLANT); addBonemealGrass(EndBlocks.PINK_MOSS, EndBlocks.BUSHY_GRASS); addBonemealGrass(EndBlocks.AMBER_MOSS, EndBlocks.AMBER_GRASS); - + addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.JUNGLE_GRASS); addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS); addBonemealGrass(EndBlocks.JUNGLE_MOSS, EndBlocks.SMALL_JELLYSHROOM, 0.1F); - + addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.BLOOMING_COOKSONIA); addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.VAIOLUSH_FERN); addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.FRACTURN); addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.SALTEAGO); - + addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.CREEPING_MOSS, 0.1F); addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.UMBRELLA_MOSS, 0.1F); addBonemealGrass(EndBiomes.GLOWING_GRASSLANDS, EndBlocks.END_MOSS, EndBlocks.TWISTED_UMBRELLA_MOSS, 0.1F); - + addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.ORANGO); addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.AERIDIUM, 0.2F); addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.LUTEBUS, 0.2F); addBonemealGrass(EndBlocks.RUTISCUS, EndBlocks.LAMELLARIUM); - + addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.AERIDIUM, 0.2F); addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.LAMELLARIUM); addBonemealGrass(EndBiomes.LANTERN_WOODS, EndBlocks.RUTISCUS, EndBlocks.BOLUX_MUSHROOM, 0.05F); - + addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.GLOBULAGUS); addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.CLAWFERN); addBonemealGrass(EndBlocks.SANGNUM, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F); - + addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.GLOBULAGUS); addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.CLAWFERN); addBonemealGrass(EndBlocks.MOSSY_DRAGON_BONE, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F); - + addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.GLOBULAGUS); addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.CLAWFERN); addBonemealGrass(EndBlocks.MOSSY_OBSIDIAN, EndBlocks.SMALL_AMARANITA_MUSHROOM, 0.1F); } - + public static void addBonemealGrass(Block terrain, Block plant) { addBonemealGrass(terrain, plant, 1F); } - + public static void addBonemealGrass(Block terrain, Block plant, float chance) { GrassList list = GRASS_TYPES.get(terrain); if (list == null) { @@ -77,11 +75,11 @@ public class BonemealUtil { } list.addGrass(plant, chance); } - + public static void addBonemealGrass(EndBiome biome, Block terrain, Block plant) { addBonemealGrass(biome, terrain, plant, 1F); } - + public static void addBonemealGrass(EndBiome biome, Block terrain, Block plant, float chance) { Map map = GRASS_BIOMES.get(biome.getID()); if (map == null) { @@ -95,7 +93,7 @@ public class BonemealUtil { } list.addGrass(plant, chance); } - + public static Block getGrass(ResourceLocation biomeID, Block terrain, Random random) { Map map = GRASS_BIOMES.get(biomeID); GrassList list = null; @@ -104,43 +102,44 @@ public class BonemealUtil { if (list == null) { list = GRASS_TYPES.get(terrain); } - } else { + } + else { list = GRASS_TYPES.get(terrain); } return list == null ? null : list.getGrass(random); } - + private static final class GrassInfo { final Block grass; float chance; - + public GrassInfo(Block grass, float chance) { this.grass = grass; this.chance = chance; } - + public float addChance(float chance) { this.chance += chance; return this.chance; } } - + private static final class GrassList { final List list = Lists.newArrayList(); float maxChance = 0; - + public void addGrass(Block grass, float chance) { GrassInfo info = new GrassInfo(grass, chance); maxChance = info.addChance(maxChance); list.add(info); } - + public Block getGrass(Random random) { if (maxChance == 0 || list.isEmpty()) { return null; } float chance = random.nextFloat() * maxChance; - for (GrassInfo info : list) { + for (GrassInfo info: list) { if (chance <= info.chance) { return info.grass; } diff --git a/src/main/java/ru/betterend/util/ColorUtil.java b/src/main/java/ru/betterend/util/ColorUtil.java index e2031cbd..87b7b5b4 100644 --- a/src/main/java/ru/betterend/util/ColorUtil.java +++ b/src/main/java/ru/betterend/util/ColorUtil.java @@ -6,50 +6,52 @@ import java.util.List; import java.util.Map; import com.google.common.collect.Maps; - +import com.mojang.blaze3d.platform.NativeImage; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper; import net.minecraft.client.Minecraft; -import net.minecraft.client.texture.NativeImage; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.Resource; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.Mth; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; @Environment(EnvType.CLIENT) public class ColorUtil { - + private static float[] floatBuffer = new float[4]; - + public static int[] toIntArray(int color) { - return new int[] { (color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, color & 255 }; + return new int[] { + (color >> 24) & 255, + (color >> 16) & 255, + (color >> 8) & 255, + color & 255 + }; } - + public static float[] toFloatArray(int color) { floatBuffer[0] = ((color >> 16 & 255) / 255.0F); floatBuffer[1] = ((color >> 8 & 255) / 255.0F); floatBuffer[2] = ((color & 255) / 255.0F); floatBuffer[3] = ((color >> 24 & 255) / 255.0F); - + return floatBuffer; } - + public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) { float hue, saturation, brightness; if (hsbvals == null) { hsbvals = floatBuffer; } int cmax = (r > g) ? r : g; - if (b > cmax) - cmax = b; + if (b > cmax) cmax = b; int cmin = (r < g) ? r : g; - if (b < cmin) - cmin = b; + if (b < cmin) cmin = b; brightness = ((float) cmax) / 255.0F; if (cmax != 0) @@ -77,14 +79,14 @@ public class ColorUtil { hsbvals[2] = brightness; return hsbvals; } - + public static int HSBtoRGB(float hue, float saturation, float brightness) { int r = 0, g = 0, b = 0; if (saturation == 0) { r = g = b = (int) (brightness * 255.0F + 0.5F); } else { - float h = (hue - (float) Math.floor(hue)) * 6.0F; - float f = h - (float) java.lang.Math.floor(h); + float h = (hue - (float)Math.floor(hue)) * 6.0F; + float f = h - (float)java.lang.Math.floor(h); float p = brightness * (1.0F - saturation); float q = brightness * (1.0F - saturation * f); float t = brightness * (1.0F - (saturation * (1.0F - f))); @@ -123,43 +125,41 @@ public class ColorUtil { } return 0xFF000000 | (r << 16) | (g << 8) | (b << 0); } - + public static int parseHex(String hexColor) { int len = hexColor.length(); if (len < 6 || len > 8 || len % 2 > 0) { return -1; } - + int color, shift; - if (len == 6) { - color = 0xFF000000; - shift = 16; + if(len == 6) { + color = 0xFF000000; shift = 16; } else { - color = 0; - shift = 24; + color = 0; shift = 24; } - + try { String[] splited = hexColor.split("(?<=\\G.{2})"); for (String digit : splited) { color |= Integer.valueOf(digit, 16) << shift; shift -= 8; } - } catch (NumberFormatException ex) { + } catch(NumberFormatException ex) { BetterEnd.LOGGER.catching(ex); return -1; } - + return color; } - + public static int toABGR(int color) { int r = (color >> 16) & 255; int g = (color >> 8) & 255; int b = color & 255; return 0xFF000000 | b << 16 | g << 8 | r; } - + public static int ABGRtoARGB(int color) { int a = (color >> 24) & 255; int b = (color >> 16) & 255; @@ -167,18 +167,18 @@ public class ColorUtil { int r = color & 255; return a << 24 | r << 16 | g << 8 | b; } - + public static int colorBrigtness(int color, float val) { RGBtoHSB((color >> 16) & 255, (color >> 8) & 255, color & 255, floatBuffer); floatBuffer[2] += val / 10.0F; floatBuffer[2] = Mth.clamp(floatBuffer[2], 0.0F, 1.0F); return HSBtoRGB(floatBuffer[0], floatBuffer[1], floatBuffer[2]); } - + public static int applyTint(int color, int tint) { return colorBrigtness(ColorHelper.multiplyColor(color, tint), 1.5F); } - + public static int colorDistance(int color1, int color2) { int r1 = (color1 >> 16) & 255; int g1 = (color1 >> 8) & 255; @@ -188,13 +188,12 @@ public class ColorUtil { int b2 = color2 & 255; return MHelper.pow2(r1 - r2) + MHelper.pow2(g1 - g2) + MHelper.pow2(b1 - b2); } - + private static Map colorPalette = Maps.newHashMap(); - + public static int extractColor(Item item) { - ResourceLocation id = Registry.ITEM.getId(item); - if (id.equals(Registry.ITEM.getDefaultKey())) - return -1; + ResourceLocation id = Registry.ITEM.getKey(item); + if (id.equals(Registry.ITEM.getDefaultKey())) return -1; if (colorPalette.containsKey(id)) { return colorPalette.get(id); } @@ -208,35 +207,34 @@ public class ColorUtil { List colors = new ArrayList<>(); for (int i = 0; i < image.getWidth(); i++) { for (int j = 0; j < 16; j++) { - int col = image.getPixelColor(i, j); + int col = image.getPixelRGBA(i, j); if (((col >> 24) & 255) > 0) { colors.add(ABGRtoARGB(col)); } } } image.close(); - - if (colors.size() == 0) - return -1; - + + if (colors.size() == 0) return -1; + ColorExtractor extractor = new ColorExtractor(colors); int color = extractor.analize(); colorPalette.put(id, color); - + return color; } - + public static NativeImage loadImage(ResourceLocation image, int w, int h) { Minecraft minecraft = Minecraft.getInstance(); ResourceManager resourceManager = minecraft.getResourceManager(); - if (resourceManager.containsResource(image)) { + if (resourceManager.hasResource(image)) { try (Resource resource = resourceManager.getResource(image)) { - return NativeImage.read(resource.getInputStream()); + return NativeImage.read(resource.getInputStream()); } catch (IOException e) { BetterEnd.LOGGER.warning("Can't load texture image: {}. Will be created empty image.", image); BetterEnd.LOGGER.warning("Cause: {}.", e.getMessage()); } - } + } return new NativeImage(w, h, false); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/util/DataFixerUtil.java b/src/main/java/ru/betterend/util/DataFixerUtil.java index 2d864e2a..39748815 100644 --- a/src/main/java/ru/betterend/util/DataFixerUtil.java +++ b/src/main/java/ru/betterend/util/DataFixerUtil.java @@ -12,8 +12,8 @@ import com.google.common.collect.Maps; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.storage.RegionFile; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.storage.RegionFile; public class DataFixerUtil { private static final Map REPLACEMENT = Maps.newHashMap(); @@ -38,7 +38,7 @@ public class DataFixerUtil { ChunkPos pos = new ChunkPos(x, z); changed[0] = false; if (region.hasChunk(pos)) { - DataInputStream input = region.getChunkInputStream(pos); + DataInputStream input = region.getChunkDataInputStream(pos); CompoundTag root = NbtIo.read(input); input.close(); ListTag sections = root.getCompound("Level").getList("Sections", 10); @@ -56,7 +56,7 @@ public class DataFixerUtil { }); if (changed[0]) { System.out.println("Write!"); - DataOutputStream output = region.getChunkOutputStream(pos); + DataOutputStream output = region.getChunkDataOutputStream(pos); NbtIo.write(root, output); output.close(); } diff --git a/src/main/java/ru/betterend/util/FeaturesHelper.java b/src/main/java/ru/betterend/util/FeaturesHelper.java index c00e2452..e7dcf4e1 100644 --- a/src/main/java/ru/betterend/util/FeaturesHelper.java +++ b/src/main/java/ru/betterend/util/FeaturesHelper.java @@ -4,14 +4,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Supplier; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import ru.betterend.mixin.common.GenerationSettingsAccessor; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndStructures; @@ -21,24 +19,22 @@ public class FeaturesHelper { public static void addFeatures(Registry biomeRegistry) { biomeRegistry.forEach((biome) -> { - if (biome.getCategory() == Biome.Category.THEEND && !INJECTED.contains(biome)) { + if (biome.getBiomeCategory() == Biome.BiomeCategory.THEEND && !INJECTED.contains(biome)) { GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); - List>> structures = Lists - .newArrayList(accessor.beGetStructures()); + List>> structures = Lists.newArrayList(accessor.beGetStructures()); List>>> preFeatures = accessor.beGetFeatures(); - List>>> features = new ArrayList>>>( - preFeatures.size()); + List>>> features = new ArrayList>>>(preFeatures.size()); preFeatures.forEach((list) -> { features.add(Lists.newArrayList(list)); }); - EndFeatures.registerBiomeFeatures(biomeRegistry.getId(biome), biome, features); - EndStructures.registerBiomeStructures(biomeRegistry.getId(biome), biome, structures); + EndFeatures.registerBiomeFeatures(biomeRegistry.getKey(biome), biome, features); + EndStructures.registerBiomeStructures(biomeRegistry.getKey(biome), biome, structures); accessor.beSetFeatures(features); accessor.beSetStructures(structures); INJECTED.add(biome); } - }); + }); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/util/ItemUtil.java b/src/main/java/ru/betterend/util/ItemUtil.java index 030a47a0..954de98e 100644 --- a/src/main/java/ru/betterend/util/ItemUtil.java +++ b/src/main/java/ru/betterend/util/ItemUtil.java @@ -4,29 +4,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import com.google.gson.JsonObject; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.GsonHelper; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.JsonHelper; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; public class ItemUtil { - + public static String toStackString(@NotNull ItemStack stack) { try { if (stack == null) { throw new IllegalStateException("Stack can't be null!"); } Item item = stack.getItem(); - return Registry.ITEM.getId(item) + ":" + stack.getCount(); + return Registry.ITEM.getKey(item) + ":" + stack.getCount(); } catch (Exception ex) { BetterEnd.LOGGER.error("ItemStack serialization error!", ex); } return ""; } - + @Nullable public static ItemStack fromStackString(String stackString) { if (stackString == null || stackString.equals("")) { @@ -34,17 +33,16 @@ public class ItemUtil { } try { String[] parts = stackString.split(":"); - if (parts.length < 2) - return null; + if (parts.length < 2) return null; if (parts.length == 2) { ResourceLocation itemId = new ResourceLocation(stackString); - Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> { + Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> { return new IllegalStateException("Output item " + itemId + " does not exists!"); }); return new ItemStack(item); } ResourceLocation itemId = new ResourceLocation(parts[0], parts[1]); - Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> { + Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> { return new IllegalStateException("Output item " + itemId + " does not exists!"); }); return new ItemStack(item, Integer.valueOf(parts[2])); @@ -53,18 +51,18 @@ public class ItemUtil { } return null; } - + @Nullable public static ItemStack fromJsonRecipe(JsonObject recipe) { try { if (!recipe.has("item")) { throw new IllegalStateException("Invalid JsonObject. Entry 'item' does not exists!"); } - ResourceLocation itemId = new ResourceLocation(JsonHelper.getString(recipe, "item")); - Item item = Registry.ITEM.getOrEmpty(itemId).orElseThrow(() -> { + ResourceLocation itemId = new ResourceLocation(GsonHelper.getAsString(recipe, "item")); + Item item = Registry.ITEM.getOptional(itemId).orElseThrow(() -> { return new IllegalStateException("Output item " + itemId + " does not exists!"); }); - int count = JsonHelper.getInt(recipe, "count", 1); + int count = GsonHelper.getAsInt(recipe, "count", 1); return new ItemStack(item, count); } catch (Exception ex) { BetterEnd.LOGGER.error("ItemStack deserialization error!", ex); diff --git a/src/main/java/ru/betterend/util/LangUtil.java b/src/main/java/ru/betterend/util/LangUtil.java index a5767bf2..bc051bf8 100644 --- a/src/main/java/ru/betterend/util/LangUtil.java +++ b/src/main/java/ru/betterend/util/LangUtil.java @@ -1,7 +1,7 @@ package ru.betterend.util; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.text.TranslatableText; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.TranslatableComponent; public class LangUtil { public final static String CONFIG_ELEMENT = "configuration"; @@ -20,19 +20,19 @@ public class LangUtil { return getString(element, key); } - public TranslatableText getText(String key) { + public TranslatableComponent getText(String key) { return getText(element, key); } public static String translate(String key) { - return I18n.translate(key); + return I18n.get(key); } public static String getString(String element, String key) { return translate(String.format("%s.%s", element, key)); } - public static TranslatableText getText(String element, String key) { - return new TranslatableText(getString(element, key)); + public static TranslatableComponent getText(String element, String key) { + return new TranslatableComponent(getString(element, key)); } } diff --git a/src/main/java/ru/betterend/util/LootTableUtil.java b/src/main/java/ru/betterend/util/LootTableUtil.java index 163cec76..c3867a2c 100644 --- a/src/main/java/ru/betterend/util/LootTableUtil.java +++ b/src/main/java/ru/betterend/util/LootTableUtil.java @@ -2,11 +2,11 @@ package ru.betterend.util; import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder; import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback; -import net.minecraft.world.item.Items; -import net.minecraft.loot.UniformLootTableRange; -import net.minecraft.loot.condition.RandomChanceLootCondition; -import net.minecraft.loot.entry.ItemEntry; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.storage.loot.RandomValueBounds; +import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition; import ru.betterend.registry.EndItems; public class LootTableUtil { @@ -16,11 +16,11 @@ public class LootTableUtil { LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> { if (END_CITY_TREASURE_ID.equals(id)) { FabricLootPoolBuilder builder = FabricLootPoolBuilder.builder(); - builder.rolls(UniformLootTableRange.between(0, 5)); - builder.withCondition(RandomChanceLootCondition.builder(0.5f).build()); - builder.withEntry(ItemEntry.builder(Items.GHAST_TEAR).build()); - builder.withEntry(ItemEntry.builder(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build()); - supplier.pool(builder); + builder.setRolls(RandomValueBounds.between(0, 5)); + builder.withCondition(LootItemRandomChanceCondition.randomChance(0.5f).build()); + builder.withEntry(LootItem.lootTableItem(Items.GHAST_TEAR).build()); + builder.withEntry(LootItem.lootTableItem(EndItems.MUSIC_DISC_STRANGE_AND_ALIEN).build()); + supplier.withPool(builder); } }); } diff --git a/src/main/java/ru/betterend/util/MHelper.java b/src/main/java/ru/betterend/util/MHelper.java index 156333b8..4d6d4d0a 100644 --- a/src/main/java/ru/betterend/util/MHelper.java +++ b/src/main/java/ru/betterend/util/MHelper.java @@ -1,9 +1,8 @@ package ru.betterend.util; -import java.util.Random; - import com.mojang.math.Vector3f; -import net.minecraft.util.math.Vec3d; +import java.util.Random; +import net.minecraft.world.phys.Vec3; public class MHelper { public static final float PI2 = (float) (Math.PI * 2); @@ -15,7 +14,7 @@ public class MHelper { public static int color(int r, int g, int b) { return ALPHA | (r << 16) | (g << 8) | b; } - + public static int color(String hex) { int r = Integer.parseInt(hex.substring(0, 2), 16); int g = Integer.parseInt(hex.substring(2, 4), 16); @@ -26,7 +25,7 @@ public class MHelper { public static int randRange(int min, int max, Random random) { return min + random.nextInt(max - min + 1); } - + public static double randRange(double min, double max, Random random) { return min + random.nextDouble() * (max - min); } @@ -68,81 +67,81 @@ public class MHelper { public static int min(int a, int b) { return a < b ? a : b; } - + public static int min(int a, int b, int c) { return min(a, min(b, c)); } - + public static int max(int a, int b) { return a > b ? a : b; } - + public static float min(float a, float b) { return a < b ? a : b; } - + public static float max(float a, float b) { return a > b ? a : b; } - + public static float max(float a, float b, float c) { return max(a, max(b, c)); } - + public static int max(int a, int b, int c) { return max(a, max(b, c)); } - + public static boolean isEven(int num) { return (num & 1) == 0; } - + public static float lengthSqr(float x, float y, float z) { return x * x + y * y + z * z; } - + public static double lengthSqr(double x, double y, double z) { return x * x + y * y + z * z; } - + public static float length(float x, float y, float z) { return (float) Math.sqrt(lengthSqr(x, y, z)); } - + public static double length(double x, double y, double z) { return Math.sqrt(lengthSqr(x, y, z)); } - + public static float lengthSqr(float x, float y) { return x * x + y * y; } - + public static double lengthSqr(double x, double y) { return x * x + y * y; } - + public static float length(float x, float y) { return (float) Math.sqrt(lengthSqr(x, y)); } - + public static double length(double x, double y) { return Math.sqrt(lengthSqr(x, y)); } - + public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) { return x1 * x2 + y1 * y2 + z1 * z2; } - + public static float dot(float x1, float y1, float x2, float y2) { return x1 * x2 + y1 * y2; } - + public static int getRandom(int x, int z) { int h = x * 374761393 + z * 668265263; h = (h ^ (h >> 13)) * 1274126177; return h ^ (h >> 16); } - + public static int getSeed(int seed, int x, int y) { int h = seed + x * 374761393 + y * 668265263; h = (h ^ (h >> 13)) * 1274126177; @@ -154,7 +153,7 @@ public class MHelper { h = (h ^ (h >> 13)) * 1274126177; return h ^ (h >> 16); } - + public static void shuffle(T[] array, Random random) { for (int i = 0; i < array.length; i++) { int i2 = random.nextInt(array.length); @@ -167,15 +166,15 @@ public class MHelper { public static int pow2(int i) { return i * i; } - + public static float pow2(float f) { return f * f; } - + public static double pow2(double d) { return d * d; } - + public static int fromHSBtoRGB(float hue, float saturation, float brightness) { int red = 0; int green = 0; @@ -189,35 +188,35 @@ public class MHelper { float var9 = brightness * (1.0F - saturation * var7); float var10 = brightness * (1.0F - saturation * (1.0F - var7)); switch ((int) var6) { - case 0: - red = (int) (brightness * 255.0F + 0.5F); - green = (int) (var10 * 255.0F + 0.5F); - blue = (int) (var8 * 255.0F + 0.5F); - break; - case 1: - red = (int) (var9 * 255.0F + 0.5F); - green = (int) (brightness * 255.0F + 0.5F); - blue = (int) (var8 * 255.0F + 0.5F); - break; - case 2: - red = (int) (var8 * 255.0F + 0.5F); - green = (int) (brightness * 255.0F + 0.5F); - blue = (int) (var10 * 255.0F + 0.5F); - break; - case 3: - red = (int) (var8 * 255.0F + 0.5F); - green = (int) (var9 * 255.0F + 0.5F); - blue = (int) (brightness * 255.0F + 0.5F); - break; - case 4: - red = (int) (var10 * 255.0F + 0.5F); - green = (int) (var8 * 255.0F + 0.5F); - blue = (int) (brightness * 255.0F + 0.5F); - break; - case 5: - red = (int) (brightness * 255.0F + 0.5F); - green = (int) (var8 * 255.0F + 0.5F); - blue = (int) (var9 * 255.0F + 0.5F); + case 0 : + red = (int) (brightness * 255.0F + 0.5F); + green = (int) (var10 * 255.0F + 0.5F); + blue = (int) (var8 * 255.0F + 0.5F); + break; + case 1 : + red = (int) (var9 * 255.0F + 0.5F); + green = (int) (brightness * 255.0F + 0.5F); + blue = (int) (var8 * 255.0F + 0.5F); + break; + case 2 : + red = (int) (var8 * 255.0F + 0.5F); + green = (int) (brightness * 255.0F + 0.5F); + blue = (int) (var10 * 255.0F + 0.5F); + break; + case 3 : + red = (int) (var8 * 255.0F + 0.5F); + green = (int) (var9 * 255.0F + 0.5F); + blue = (int) (brightness * 255.0F + 0.5F); + break; + case 4 : + red = (int) (var10 * 255.0F + 0.5F); + green = (int) (var8 * 255.0F + 0.5F); + blue = (int) (brightness * 255.0F + 0.5F); + break; + case 5 : + red = (int) (brightness * 255.0F + 0.5F); + green = (int) (var8 * 255.0F + 0.5F); + blue = (int) (var9 * 255.0F + 0.5F); } } @@ -241,7 +240,8 @@ public class MHelper { float hue; if (saturation == 0.0F) { hue = 0.0F; - } else { + } + else { float var9 = (float) (max - r) / (float) (max - min); float var10 = (float) (max - g) / (float) (max - min); float var11 = (float) (max - b) / (float) (max - min); @@ -262,11 +262,11 @@ public class MHelper { values[0] = hue; values[1] = saturation; values[2] = brightness; - + return values; } - - public static Vec3d fromRGBtoHSBV(int r, int g, int b) { + + public static Vec3 fromRGBtoHSBV(int r, int g, int b) { int max = max(r, g, b); int min = min(r, g, b); @@ -281,7 +281,8 @@ public class MHelper { float hue; if (saturation == 0.0F) { hue = 0.0F; - } else { + } + else { float var9 = (float) (max - r) / (float) (max - min); float var10 = (float) (max - g) / (float) (max - min); float var11 = (float) (max - b) / (float) (max - min); @@ -298,25 +299,26 @@ public class MHelper { ++hue; } } - - return new Vec3d(hue, saturation, brightness); + + return new Vec3(hue, saturation, brightness); } - + public static final float radiansToDegrees(float value) { return value * RAD_TO_DEG; } - + public static final float degreesToRadians(float value) { return value / RAD_TO_DEG; } - - public static Vector3f cross(Vector3f vec1, Vector3f vec2) { - float cx = vec1.getY() * vec2.getZ() - vec1.getZ() * vec2.getY(); - float cy = vec1.getZ() * vec2.getX() - vec1.getX() * vec2.getZ(); - float cz = vec1.getX() * vec2.getY() - vec1.getY() * vec2.getX(); + + public static Vector3f cross(Vector3f vec1, Vector3f vec2) + { + float cx = vec1.y() * vec2.z() - vec1.z() * vec2.y(); + float cy = vec1.z() * vec2.x() - vec1.x() * vec2.z(); + float cz = vec1.x() * vec2.y() - vec1.y() * vec2.x(); return new Vector3f(cx, cy, cz); } - + public static Vector3f normalize(Vector3f vec) { float length = lengthSqr(vec.x(), vec.y(), vec.z()); if (length > 0) { @@ -328,14 +330,14 @@ public class MHelper { } return vec; } - + public static float angle(Vector3f vec1, Vector3f vec2) { - float dot = vec1.getX() * vec2.getX() + vec1.getY() * vec2.getY() + vec1.getZ() * vec2.getZ(); - float length1 = lengthSqr(vec1.getX(), vec1.getY(), vec1.getZ()); - float length2 = lengthSqr(vec2.getX(), vec2.getY(), vec2.getZ()); + float dot = vec1.x() * vec2.x() + vec1.y() * vec2.y() + vec1.z() * vec2.z(); + float length1 = lengthSqr(vec1.x(), vec1.y(), vec1.z()); + float length2 = lengthSqr(vec2.x(), vec2.y(), vec2.z()); return (float) Math.acos(dot / Math.sqrt(length1 * length2)); } - + public static Vector3f randomHorizontal(Random random) { float angleY = MHelper.randRange(0, MHelper.PI2, random); float vx = (float) Math.sin(angleY); diff --git a/src/main/java/ru/betterend/util/RecipeHelper.java b/src/main/java/ru/betterend/util/RecipeHelper.java index e0b9b2a0..7b0f879e 100644 --- a/src/main/java/ru/betterend/util/RecipeHelper.java +++ b/src/main/java/ru/betterend/util/RecipeHelper.java @@ -1,18 +1,18 @@ package ru.betterend.util; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.ItemLike; import net.minecraft.core.Registry; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.Block; public class RecipeHelper { public static boolean exists(ItemLike item) { if (item instanceof Block) { return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey(); } else { - return Registry.ITEM.getId(item.asItem()) != Registry.ITEM.getDefaultKey(); + return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey(); } } - + public static boolean exists(ItemLike... items) { for (ItemLike item : items) { if (!exists(item)) { diff --git a/src/main/java/ru/betterend/util/SpawnHelper.java b/src/main/java/ru/betterend/util/SpawnHelper.java index fccf56c7..e42a688a 100644 --- a/src/main/java/ru/betterend/util/SpawnHelper.java +++ b/src/main/java/ru/betterend/util/SpawnHelper.java @@ -2,21 +2,21 @@ package ru.betterend.util; import net.fabricmc.fabric.mixin.object.builder.SpawnRestrictionAccessor; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.SpawnRestriction.Location; -import net.minecraft.world.entity.SpawnRestriction.SpawnPredicate; -import net.minecraft.world.entity.mob.MobEntity; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.SpawnPlacements.SpawnPredicate; +import net.minecraft.world.entity.SpawnPlacements.Type; +import net.minecraft.world.level.levelgen.Heightmap.Types; public class SpawnHelper { - public static void restrictionAir(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Location.NO_RESTRICTIONS, Type.MOTION_BLOCKING, predicate); + public static void restrictionAir(EntityType entity, SpawnPredicate predicate) { + SpawnRestrictionAccessor.callRegister(entity, Type.NO_RESTRICTIONS, Types.MOTION_BLOCKING, predicate); } - - public static void restrictionLand(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Location.ON_GROUND, Type.MOTION_BLOCKING, predicate); + + public static void restrictionLand(EntityType entity, SpawnPredicate predicate) { + SpawnRestrictionAccessor.callRegister(entity, Type.ON_GROUND, Types.MOTION_BLOCKING, predicate); } - - public static void restrictionWater(EntityType entity, SpawnPredicate predicate) { - SpawnRestrictionAccessor.callRegister(entity, Location.IN_WATER, Type.MOTION_BLOCKING, predicate); + + public static void restrictionWater(EntityType entity, SpawnPredicate predicate) { + SpawnRestrictionAccessor.callRegister(entity, Type.IN_WATER, Types.MOTION_BLOCKING, predicate); } } diff --git a/src/main/java/ru/betterend/util/SplineHelper.java b/src/main/java/ru/betterend/util/SplineHelper.java index d0ad187f..8dfef055 100644 --- a/src/main/java/ru/betterend/util/SplineHelper.java +++ b/src/main/java/ru/betterend/util/SplineHelper.java @@ -4,15 +4,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.util.sdf.SDF; import ru.betterend.util.sdf.operator.SDFUnion; import ru.betterend.util.sdf.primitive.SDFLine; @@ -32,7 +30,7 @@ public class SplineHelper { spline.add(new Vector3f(x2, y2, z2)); return spline; } - + public static List smoothSpline(List spline, int segmentPoints) { List result = Lists.newArrayList(); Vector3f start = spline.get(0); @@ -48,38 +46,37 @@ public class SplineHelper { result.add(start); return result; } - + private static Vector3f lerp(Vector3f start, Vector3f end, float delta) { - float x = Mth.lerp(delta, start.getX(), end.getX()); - float y = Mth.lerp(delta, start.getY(), end.getY()); - float z = Mth.lerp(delta, start.getZ(), end.getZ()); + float x = Mth.lerp(delta, start.x(), end.x()); + float y = Mth.lerp(delta, start.y(), end.y()); + float z = Mth.lerp(delta, start.z(), end.z()); return new Vector3f(x, y, z); } - + public static void offsetParts(List spline, Random random, float dx, float dy, float dz) { int count = spline.size(); for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); - float x = pos.getX() + (float) random.nextGaussian() * dx; - float y = pos.getY() + (float) random.nextGaussian() * dy; - float z = pos.getZ() + (float) random.nextGaussian() * dz; + float x = pos.x() + (float) random.nextGaussian() * dx; + float y = pos.y() + (float) random.nextGaussian() * dy; + float z = pos.z() + (float) random.nextGaussian() * dz; pos.set(x, y, z); } } - + public static void powerOffset(List spline, float distance, float power) { int count = spline.size(); float max = count + 1; for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); float x = (float) i / max; - float y = pos.getY() + (float) Math.pow(x, power) * distance; - pos.set(pos.getX(), y, pos.getZ()); + float y = pos.y() + (float) Math.pow(x, power) * distance; + pos.set(pos.x(), y, pos.z()); } } - - public static SDF buildSDF(List spline, float radius1, float radius2, - Function placerFunction) { + + public static SDF buildSDF(List spline, float radius1, float radius2, Function placerFunction) { int count = spline.size(); float max = count - 2; SDF result = null; @@ -87,17 +84,18 @@ public class SplineHelper { for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); float delta = (float) (i - 1) / max; - SDF line = new SDFLine().setRadius(Mth.lerp(delta, radius1, radius2)) - .setStart(start.getX(), start.getY(), start.getZ()).setEnd(pos.getX(), pos.getY(), pos.getZ()) + SDF line = new SDFLine() + .setRadius(Mth.lerp(delta, radius1, radius2)) + .setStart(start.x(), start.y(), start.z()) + .setEnd(pos.x(), pos.y(), pos.z()) .setBlock(placerFunction); result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line); start = pos; } return result; } - - public static SDF buildSDF(List spline, Function radiusFunction, - Function placerFunction) { + + public static SDF buildSDF(List spline, Function radiusFunction, Function placerFunction) { int count = spline.size(); float max = count - 2; SDF result = null; @@ -105,17 +103,18 @@ public class SplineHelper { for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); float delta = (float) (i - 1) / max; - SDF line = new SDFLine().setRadius(radiusFunction.apply(delta)) - .setStart(start.getX(), start.getY(), start.getZ()).setEnd(pos.getX(), pos.getY(), pos.getZ()) + SDF line = new SDFLine() + .setRadius(radiusFunction.apply(delta)) + .setStart(start.x(), start.y(), start.z()) + .setEnd(pos.x(), pos.y(), pos.z()) .setBlock(placerFunction); result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line); start = pos; } return result; } - - public static boolean fillSpline(List spline, WorldGenLevel world, BlockState state, BlockPos pos, - Function replace) { + + public static boolean fillSpline(List spline, WorldGenLevel world, BlockState state, BlockPos pos, Function replace) { Vector3f startPos = spline.get(0); for (int i = 1; i < spline.size(); i++) { Vector3f endPos = spline.get(i); @@ -124,12 +123,11 @@ public class SplineHelper { } startPos = endPos; } - + return true; } - - public static void fillSplineForce(List spline, WorldGenLevel world, BlockState state, BlockPos pos, - Function replace) { + + public static void fillSplineForce(List spline, WorldGenLevel world, BlockState state, BlockPos pos, Function replace) { Vector3f startPos = spline.get(0); for (int i = 1; i < spline.size(); i++) { Vector3f endPos = spline.get(i); @@ -137,22 +135,21 @@ public class SplineHelper { startPos = endPos; } } - - public static boolean fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, - Function replace) { - float dx = end.getX() - start.getX(); - float dy = end.getY() - start.getY(); - float dz = end.getZ() - start.getZ(); + + public static boolean fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function replace) { + float dx = end.x() - start.x(); + float dy = end.y() - start.y(); + float dz = end.z() - start.z(); float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz)); int count = MHelper.floor(max + 1); dx /= max; dy /= max; dz /= max; - float x = start.getX(); - float y = start.getY(); - float z = start.getZ(); + float x = start.x(); + float y = start.y(); + float z = start.z(); boolean down = Math.abs(dy) > 0.2; - + BlockState bState; MutableBlockPos bPos = new MutableBlockPos(); for (int i = 0; i < count; i++) { @@ -165,14 +162,15 @@ public class SplineHelper { if (down && bState.equals(state) || replace.apply(bState)) { BlocksHelper.setWithoutUpdate(world, bPos, state); } - } else { + } + else { return false; } x += dx; y += dy; z += dz; } - bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ()); + bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ()); bState = world.getBlockState(bPos); if (bState.equals(state) || replace.apply(bState)) { BlocksHelper.setWithoutUpdate(world, bPos, state); @@ -182,26 +180,26 @@ public class SplineHelper { BlocksHelper.setWithoutUpdate(world, bPos, state); } return true; - } else { + } + else { return false; } } - - public static void fillLineForce(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, - Function replace) { - float dx = end.getX() - start.getX(); - float dy = end.getY() - start.getY(); - float dz = end.getZ() - start.getZ(); + + public static void fillLineForce(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function replace) { + float dx = end.x() - start.x(); + float dy = end.y() - start.y(); + float dz = end.z() - start.z(); float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz)); int count = MHelper.floor(max + 1); dx /= max; dy /= max; dz /= max; - float x = start.getX(); - float y = start.getY(); - float z = start.getZ(); + float x = start.x(); + float y = start.y(); + float z = start.z(); boolean down = Math.abs(dy) > 0.2; - + BlockState bState; MutableBlockPos bPos = new MutableBlockPos(); for (int i = 0; i < count; i++) { @@ -219,7 +217,7 @@ public class SplineHelper { y += dy; z += dz; } - bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ()); + bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ()); bState = world.getBlockState(bPos); if (replace.apply(bState)) { BlocksHelper.setWithoutUpdate(world, bPos, state); @@ -230,9 +228,8 @@ public class SplineHelper { } } } - - public static boolean canGenerate(List spline, float scale, BlockPos start, WorldGenLevel world, - Function canReplace) { + + public static boolean canGenerate(List spline, float scale, BlockPos start, WorldGenLevel world, Function canReplace) { int count = spline.size(); Vector3f vec = spline.get(0); MutableBlockPos mut = new MutableBlockPos(); @@ -244,10 +241,9 @@ public class SplineHelper { float x2 = start.getX() + vec.x() * scale; float y2 = start.getY() + vec.y() * scale; float z2 = start.getZ() + vec.z() * scale; - + for (float py = y1; py < y2; py += 3) { - if (py - start.getY() < 10) - continue; + if (py - start.getY() < 10) continue; float lerp = (py - y1) / (y2 - y1); float x = Mth.lerp(lerp, x1, x2); float z = Mth.lerp(lerp, z1, z2); @@ -256,16 +252,15 @@ public class SplineHelper { return false; } } - + x1 = x2; y1 = y2; z1 = z2; } return true; } - - public static boolean canGenerate(List spline, BlockPos start, WorldGenLevel world, - Function canReplace) { + + public static boolean canGenerate(List spline, BlockPos start, WorldGenLevel world, Function canReplace) { int count = spline.size(); Vector3f vec = spline.get(0); MutableBlockPos mut = new MutableBlockPos(); @@ -277,10 +272,9 @@ public class SplineHelper { float x2 = start.getX() + vec.x(); float y2 = start.getY() + vec.y(); float z2 = start.getZ() + vec.z(); - + for (float py = y1; py < y2; py += 3) { - if (py - start.getY() < 10) - continue; + if (py - start.getY() < 10) continue; float lerp = (py - y1) / (y2 - y1); float x = Mth.lerp(lerp, x1, x2); float z = Mth.lerp(lerp, z1, z2); @@ -289,14 +283,14 @@ public class SplineHelper { return false; } } - + x1 = x2; y1 = y2; z1 = z2; } return true; } - + public static Vector3f getPos(List spline, float index) { int i = (int) index; int last = spline.size() - 1; @@ -306,43 +300,43 @@ public class SplineHelper { float delta = index - i; Vector3f p1 = spline.get(i); Vector3f p2 = spline.get(i + 1); - float x = Mth.lerp(delta, p1.getX(), p2.getX()); - float y = Mth.lerp(delta, p1.getY(), p2.getY()); - float z = Mth.lerp(delta, p1.getZ(), p2.getZ()); + float x = Mth.lerp(delta, p1.x(), p2.x()); + float y = Mth.lerp(delta, p1.y(), p2.y()); + float z = Mth.lerp(delta, p1.z(), p2.z()); return new Vector3f(x, y, z); } - + public static void rotateSpline(List spline, float angle) { - for (Vector3f v : spline) { + for (Vector3f v: spline) { float sin = (float) Math.sin(angle); float cos = (float) Math.cos(angle); - float x = v.getX() * cos + v.getZ() * sin; - float z = v.getX() * sin + v.getZ() * cos; - v.set(x, v.getY(), z); + float x = v.x() * cos + v.z() * sin; + float z = v.x() * sin + v.z() * cos; + v.set(x, v.y(), z); } } - + public static List copySpline(List spline) { List result = new ArrayList(spline.size()); - for (Vector3f v : spline) { - result.add(new Vector3f(v.getX(), v.getY(), v.getZ())); + for (Vector3f v: spline) { + result.add(new Vector3f(v.x(), v.y(), v.z())); } return result; } - + public static void scale(List spline, float scale) { scale(spline, scale, scale, scale); } - + public static void scale(List spline, float x, float y, float z) { - for (Vector3f v : spline) { - v.set(v.getX() * x, v.getY() * y, v.getZ() * z); + for (Vector3f v: spline) { + v.set(v.x() * x, v.y() * y, v.z() * z); } } - + public static void offset(List spline, Vector3f offset) { - for (Vector3f v : spline) { - v.set(offset.getX() + v.getX(), offset.getY() + v.getY(), offset.getZ() + v.getZ()); + for (Vector3f v: spline) { + v.set(offset.x() + v.x(), offset.y() + v.y(), offset.z() + v.z()); } } } diff --git a/src/main/java/ru/betterend/util/StructureHelper.java b/src/main/java/ru/betterend/util/StructureHelper.java index 8ec9dbc5..4274a66d 100644 --- a/src/main/java/ru/betterend/util/StructureHelper.java +++ b/src/main/java/ru/betterend/util/StructureHelper.java @@ -10,39 +10,39 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtIo; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.material.Material; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; public class StructureHelper { private static final Direction[] DIR = BlocksHelper.makeHorizontal(); - - public static Structure readStructure(ResourceLocation resource) { + + public static StructureTemplate readStructure(ResourceLocation resource) { String ns = resource.getNamespace(); String nm = resource.getPath(); return readStructure("/data/" + ns + "/structures/" + nm + ".nbt"); } - - public static Structure readStructure(File datapack, String path) { + + public static StructureTemplate readStructure(File datapack, String path) { if (datapack.isDirectory()) { return readStructure(datapack.toString() + "/" + path); - } else if (datapack.isFile() && datapack.getName().endsWith(".zip")) { + } + else if (datapack.isFile() && datapack.getName().endsWith(".zip")) { try { ZipFile zipFile = new ZipFile(datapack); Enumeration entries = zipFile.entries(); @@ -57,91 +57,88 @@ public class StructureHelper { System.out.format("\t %s - %d - %d\n", type, compressedSize, normalSize); } zipFile.close(); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } } return null; } - - public static Structure readStructure(String path) { + + public static StructureTemplate readStructure(String path) { try { InputStream inputstream = StructureHelper.class.getResourceAsStream(path); return readStructureFromStream(inputstream); - } catch (IOException e) { + } + catch (IOException e) { e.printStackTrace(); } return null; } - - private static Structure readStructureFromStream(InputStream stream) throws IOException { + + private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException { CompoundTag nbttagcompound = NbtIo.readCompressed(stream); - Structure template = new Structure(); - template.fromTag(nbttagcompound); + StructureTemplate template = new StructureTemplate(); + template.load(nbttagcompound); return template; } - - public static BlockPos offsetPos(BlockPos pos, Structure structure, Rotation rotation, BlockMirror mirror) { - BlockPos offset = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN); + + public static BlockPos offsetPos(BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror) { + BlockPos offset = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO); return pos.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); } - - public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, Structure structure, Rotation rotation, - BlockMirror mirror, Random random) { + + public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror, Random random) { placeCenteredBottom(world, pos, structure, rotation, mirror, makeBox(pos), random); } - - public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, Structure structure, Rotation rotation, - BlockMirror mirror, BlockBox bounds, Random random) { + + public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror, BoundingBox bounds, Random random) { BlockPos offset = offsetPos(pos, structure, rotation, mirror); - StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror) - .setBoundingBox(bounds); - structure.place(world, offset, placementData, random); + StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds); + structure.placeInWorldChunk(world, offset, placementData, random); } - - private static BlockBox makeBox(BlockPos pos) { + + private static BoundingBox makeBox(BlockPos pos) { int sx = ((pos.getX() >> 4) << 4) - 16; int sz = ((pos.getZ() >> 4) << 4) - 16; int ex = sx + 47; int ez = sz + 47; - return BlockBox.create(sx, 0, sz, ex, 255, ez); + return BoundingBox.createProper(sx, 0, sz, ex, 255, ez); } - - public static BlockBox getStructureBounds(BlockPos pos, Structure structure, Rotation rotation, - BlockMirror mirror) { + + public static BoundingBox getStructureBounds(BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror) { BlockPos max = structure.getSize(); - BlockPos min = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN); + BlockPos min = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO); max = max.subtract(min); - return new BlockBox(min.add(pos), max.add(pos)); + return new BoundingBox(min.offset(pos), max.offset(pos)); } - - public static BlockBox intersectBoxes(BlockBox box1, BlockBox box2) { - int x1 = MHelper.max(box1.minX, box2.minX); - int y1 = MHelper.max(box1.minY, box2.minY); - int z1 = MHelper.max(box1.minZ, box2.minZ); - - int x2 = MHelper.min(box1.maxX, box2.maxX); - int y2 = MHelper.min(box1.maxY, box2.maxY); - int z2 = MHelper.min(box1.maxZ, box2.maxZ); - - return BlockBox.create(x1, y1, z1, x2, y2, z2); + + public static BoundingBox intersectBoxes(BoundingBox box1, BoundingBox box2) { + int x1 = MHelper.max(box1.x0, box2.x0); + int y1 = MHelper.max(box1.y0, box2.y0); + int z1 = MHelper.max(box1.z0, box2.z0); + + int x2 = MHelper.min(box1.x1, box2.x1); + int y2 = MHelper.min(box1.y1, box2.y1); + int z2 = MHelper.min(box1.z1, box2.z1); + + return BoundingBox.createProper(x1, y1, z1, x2, y2, z2); } - - public static void erode(WorldGenLevel world, BlockBox bounds, int iterations, Random random) { + + public static void erode(WorldGenLevel world, BoundingBox bounds, int iterations, Random random) { MutableBlockPos mut = new MutableBlockPos(); boolean canDestruct = true; for (int i = 0; i < iterations; i++) { - for (int x = bounds.minX; x <= bounds.maxX; x++) { + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); - for (int y = bounds.maxY; y >= bounds.minY; y--) { + for (int y = bounds.y1; y >= bounds.y0; y--) { mut.setY(y); BlockState state = world.getBlockState(mut); - if (canDestruct && state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && random.nextInt(8) == 0 - && world.isAir(mut.down(2))) { + if (canDestruct && state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && random.nextInt(8) == 0 && world.isEmptyBlock(mut.below(2))) { int r = MHelper.randRange(1, 4, random); int cx = mut.getX(); int cy = mut.getY(); @@ -164,8 +161,7 @@ public class StructureHelper { int dz = pz - cz; dz *= dz; mut.setZ(pz); - if (dx + dy + dz <= r - && world.getBlockState(mut).is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)) { + if (dx + dy + dz <= r && world.getBlockState(mut).is(EndBlocks.FLAVOLITE_RUNED_ETERNAL)) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); } } @@ -176,18 +172,19 @@ public class StructureHelper { mut.setZ(cz); canDestruct = false; continue; - } else if (ignore(state)) { + } + else if (ignore(state)) { continue; } if (!state.isAir() && random.nextBoolean()) { shuffle(random); - for (Direction dir : DIR) { - if (world.isAir(mut.offset(dir)) && world.isAir(mut.below().offset(dir))) { + for (Direction dir: DIR) { + if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below().relative(dir))) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); mut.move(dir).move(Direction.DOWN); - for (int py = mut.getY(); y >= bounds.minY - 10; y--) { + for (int py = mut.getY(); y >= bounds.y0 - 10; y--) { mut.setY(py - 1); - if (!world.isAir(mut)) { + if (!world.isEmptyBlock(mut)) { mut.setY(py); BlocksHelper.setWithoutUpdate(world, mut, state); break; @@ -196,26 +193,26 @@ public class StructureHelper { } } break; - } else if (random.nextInt(8) == 0 - && !world.getBlockState(mut.up()).is(EndBlocks.ETERNAL_PEDESTAL)) { + } + else if (random.nextInt(8) == 0 && !world.getBlockState(mut.above()).is(EndBlocks.ETERNAL_PEDESTAL)) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); } } } } } - for (int x = bounds.minX; x <= bounds.maxX; x++) { + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); - for (int y = bounds.maxY; y >= bounds.minY; y--) { + for (int y = bounds.y1; y >= bounds.y0; y--) { mut.setY(y); BlockState state = world.getBlockState(mut); - if (!ignore(state) && world.isAir(mut.below())) { + if (!ignore(state) && world.isEmptyBlock(mut.below())) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); - for (int py = mut.getY(); py >= bounds.minY - 10; py--) { + for (int py = mut.getY(); py >= bounds.y0 - 10; py--) { mut.setY(py - 1); - if (!world.isAir(mut)) { + if (!world.isEmptyBlock(mut)) { mut.setY(py); BlocksHelper.setWithoutUpdate(world, mut, state); break; @@ -227,15 +224,15 @@ public class StructureHelper { } } - public static void erodeIntense(WorldGenLevel world, BlockBox bounds, Random random) { + public static void erodeIntense(WorldGenLevel world, BoundingBox bounds, Random random) { MutableBlockPos mut = new MutableBlockPos(); MutableBlockPos mut2 = new MutableBlockPos(); - int minY = bounds.minY - 10; - for (int x = bounds.minX; x <= bounds.maxX; x++) { + int minY = bounds.y0 - 10; + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); - for (int y = bounds.maxY; y >= bounds.minY; y--) { + for (int y = bounds.y1; y >= bounds.y0; y--) { mut.setY(y); BlockState state = world.getBlockState(mut); if (!ignore(state)) { @@ -248,12 +245,13 @@ public class StructureHelper { while (world.getBlockState(mut2).getMaterial().isReplaceable() && mut2.getY() > minY) { mut2.setY(mut2.getY() - 1); } - if (!world.getBlockState(mut2).isAir() && state.canPlaceAt(world, mut2)) { + if (!world.getBlockState(mut2).isAir() && state.canSurvive(world, mut2)) { mut2.setY(mut2.getY() + 1); BlocksHelper.setWithoutUpdate(world, mut2, state); } } - } else if (random.nextInt(8) == 0) { + } + else if (random.nextInt(8) == 0) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); } } @@ -263,28 +261,28 @@ public class StructureHelper { drop(world, bounds); } - + private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) { - for (Direction dir : BlocksHelper.DIRECTIONS) { - if (world.getBlockState(pos.relative(dir)).isIn(EndTags.GEN_TERRAIN)) { + for (Direction dir: BlocksHelper.DIRECTIONS) { + if (world.getBlockState(pos.relative(dir)).is(EndTags.GEN_TERRAIN)) { return true; } } return false; } - - private static void drop(WorldGenLevel world, BlockBox bounds) { + + private static void drop(WorldGenLevel world, BoundingBox bounds) { MutableBlockPos mut = new MutableBlockPos(); - + Set blocks = Sets.newHashSet(); Set edge = Sets.newHashSet(); Set add = Sets.newHashSet(); - - for (int x = bounds.minX; x <= bounds.maxX; x++) { + + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); - for (int y = bounds.minY; y <= bounds.maxY; y++) { + for (int y = bounds.y0; y <= bounds.y1; y++) { mut.setY(y); BlockState state = world.getBlockState(mut); if (!ignore(state) && isTerrainNear(world, mut)) { @@ -293,18 +291,18 @@ public class StructureHelper { } } } - + if (edge.isEmpty()) { return; } - + while (!edge.isEmpty()) { - for (BlockPos center : edge) { - for (Direction dir : BlocksHelper.DIRECTIONS) { + for (BlockPos center: edge) { + for (Direction dir: BlocksHelper.DIRECTIONS) { BlockState state = world.getBlockState(center); - if (state.isFullCube(world, center)) { + if (state.isCollisionShapeFullBlock(world, center)) { mut.set(center).move(dir); - if (bounds.contains(mut)) { + if (bounds.isInside(mut)) { state = world.getBlockState(mut); if (!ignore(state) && !blocks.contains(mut)) { add.add(mut.immutable()); @@ -313,19 +311,19 @@ public class StructureHelper { } } } - + blocks.addAll(edge); edge.clear(); edge.addAll(add); add.clear(); } - - int minY = bounds.minY - 10; - for (int x = bounds.minX; x <= bounds.maxX; x++) { + + int minY = bounds.y0 - 10; + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); - for (int y = bounds.minY; y <= bounds.maxY; y++) { + for (int y = bounds.y0; y <= bounds.y1; y++) { mut.setY(y); BlockState state = world.getBlockState(mut); if (!ignore(state) && !blocks.contains(mut)) { @@ -344,12 +342,17 @@ public class StructureHelper { } private static boolean ignore(BlockState state) { - return state.getMaterial().isReplaceable() || !state.getFluidState().isEmpty() || state.isIn(EndTags.END_GROUND) - || state.is(EndBlocks.ETERNAL_PEDESTAL) || state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) - || state.isIn(BlockTags.LOGS) || state.isIn(BlockTags.LEAVES) - || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES); + return state.getMaterial().isReplaceable() + || !state.getFluidState().isEmpty() + || state.is(EndTags.END_GROUND) + || state.is(EndBlocks.ETERNAL_PEDESTAL) + || state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) + || state.is(BlockTags.LOGS) + || state.is(BlockTags.LEAVES) + || state.getMaterial().equals(Material.PLANT) + || state.getMaterial().equals(Material.LEAVES); } - + private static void shuffle(Random random) { for (int i = 0; i < 4; i++) { int j = random.nextInt(4); @@ -358,18 +361,18 @@ public class StructureHelper { DIR[j] = d; } } - - public static void cover(WorldGenLevel world, BlockBox bounds, Random random) { + + public static void cover(WorldGenLevel world, BoundingBox bounds, Random random) { MutableBlockPos mut = new MutableBlockPos(); - for (int x = bounds.minX; x <= bounds.maxX; x++) { + for (int x = bounds.x0; x <= bounds.x1; x++) { mut.setX(x); - for (int z = bounds.minZ; z <= bounds.maxZ; z++) { + for (int z = bounds.z0; z <= bounds.z1; z++) { mut.setZ(z); BlockState top = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); - for (int y = bounds.maxY; y >= bounds.minY; y--) { + for (int y = bounds.y1; y >= bounds.y0; y--) { mut.setY(y); BlockState state = world.getBlockState(mut); - if (state.isIn(EndTags.END_GROUND) && !world.getBlockState(mut.up()).getMaterial().blocksLight()) { + if (state.is(EndTags.END_GROUND) && !world.getBlockState(mut.above()).getMaterial().isSolidBlocking()) { BlocksHelper.setWithoutUpdate(world, mut, top); } } diff --git a/src/main/java/ru/betterend/util/TagHelper.java b/src/main/java/ru/betterend/util/TagHelper.java index 2f962089..2ca68e42 100644 --- a/src/main/java/ru/betterend/util/TagHelper.java +++ b/src/main/java/ru/betterend/util/TagHelper.java @@ -2,64 +2,70 @@ package ru.betterend.util; import java.util.Map; import java.util.Set; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.Tag; +import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; -import net.minecraft.world.item.Item; -import net.minecraft.tags.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; public class TagHelper { private static final Map> TAGS_BLOCK = Maps.newHashMap(); private static final Map> TAGS_ITEM = Maps.newHashMap(); - + public static void addTag(Tag.Named tag, Block... blocks) { ResourceLocation tagID = tag.getName(); - Set set = TAGS_BLOCK.computeIfAbsent(tagID, k -> Sets.newHashSet()); - for (Block block : blocks) { + Set set = TAGS_BLOCK.get(tagID); + if (set == null) { + set = Sets.newHashSet(); + TAGS_BLOCK.put(tagID, set); + } + for (Block block: blocks) { ResourceLocation id = Registry.BLOCK.getKey(block); if (id != Registry.BLOCK.getDefaultKey()) { set.add(id); } } } - + public static void addTag(Tag.Named tag, ItemLike... items) { ResourceLocation tagID = tag.getName(); - Set set = TAGS_ITEM.computeIfAbsent(tagID, k -> Sets.newHashSet()); - for (ItemLike item : items) { + Set set = TAGS_ITEM.get(tagID); + if (set == null) { + set = Sets.newHashSet(); + TAGS_ITEM.put(tagID, set); + } + for (ItemLike item: items) { ResourceLocation id = Registry.ITEM.getKey(item.asItem()); if (id != Registry.ITEM.getDefaultKey()) { set.add(id); } } } - + @SafeVarargs public static void addTags(ItemLike item, Tag.Named... tags) { - for (Tag.Named tag : tags) { + for (Tag.Named tag: tags) { addTag(tag, item); } } - + @SafeVarargs public static void addTags(Block block, Tag.Named... tags) { - for (Tag.Named tag : tags) { + for (Tag.Named tag: tags) { addTag(tag, block); } } - + public static Tag.Builder apply(Tag.Builder builder, Set ids) { - ids.forEach(value -> { - builder.addTag(value, "Better End Code"); + ids.forEach((value) -> { + builder.addElement(value, "Better End Code"); }); return builder; } - + public static void apply(String entry, Map tagsMap) { Map> endTags = null; if (entry.equals("block")) { diff --git a/src/main/java/ru/betterend/util/TranslationHelper.java b/src/main/java/ru/betterend/util/TranslationHelper.java index 1911dff5..cd6adfa7 100644 --- a/src/main/java/ru/betterend/util/TranslationHelper.java +++ b/src/main/java/ru/betterend/util/TranslationHelper.java @@ -4,13 +4,11 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.Collections; import java.util.List; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonObject; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; import ru.betterend.BetterEnd; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndItems; @@ -19,13 +17,13 @@ public class TranslationHelper { public static void printMissingNames() { List missingNamesEn = Lists.newArrayList(); List missingNamesRu = Lists.newArrayList(); - + Gson gson = new Gson(); InputStream streamEn = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/en_us.json"); InputStream streamRu = BetterEnd.class.getResourceAsStream("/assets/betterend/lang/ru_ru.json"); JsonObject translationEn = gson.fromJson(new InputStreamReader(streamEn), JsonObject.class); JsonObject translationRu = gson.fromJson(new InputStreamReader(streamRu), JsonObject.class); - + Registry.BLOCK.forEach((block) -> { if (Registry.BLOCK.getKey(block).getNamespace().equals(BetterEnd.MOD_ID)) { String name = block.getName().getString(); @@ -37,9 +35,9 @@ public class TranslationHelper { } } }); - + EndItems.getModItems().forEach((item) -> { - String name = item.getName().getString(); + String name = item.getDescription().getString(); if (!translationEn.has(name)) { missingNamesEn.add(name); } @@ -47,7 +45,7 @@ public class TranslationHelper { missingNamesRu.add(name); } }); - + EndBiomes.getModBiomes().forEach((endBiome) -> { if (endBiome.getID().getNamespace().equals(BetterEnd.MOD_ID)) { String name = "biome." + BetterEnd.MOD_ID + "." + endBiome.getID().getPath(); @@ -59,9 +57,9 @@ public class TranslationHelper { } } }); - + Registry.ENTITY_TYPE.forEach((entity) -> { - ResourceLocation id = Registry.ENTITY_TYPE.getId(entity); + ResourceLocation id = Registry.ENTITY_TYPE.getKey(entity); if (id.getNamespace().equals(BetterEnd.MOD_ID)) { String name = "entity." + BetterEnd.MOD_ID + "." + id.getPath(); if (!translationEn.has(name)) { @@ -72,12 +70,12 @@ public class TranslationHelper { } } }); - + if (!missingNamesEn.isEmpty() || !missingNamesRu.isEmpty()) { - + System.out.println("========================================"); System.out.println(" MISSING NAMES LIST"); - + if (!missingNamesEn.isEmpty()) { Collections.sort(missingNamesEn); System.out.println("========================================"); @@ -87,7 +85,7 @@ public class TranslationHelper { System.out.println(" \"" + name + "\": \"" + fastTranslateEn(name) + "\","); }); } - + if (!missingNamesRu.isEmpty()) { Collections.sort(missingNamesRu); System.out.println("========================================"); @@ -97,11 +95,11 @@ public class TranslationHelper { System.out.println(" \"" + name + "\": \"\","); }); } - + System.out.println("========================================"); } } - + public static String fastTranslateEn(String text) { String[] words = text.substring(text.lastIndexOf('.') + 1).split("_"); StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/ru/betterend/util/WorldDataUtil.java b/src/main/java/ru/betterend/util/WorldDataUtil.java index 5c99bcab..e881ba09 100644 --- a/src/main/java/ru/betterend/util/WorldDataUtil.java +++ b/src/main/java/ru/betterend/util/WorldDataUtil.java @@ -10,32 +10,34 @@ import ru.betterend.BetterEnd; public class WorldDataUtil { private static CompoundTag root; private static File saveFile; - + public static void load(File file) { saveFile = file; if (file.exists()) { try { root = NbtIo.readCompressed(file); - } catch (IOException e) { - BetterEnd.LOGGER.error("Level data loading failed", e); + } + catch (IOException e) { + BetterEnd.LOGGER.error("World data loading failed", e); root = new CompoundTag(); } return; } root = new CompoundTag(); } - + public static CompoundTag getRootTag() { return root; } - + public static CompoundTag getCompoundTag(String path) { String[] parts = path.split("\\."); CompoundTag tag = root; - for (String part : parts) { + for (String part: parts) { if (tag.contains(part)) { tag = tag.getCompound(part); - } else { + } + else { CompoundTag t = new CompoundTag(); tag.put(part, t); tag = t; @@ -43,12 +45,13 @@ public class WorldDataUtil { } return tag; } - + public static void saveFile() { try { NbtIo.writeCompressed(root, saveFile); - } catch (IOException e) { - BetterEnd.LOGGER.error("Level data saving failed", e); + } + catch (IOException e) { + BetterEnd.LOGGER.error("World data saving failed", e); } } } diff --git a/src/main/java/ru/betterend/util/sdf/PosInfo.java b/src/main/java/ru/betterend/util/sdf/PosInfo.java index 8594141f..74510770 100644 --- a/src/main/java/ru/betterend/util/sdf/PosInfo.java +++ b/src/main/java/ru/betterend/util/sdf/PosInfo.java @@ -1,11 +1,10 @@ package ru.betterend.util.sdf; import java.util.Map; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; public class PosInfo implements Comparable { private static final BlockState AIR = Blocks.AIR.defaultBlockState(); @@ -13,22 +12,22 @@ public class PosInfo implements Comparable { private final Map add; private final BlockPos pos; private BlockState state; - + public static PosInfo create(Map blocks, Map add, BlockPos pos) { return new PosInfo(blocks, add, pos); } - + private PosInfo(Map blocks, Map add, BlockPos pos) { this.blocks = blocks; this.add = add; this.pos = pos; blocks.put(pos, this); } - + public BlockState getState() { return state; } - + public BlockState getState(BlockPos pos) { PosInfo info = blocks.get(pos); if (info == null) { @@ -37,18 +36,18 @@ public class PosInfo implements Comparable { } return info.getState(); } - + public void setState(BlockState state) { this.state = state; } - + public void setState(BlockPos pos, BlockState state) { PosInfo info = blocks.get(pos); if (info != null) { info.setState(state); } } - + public BlockState getState(Direction dir) { PosInfo info = blocks.get(pos.relative(dir)); if (info == null) { @@ -57,7 +56,7 @@ public class PosInfo implements Comparable { } return info.getState(); } - + public BlockState getState(Direction dir, int distance) { PosInfo info = blocks.get(pos.relative(dir, distance)); if (info == null) { @@ -65,20 +64,20 @@ public class PosInfo implements Comparable { } return info.getState(); } - + public BlockState getStateUp() { return getState(Direction.UP); } - + public BlockState getStateDown() { return getState(Direction.DOWN); } - + @Override public int hashCode() { return pos.hashCode(); } - + @Override public boolean equals(Object obj) { if (!(obj instanceof PosInfo)) { @@ -95,7 +94,7 @@ public class PosInfo implements Comparable { public BlockPos getPos() { return pos; } - + public void setBlockPos(BlockPos pos, BlockState state) { PosInfo info = new PosInfo(blocks, add, pos); info.state = state; diff --git a/src/main/java/ru/betterend/util/sdf/SDF.java b/src/main/java/ru/betterend/util/sdf/SDF.java index 68bfc191..e288291e 100644 --- a/src/main/java/ru/betterend/util/sdf/SDF.java +++ b/src/main/java/ru/betterend/util/sdf/SDF.java @@ -6,17 +6,15 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; - +import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; - -import net.minecraft.world.level.ServerLevelAccessor; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.world.phys.AABB; -import net.minecraft.core.Direction; import ru.betterend.util.BlocksHelper; import ru.betterend.world.structures.StructureWorld; @@ -27,19 +25,19 @@ public abstract class SDF { }; public abstract float getDistance(float x, float y, float z); - + public abstract BlockState getBlockState(BlockPos pos); - + public SDF addPostProcess(Function postProcess) { this.postProcesses.add(postProcess); return this; } - + public SDF setReplaceFunction(Function canReplace) { this.canReplace = canReplace; return this; } - + public void fillRecursive(ServerLevelAccessor world, BlockPos start) { Map mapWorld = Maps.newHashMap(); Map addInfo = Maps.newHashMap(); @@ -48,15 +46,15 @@ public abstract class SDF { Set add = Sets.newHashSet(); ends.add(new BlockPos(0, 0, 0)); boolean run = true; - + MutableBlockPos bPos = new MutableBlockPos(); - + while (run) { - for (BlockPos center : ends) { - for (Direction dir : Direction.values()) { + for (BlockPos center: ends) { + for (Direction dir: Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); - + if (!blocks.contains(bPos) && canReplace.apply(world.getBlockState(wpos))) { if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) { BlockState state = getBlockState(wpos); @@ -66,15 +64,15 @@ public abstract class SDF { } } } - + blocks.addAll(ends); ends.clear(); ends.addAll(add); add.clear(); - + run &= !ends.isEmpty(); } - + List infos = new ArrayList(mapWorld.values()); if (infos.size() > 0) { Collections.sort(infos); @@ -102,11 +100,11 @@ public abstract class SDF { }); } } - + public void fillArea(ServerLevelAccessor world, BlockPos center, AABB box) { Map mapWorld = Maps.newHashMap(); Map addInfo = Maps.newHashMap(); - + MutableBlockPos mut = new MutableBlockPos(); for (int y = (int) box.minY; y <= box.maxY; y++) { mut.setY(y); @@ -123,7 +121,7 @@ public abstract class SDF { } } } - + List infos = new ArrayList(mapWorld.values()); if (infos.size() > 0) { Collections.sort(infos); @@ -151,7 +149,7 @@ public abstract class SDF { }); } } - + public void fillRecursiveIgnore(ServerLevelAccessor world, BlockPos start, Function ignore) { Map mapWorld = Maps.newHashMap(); Map addInfo = Maps.newHashMap(); @@ -160,12 +158,12 @@ public abstract class SDF { Set add = Sets.newHashSet(); ends.add(new BlockPos(0, 0, 0)); boolean run = true; - + MutableBlockPos bPos = new MutableBlockPos(); - + while (run) { - for (BlockPos center : ends) { - for (Direction dir : Direction.values()) { + for (BlockPos center: ends) { + for (Direction dir: Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); BlockState state = world.getBlockState(wpos); @@ -178,15 +176,15 @@ public abstract class SDF { } } } - + blocks.addAll(ends); ends.clear(); ends.addAll(add); add.clear(); - + run &= !ends.isEmpty(); } - + List infos = new ArrayList(mapWorld.values()); if (infos.size() > 0) { Collections.sort(infos); @@ -214,7 +212,7 @@ public abstract class SDF { }); } } - + public void fillRecursive(StructureWorld world, BlockPos start) { Map mapWorld = Maps.newHashMap(); Map addInfo = Maps.newHashMap(); @@ -223,15 +221,15 @@ public abstract class SDF { Set add = Sets.newHashSet(); ends.add(new BlockPos(0, 0, 0)); boolean run = true; - + MutableBlockPos bPos = new MutableBlockPos(); - + while (run) { - for (BlockPos center : ends) { - for (Direction dir : Direction.values()) { + for (BlockPos center: ends) { + for (Direction dir: Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); - + if (!blocks.contains(bPos)) { if (this.getDistance(bPos.getX(), bPos.getY(), bPos.getZ()) < 0) { BlockState state = getBlockState(wpos); @@ -241,15 +239,15 @@ public abstract class SDF { } } } - + blocks.addAll(ends); ends.clear(); ends.addAll(add); add.clear(); - + run &= !ends.isEmpty(); } - + List infos = new ArrayList(mapWorld.values()); Collections.sort(infos); postProcesses.forEach((postProcess) -> { @@ -260,7 +258,7 @@ public abstract class SDF { infos.forEach((info) -> { world.setBlock(info.getPos(), info.getState()); }); - + infos.clear(); infos.addAll(addInfo.values()); Collections.sort(infos); @@ -273,19 +271,19 @@ public abstract class SDF { world.setBlock(info.getPos(), info.getState()); }); } - + public Set getPositions(ServerLevelAccessor world, BlockPos start) { Set blocks = Sets.newHashSet(); Set ends = Sets.newHashSet(); Set add = Sets.newHashSet(); ends.add(new BlockPos(0, 0, 0)); boolean run = true; - + MutableBlockPos bPos = new MutableBlockPos(); - + while (run) { - for (BlockPos center : ends) { - for (Direction dir : Direction.values()) { + for (BlockPos center: ends) { + for (Direction dir: Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); BlockState state = world.getBlockState(wpos); @@ -296,15 +294,15 @@ public abstract class SDF { } } } - + ends.forEach((end) -> blocks.add(end.offset(start))); ends.clear(); ends.addAll(add); add.clear(); - + run &= !ends.isEmpty(); } - + return blocks; } } diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFBinary.java b/src/main/java/ru/betterend/util/sdf/operator/SDFBinary.java index 167de382..1d48561d 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFBinary.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFBinary.java @@ -1,28 +1,28 @@ package ru.betterend.util.sdf.operator; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.util.sdf.SDF; public abstract class SDFBinary extends SDF { protected SDF sourceA; protected SDF sourceB; protected boolean firstValue; - + public SDFBinary setSourceA(SDF sourceA) { this.sourceA = sourceA; return this; } - + public SDFBinary setSourceB(SDF sourceB) { this.sourceB = sourceB; return this; } - + protected void selectValue(float a, float b) { firstValue = a < b; } - + @Override public BlockState getBlockState(BlockPos pos) { if (firstValue) { diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFCoordModify.java b/src/main/java/ru/betterend/util/sdf/operator/SDFCoordModify.java index 280cd223..ccba6d7e 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFCoordModify.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFCoordModify.java @@ -1,22 +1,21 @@ package ru.betterend.util.sdf.operator; -import java.util.function.Consumer; - import com.mojang.math.Vector3f; +import java.util.function.Consumer; public class SDFCoordModify extends SDFUnary { private static final Vector3f POS = new Vector3f(); private Consumer function; - + public SDFCoordModify setFunction(Consumer function) { this.function = function; return this; } - + @Override public float getDistance(float x, float y, float z) { POS.set(x, y, z); function.accept(POS); - return this.source.getDistance(POS.getX(), POS.getY(), POS.getZ()); + return this.source.getDistance(POS.x(), POS.y(), POS.z()); } } diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFDisplacement.java b/src/main/java/ru/betterend/util/sdf/operator/SDFDisplacement.java index 32b9474d..14e212b8 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFDisplacement.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFDisplacement.java @@ -1,18 +1,17 @@ package ru.betterend.util.sdf.operator; -import java.util.function.Function; - import com.mojang.math.Vector3f; +import java.util.function.Function; public class SDFDisplacement extends SDFUnary { private static final Vector3f POS = new Vector3f(); private Function displace; - + public SDFDisplacement setFunction(Function displace) { this.displace = displace; return this; } - + @Override public float getDistance(float x, float y, float z) { POS.set(x, y, z); diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFFlatWave.java b/src/main/java/ru/betterend/util/sdf/operator/SDFFlatWave.java index a94f2c3c..f5707bdb 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFFlatWave.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFFlatWave.java @@ -7,7 +7,7 @@ public class SDFFlatWave extends SDFDisplacement { public SDFFlatWave() { setFunction((pos) -> { - return (float) Math.cos(Math.atan2(pos.getX(), pos.getZ()) * rayCount + angle) * intensity; + return (float) Math.cos(Math.atan2(pos.x(), pos.z()) * rayCount + angle) * intensity; }); } diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFHeightmap.java b/src/main/java/ru/betterend/util/sdf/operator/SDFHeightmap.java index a82b50e4..62c17d22 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFHeightmap.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFHeightmap.java @@ -1,6 +1,6 @@ package ru.betterend.util.sdf.operator; -import net.minecraft.client.texture.NativeImage; +import com.mojang.blaze3d.platform.NativeImage; import net.minecraft.util.Mth; public class SDFHeightmap extends SDFDisplacement { @@ -11,14 +11,14 @@ public class SDFHeightmap extends SDFDisplacement { private float scale; private float cos = 1; private float sin = 0; - + public SDFHeightmap() { setFunction((pos) -> { if (map == null) { return 0F; } - float px = Mth.clamp(pos.getX() * scale + offsetX, 0, map.getWidth() - 2); - float pz = Mth.clamp(pos.getZ() * scale + offsetZ, 0, map.getHeight() - 2); + float px = Mth.clamp(pos.x() * scale + offsetX, 0, map.getWidth() - 2); + float pz = Mth.clamp(pos.z() * scale + offsetZ, 0, map.getHeight() - 2); float dx = (px * cos - pz * sin); float dz = (pz * cos + px * sin); int x1 = Mth.floor(dx); @@ -27,16 +27,16 @@ public class SDFHeightmap extends SDFDisplacement { int z2 = z1 + 1; dx = dx - x1; dz = dz - z1; - float a = (map.getPixelColor(x1, z1) & 255) / 255F; - float b = (map.getPixelColor(x2, z1) & 255) / 255F; - float c = (map.getPixelColor(x1, z2) & 255) / 255F; - float d = (map.getPixelColor(x2, z2) & 255) / 255F; + float a = (map.getPixelRGBA(x1, z1) & 255) / 255F; + float b = (map.getPixelRGBA(x2, z1) & 255) / 255F; + float c = (map.getPixelRGBA(x1, z2) & 255) / 255F; + float d = (map.getPixelRGBA(x2, z2) & 255) / 255F; a = Mth.lerp(dx, a, b); b = Mth.lerp(dx, c, d); return -Mth.lerp(dz, a, b) * intensity; }); } - + public SDFHeightmap setMap(NativeImage map) { this.map = map; offsetX = map.getWidth() * 0.5F; @@ -44,18 +44,18 @@ public class SDFHeightmap extends SDFDisplacement { scale = map.getWidth(); return this; } - + public SDFHeightmap setAngle(float angle) { sin = Mth.sin(angle); cos = Mth.cos(angle); return this; } - + public SDFHeightmap setScale(float scale) { this.scale = map.getWidth() * scale; return this; } - + public SDFHeightmap setIntensity(float intensity) { this.intensity = intensity; return this; diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFRadialNoiseMap.java b/src/main/java/ru/betterend/util/sdf/operator/SDFRadialNoiseMap.java index b428973d..258d2ee2 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFRadialNoiseMap.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFRadialNoiseMap.java @@ -7,20 +7,20 @@ import ru.betterend.util.MHelper; public class SDFRadialNoiseMap extends SDFDisplacement { private static final float SIN = Mth.sin(0.5F); private static final float COS = Mth.cos(0.5F); - + private OpenSimplexNoise noise; private float intensity = 1F; private float radius = 1F; private short offsetX; private short offsetZ; - + public SDFRadialNoiseMap() { setFunction((pos) -> { if (intensity == 0) { return 0F; } - float px = pos.getX() / radius; - float pz = pos.getZ() / radius; + float px = pos.x() / radius; + float pz = pos.z() / radius; float distance = MHelper.lengthSqr(px, pz); if (distance > 1) { return 0F; @@ -32,27 +32,26 @@ public class SDFRadialNoiseMap extends SDFDisplacement { return distance * intensity; }); } - + private float getNoise(double x, double z) { - return (float) noise.eval(x, z) + (float) noise.eval(x * 3 + 1000, z * 3) * 0.5F - + (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F; + return (float) noise.eval(x, z) + (float) noise.eval(x * 3 + 1000, z * 3) * 0.5F + (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F; } - + public SDFRadialNoiseMap setSeed(long seed) { noise = new OpenSimplexNoise(seed); return this; } - + public SDFRadialNoiseMap setIntensity(float intensity) { this.intensity = intensity; return this; } - + public SDFRadialNoiseMap setRadius(float radius) { this.radius = radius; return this; } - + public SDFRadialNoiseMap setOffset(int x, int z) { offsetX = (short) (x & 32767); offsetZ = (short) (z & 32767); diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFRotation.java b/src/main/java/ru/betterend/util/sdf/operator/SDFRotation.java index 38112670..3772443a 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFRotation.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFRotation.java @@ -1,21 +1,21 @@ package ru.betterend.util.sdf.operator; +import com.mojang.math.Quaternion; import com.mojang.math.Vector3f; -import net.minecraft.util.math.Quaternion; public class SDFRotation extends SDFUnary { private static final Vector3f POS = new Vector3f(); private Quaternion rotation; - + public SDFRotation setRotation(Vector3f axis, float rotationAngle) { rotation = new Quaternion(axis, rotationAngle, false); return this; } - + @Override public float getDistance(float x, float y, float z) { POS.set(x, y, z); - POS.rotate(rotation); - return source.getDistance(POS.getX(), POS.getY(), POS.getZ()); + POS.transform(rotation); + return source.getDistance(POS.x(), POS.y(), POS.z()); } } diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothIntersection.java b/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothIntersection.java index e9aa513c..de4d12f0 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothIntersection.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothIntersection.java @@ -9,7 +9,7 @@ public class SDFSmoothIntersection extends SDFBinary { this.radius = radius; return this; } - + @Override public float getDistance(float x, float y, float z) { float a = this.sourceA.getDistance(x, y, z); diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothSubtraction.java b/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothSubtraction.java index 98ba21c1..8f2a5226 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothSubtraction.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFSmoothSubtraction.java @@ -9,7 +9,7 @@ public class SDFSmoothSubtraction extends SDFBinary { this.radius = radius; return this; } - + @Override public float getDistance(float x, float y, float z) { float a = this.sourceA.getDistance(x, y, z); diff --git a/src/main/java/ru/betterend/util/sdf/operator/SDFUnary.java b/src/main/java/ru/betterend/util/sdf/operator/SDFUnary.java index 29286ad5..233901c3 100644 --- a/src/main/java/ru/betterend/util/sdf/operator/SDFUnary.java +++ b/src/main/java/ru/betterend/util/sdf/operator/SDFUnary.java @@ -1,17 +1,17 @@ package ru.betterend.util.sdf.operator; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.util.sdf.SDF; public abstract class SDFUnary extends SDF { protected SDF source; - + public SDFUnary setSource(SDF source) { this.source = source; return this; } - + @Override public BlockState getBlockState(BlockPos pos) { return source.getBlockState(pos); diff --git a/src/main/java/ru/betterend/util/sdf/primitive/SDFCappedCone.java b/src/main/java/ru/betterend/util/sdf/primitive/SDFCappedCone.java index 580c6dfb..e7461443 100644 --- a/src/main/java/ru/betterend/util/sdf/primitive/SDFCappedCone.java +++ b/src/main/java/ru/betterend/util/sdf/primitive/SDFCappedCone.java @@ -7,17 +7,17 @@ public class SDFCappedCone extends SDFPrimitive { private float radius1; private float radius2; private float height; - + public SDFCappedCone setRadius1(float radius) { this.radius1 = radius; return this; } - + public SDFCappedCone setRadius2(float radius) { this.radius2 = radius; return this; } - + public SDFCappedCone setHeight(float height) { this.height = height; return this; @@ -30,8 +30,7 @@ public class SDFCappedCone extends SDFPrimitive { float k2y = 2 * height; float cax = qx - MHelper.min(qx, (y < 0F) ? radius1 : radius2); float cay = Math.abs(y) - height; - float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F, - 1F); + float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F, 1F); float cbx = qx - radius2 + k2x * mlt; float cby = y - height + k2y * mlt; float s = (cbx < 0F && cay < 0F) ? -1F : 1F; diff --git a/src/main/java/ru/betterend/util/sdf/primitive/SDFCapsule.java b/src/main/java/ru/betterend/util/sdf/primitive/SDFCapsule.java index 4242d18f..94c38913 100644 --- a/src/main/java/ru/betterend/util/sdf/primitive/SDFCapsule.java +++ b/src/main/java/ru/betterend/util/sdf/primitive/SDFCapsule.java @@ -6,17 +6,17 @@ import ru.betterend.util.MHelper; public class SDFCapsule extends SDFPrimitive { private float radius; private float height; - + public SDFCapsule setRadius(float radius) { this.radius = radius; return this; } - + public SDFCapsule setHeight(float height) { this.height = height; return this; } - + @Override public float getDistance(float x, float y, float z) { return MHelper.length(x, y - Mth.clamp(y, 0, height), z) - radius; diff --git a/src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java b/src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java index e35fc302..eff4c11a 100644 --- a/src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java +++ b/src/main/java/ru/betterend/util/sdf/primitive/SDFLine.java @@ -11,19 +11,19 @@ public class SDFLine extends SDFPrimitive { private float x2; private float y2; private float z2; - + public SDFLine setRadius(float radius) { this.radius = radius; return this; } - + public SDFLine setStart(float x, float y, float z) { this.x1 = x; this.y1 = y; this.z1 = z; return this; } - + public SDFLine setEnd(float x, float y, float z) { this.x2 = x; this.y2 = y; diff --git a/src/main/java/ru/betterend/util/sdf/primitive/SDFPie.java b/src/main/java/ru/betterend/util/sdf/primitive/SDFPie.java index 3fdb2dcf..49482fd6 100644 --- a/src/main/java/ru/betterend/util/sdf/primitive/SDFPie.java +++ b/src/main/java/ru/betterend/util/sdf/primitive/SDFPie.java @@ -7,25 +7,25 @@ public class SDFPie extends SDFPrimitive { private float sin; private float cos; private float radius; - + public SDFPie setAngle(float angle) { this.sin = (float) Math.sin(angle); this.cos = (float) Math.cos(angle); return this; } - + public SDFPie setRadius(float radius) { this.radius = radius; return this; } - + @Override public float getDistance(float x, float y, float z) { float px = Math.abs(x); - float l = MHelper.length(px, y, z) - radius; - float m = MHelper.dot(px, z, sin, cos); - m = Mth.clamp(m, 0, radius); + float l = MHelper.length(px, y, z) - radius; + float m = MHelper.dot(px, z, sin, cos); + m = Mth.clamp(m, 0, radius); m = MHelper.length(px - sin * m, z - cos * m); - return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z)); + return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z)); } } diff --git a/src/main/java/ru/betterend/util/sdf/primitive/SDFPrimitive.java b/src/main/java/ru/betterend/util/sdf/primitive/SDFPrimitive.java index 7ee719bf..27ef4f91 100644 --- a/src/main/java/ru/betterend/util/sdf/primitive/SDFPrimitive.java +++ b/src/main/java/ru/betterend/util/sdf/primitive/SDFPrimitive.java @@ -1,41 +1,38 @@ package ru.betterend.util.sdf.primitive; import java.util.function.Function; - +import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.core.BlockPos; import ru.betterend.util.sdf.SDF; public abstract class SDFPrimitive extends SDF { protected Function placerFunction; - + public SDFPrimitive setBlock(Function placerFunction) { this.placerFunction = placerFunction; return this; } - + public SDFPrimitive setBlock(BlockState state) { this.placerFunction = (pos) -> { return state; }; return this; } - + public SDFPrimitive setBlock(Block block) { this.placerFunction = (pos) -> { return block.defaultBlockState(); }; return this; } - + public BlockState getBlockState(BlockPos pos) { return placerFunction.apply(pos); } - - /* - * public abstract CompoundTag toNBT(CompoundTag root) { - * - * } - */ + + /*public abstract CompoundTag toNBT(CompoundTag root) { + + }*/ } diff --git a/src/main/java/ru/betterend/world/biome/BiomeDefinition.java b/src/main/java/ru/betterend/world/biome/BiomeDefinition.java index 8a02e4a9..687db4cb 100644 --- a/src/main/java/ru/betterend/world/biome/BiomeDefinition.java +++ b/src/main/java/ru/betterend/world/biome/BiomeDefinition.java @@ -1,39 +1,36 @@ package ru.betterend.world.biome; import java.util.List; - -import com.google.common.collect.Lists; - +import net.minecraft.core.Registry; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.Music; +import net.minecraft.sounds.Musics; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.biome.AmbientAdditionsSettings; +import net.minecraft.world.level.biome.AmbientMoodSettings; +import net.minecraft.world.level.biome.AmbientParticleSettings; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.world.level.biome.Biome.Precipitation; +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.biome.BiomeSpecialEffects.Builder; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import net.minecraft.client.sound.MusicType; -import net.minecraft.world.entity.EntityType; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.sound.BiomeAdditionsSound; -import net.minecraft.sound.BiomeMoodSound; -import net.minecraft.sound.MusicSound; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.Category; -import net.minecraft.world.level.biome.Biome.Precipitation; -import net.minecraft.world.biome.BiomeEffects.Builder; -import net.minecraft.world.biome.BiomeParticleConfig; -import net.minecraft.world.biome.GenerationSettings; -import net.minecraft.world.biome.SpawnSettings; -import net.minecraft.world.biome.SpawnSettings.SpawnEntry; -import net.minecraft.world.gen.GenerationStep.Carver; -import net.minecraft.world.gen.GenerationStep.Feature; -import net.minecraft.world.gen.ProbabilityConfig; -import net.minecraft.world.gen.carver.ConfiguredCarver; +import net.minecraft.world.level.levelgen.GenerationStep.Carving; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilders; -import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; +import net.minecraft.world.level.levelgen.feature.configurations.ProbabilityFeatureConfiguration; +import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; +import com.google.common.collect.Lists; import ru.betterend.BetterEnd; import ru.betterend.registry.EndFeatures; import ru.betterend.util.MHelper; @@ -44,16 +41,16 @@ import ru.betterend.world.surface.SurfaceBuilders; public class BiomeDefinition { private static final int DEF_FOLIAGE = MHelper.color(197, 210, 112); - + private final List> structures = Lists.newArrayList(); private final List features = Lists.newArrayList(); private final List carvers = Lists.newArrayList(); private final List mobs = Lists.newArrayList(); - private final List spawns = Lists.newArrayList(); + private final List spawns = Lists.newArrayList(); - private BiomeParticleConfig particleConfig; - private BiomeAdditionsSound additions; - private BiomeMoodSound mood; + private AmbientParticleSettings particleConfig; + private AmbientAdditionsSettings additions; + private AmbientMoodSettings mood; private SoundEvent music; private SoundEvent loop; @@ -69,56 +66,58 @@ public class BiomeDefinition { private float genChance = 1F; private boolean hasCaves = true; private boolean isCaveBiome = false; - + private ConfiguredSurfaceBuilder surface; public BiomeDefinition(String name) { this.id = BetterEnd.makeID(name); } - + public BiomeDefinition setCaveBiome() { isCaveBiome = true; return this; } - + public BiomeDefinition setSurface(Block block) { - setSurface(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(block.defaultBlockState(), - Blocks.END_STONE.defaultBlockState(), Blocks.END_STONE.defaultBlockState()))); + setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration( + block.defaultBlockState(), + Blocks.END_STONE.defaultBlockState(), + Blocks.END_STONE.defaultBlockState() + ))); return this; } - + public BiomeDefinition setSurface(Block block1, Block block2) { - setSurface(DoubleBlockSurfaceBuilder.register("be_" + id.getPath() + "_surface").setBlock1(block1) - .setBlock2(block2).configured()); + setSurface(DoubleBlockSurfaceBuilder.register("be_" + id.getPath() + "_surface").setBlock1(block1).setBlock2(block2).configured()); return this; } - + public BiomeDefinition setSurface(ConfiguredSurfaceBuilder builder) { this.surface = builder; return this; } - - public BiomeDefinition setSurface(SurfaceBuilder builder) { - return setSurface(builder.withConfig(SurfaceBuilders.DEFAULT_END_CONFIG)); + + public BiomeDefinition setSurface(SurfaceBuilder builder) { + return setSurface(builder.configured(SurfaceBuilders.DEFAULT_END_CONFIG)); } public BiomeDefinition setParticles(ParticleOptions particle, float probability) { - this.particleConfig = new BiomeParticleConfig(particle, probability); + this.particleConfig = new AmbientParticleSettings(particle, probability); return this; } - + public BiomeDefinition setGenChance(float genChance) { this.genChance = genChance; return this; } - + public BiomeDefinition setDepth(float depth) { this.depth = depth; return this; } public BiomeDefinition addMobSpawn(EntityType type, int weight, int minGroupSize, int maxGroupSize) { - ResourceLocation eID = Registry.ENTITY_TYPE.getId(type); + ResourceLocation eID = Registry.ENTITY_TYPE.getKey(type); if (eID != Registry.ENTITY_TYPE.getDefaultKey()) { SpawnInfo info = new SpawnInfo(); info.type = type; @@ -129,8 +128,8 @@ public class BiomeDefinition { } return this; } - - public BiomeDefinition addMobSpawn(SpawnEntry entry) { + + public BiomeDefinition addMobSpawn(SpawnerData entry) { spawns.add(entry); return this; } @@ -139,12 +138,12 @@ public class BiomeDefinition { structures.add(feature); return this; } - + public BiomeDefinition addStructureFeature(EndStructureFeature feature) { structures.add(feature.getFeatureConfigured()); return this; } - + public BiomeDefinition addFeature(EndFeature feature) { FeatureInfo info = new FeatureInfo(); info.featureStep = feature.getFeatureStep(); @@ -153,14 +152,14 @@ public class BiomeDefinition { return this; } - public BiomeDefinition addFeature(Feature featureStep, ConfiguredFeature feature) { + public BiomeDefinition addFeature(Decoration featureStep, ConfiguredFeature feature) { FeatureInfo info = new FeatureInfo(); info.featureStep = featureStep; info.feature = feature; features.add(info); return this; } - + private int getColor(int r, int g, int b) { r = Mth.clamp(r, 0, 255); g = Mth.clamp(g, 0, 255); @@ -187,21 +186,21 @@ public class BiomeDefinition { this.waterFogColor = getColor(r, g, b); return this; } - + public BiomeDefinition setWaterAndFogColor(int r, int g, int b) { return setWaterColor(r, g, b).setWaterFogColor(r, g, b); } - + public BiomeDefinition setFoliageColor(int r, int g, int b) { this.foliageColor = getColor(r, g, b); return this; } - + public BiomeDefinition setGrassColor(int r, int g, int b) { this.grassColor = getColor(r, g, b); return this; } - + public BiomeDefinition setPlantsColor(int r, int g, int b) { return this.setFoliageColor(r, g, b).setGrassColor(r, g, b); } @@ -212,12 +211,12 @@ public class BiomeDefinition { } public BiomeDefinition setMood(SoundEvent mood) { - this.mood = new BiomeMoodSound(mood, 6000, 8, 2.0D); + this.mood = new AmbientMoodSettings(mood, 6000, 8, 2.0D); return this; } public BiomeDefinition setAdditions(SoundEvent additions) { - this.additions = new BiomeAdditionsSound(additions, 0.0111); + this.additions = new AmbientAdditionsSettings(additions, 0.0111); return this; } @@ -225,48 +224,49 @@ public class BiomeDefinition { this.music = music; return this; } - + public BiomeDefinition setCaves(boolean hasCaves) { this.hasCaves = hasCaves; return this; } public Biome build() { - SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder(); - GenerationSettings.Builder generationSettings = new GenerationSettings.Builder(); + MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); + BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder(); Builder effects = new Builder(); mobs.forEach((spawn) -> { - spawnSettings.spawn(spawn.type.getSpawnGroup(), - new SpawnSettings.SpawnEntry(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize)); + spawnSettings.addSpawn(spawn.type.getCategory(), new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize)); }); - + spawns.forEach((entry) -> { - spawnSettings.spawn(entry.type.getSpawnGroup(), entry); + spawnSettings.addSpawn(entry.type.getCategory(), entry); }); EndFeatures.addDefaultFeatures(this); - generationSettings.surfaceBuilder(surface == null ? ConfiguredSurfaceBuilders.END : surface); - structures.forEach((structure) -> generationSettings.structureFeature(structure)); - features.forEach((info) -> generationSettings.feature(info.featureStep, info.feature)); - carvers.forEach((info) -> generationSettings.carver(info.carverStep, info.carver)); + generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); + structures.forEach((structure) -> generationSettings.addStructureStart(structure)); + features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); + carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); - effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor) - .foliageColor(foliageColor).grassColor(grassColor); - if (loop != null) - effects.loopSound(loop); - if (mood != null) - effects.moodSound(mood); - if (additions != null) - effects.additionsSound(additions); - if (particleConfig != null) - effects.particleConfig(particleConfig); - effects.music(music != null ? new MusicSound(music, 600, 2400, true) : MusicType.END); + effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor).foliageColorOverride(foliageColor).grassColorOverride(grassColor); + if (loop != null) effects.ambientLoopSound(loop); + if (mood != null) effects.ambientMoodSound(mood); + if (additions != null) effects.ambientAdditionsSound(additions); + if (particleConfig != null) effects.ambientParticle(particleConfig); + effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - return new Biome.Builder().precipitation(Precipitation.NONE) - .category(isCaveBiome ? Category.NONE : Category.THEEND).depth(depth).scale(0.2F).temperature(2.0F) - .downfall(0.0F).effects(effects.build()).spawnSettings(spawnSettings.build()) - .generationSettings(generationSettings.build()).build(); + return new Biome.BiomeBuilder() + .precipitation(Precipitation.NONE) + .biomeCategory(isCaveBiome ? BiomeCategory.NONE : BiomeCategory.THEEND) + .depth(depth) + .scale(0.2F) + .temperature(2.0F) + .downfall(0.0F) + .specialEffects(effects.build()) + .mobSpawnSettings(spawnSettings.build()) + .generationSettings(generationSettings.build()) + .build(); } private static final class SpawnInfo { @@ -277,19 +277,19 @@ public class BiomeDefinition { } private static final class FeatureInfo { - Feature featureStep; + Decoration featureStep; ConfiguredFeature feature; } - + private static final class CarverInfo { - Carver carverStep; - ConfiguredCarver carver; + Carving carverStep; + ConfiguredWorldCarver carver; } public ResourceLocation getID() { return id; } - + public float getFodDensity() { return fogDensity; } @@ -302,7 +302,7 @@ public class BiomeDefinition { return hasCaves; } - public BiomeDefinition addCarver(Carver carverStep, ConfiguredCarver carver) { + public BiomeDefinition addCarver(Carving carverStep, ConfiguredWorldCarver carver) { CarverInfo info = new CarverInfo(); info.carverStep = carverStep; info.carver = carver; diff --git a/src/main/java/ru/betterend/world/biome/EndBiome.java b/src/main/java/ru/betterend/world/biome/EndBiome.java index 94c553a7..00e8bccc 100644 --- a/src/main/java/ru/betterend/world/biome/EndBiome.java +++ b/src/main/java/ru/betterend/world/biome/EndBiome.java @@ -3,14 +3,12 @@ package ru.betterend.world.biome; import java.io.InputStream; import java.util.List; import java.util.Random; - +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; import com.google.common.collect.Lists; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - -import net.minecraft.resources.ResourceLocation; -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; import ru.betterend.config.Configs; import ru.betterend.util.JsonFactory; import ru.betterend.util.StructureHelper; @@ -82,7 +80,7 @@ public class EndBiome { biome.biomeParent = this; subbiomes.add(biome); } - + public boolean containsSubBiome(EndBiome biome) { return subbiomes.contains(biome); } @@ -137,7 +135,7 @@ public class EndBiome { public float getFogDensity() { return fogDensity; } - + protected void readStructureList() { String ns = mcID.getNamespace(); String nm = mcID.getPath(); @@ -162,11 +160,11 @@ public class EndBiome { } } } - + public EndFeature getStructuresFeature() { return structuresFeature; } - + public Biome getActualBiome() { return this.actualBiome; } @@ -174,15 +172,15 @@ public class EndBiome { public float getGenChance() { return this.genChance; } - + public float getGenChanceImmutable() { return this.genChanceUnmutable; } - + public boolean hasCaves() { return hasCaves; } - + public void updateActualBiomes(Registry biomeRegistry) { subbiomes.forEach((sub) -> { if (sub != this) { @@ -194,7 +192,7 @@ public class EndBiome { } this.actualBiome = biomeRegistry.get(mcID); } - + @Override public boolean equals(Object obj) { if (obj == this) { @@ -203,7 +201,7 @@ public class EndBiome { EndBiome biome = (EndBiome) obj; return biome == null ? false : biome.mcID.equals(mcID); } - + @Override public int hashCode() { return mcID.hashCode(); diff --git a/src/main/java/ru/betterend/world/biome/air/BiomeIceStarfield.java b/src/main/java/ru/betterend/world/biome/air/BiomeIceStarfield.java index 9e2424c9..f90945e3 100644 --- a/src/main/java/ru/betterend/world/biome/air/BiomeIceStarfield.java +++ b/src/main/java/ru/betterend/world/biome/air/BiomeIceStarfield.java @@ -9,9 +9,15 @@ import ru.betterend.world.biome.EndBiome; public class BiomeIceStarfield extends EndBiome { public BiomeIceStarfield() { - super(new BiomeDefinition("ice_starfield").setFogColor(224, 245, 254).setFogDensity(2.2F) - .setFoliageColor(193, 244, 244).setGenChance(0.25F).setParticles(EndParticles.SNOWFLAKE, 0.002F) - .addStructureFeature(EndStructures.GIANT_ICE_STAR).addFeature(EndFeatures.ICE_STAR) - .addFeature(EndFeatures.ICE_STAR_SMALL).addMobSpawn(EntityType.ENDERMAN, 20, 1, 4)); + super(new BiomeDefinition("ice_starfield") + .setFogColor(224, 245, 254) + .setFogDensity(2.2F) + .setFoliageColor(193, 244, 244) + .setGenChance(0.25F) + .setParticles(EndParticles.SNOWFLAKE, 0.002F) + .addStructureFeature(EndStructures.GIANT_ICE_STAR) + .addFeature(EndFeatures.ICE_STAR) + .addFeature(EndFeatures.ICE_STAR_SMALL) + .addMobSpawn(EntityType.ENDERMAN, 20, 1, 4)); } } diff --git a/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java b/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java index 94368757..673f9556 100644 --- a/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java +++ b/src/main/java/ru/betterend/world/biome/cave/EndCaveBiome.java @@ -1,10 +1,9 @@ package ru.betterend.world.biome.cave; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.util.collection.WeightedList; import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.ai.behavior.WeightedList; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.Feature; import ru.betterend.registry.EndBiomes; import ru.betterend.world.biome.BiomeDefinition; @@ -15,42 +14,44 @@ import ru.betterend.world.features.terrain.caves.CaveChunkPopulatorFeature; public class EndCaveBiome extends EndBiome { private WeightedList> floorFeatures = new WeightedList>(); private WeightedList> ceilFeatures = new WeightedList>(); - + public EndCaveBiome(BiomeDefinition definition) { super(makeDef(definition)); } - + private static BiomeDefinition makeDef(BiomeDefinition definition) { - EndFeature feature = EndFeature.makeChunkFeature(definition.getID().getPath() + "_cave_populator", - new CaveChunkPopulatorFeature(() -> (EndCaveBiome) EndBiomes.getBiome(definition.getID()))); + EndFeature feature = EndFeature.makeChunkFeature( + definition.getID().getPath() + "_cave_populator", + new CaveChunkPopulatorFeature(() -> (EndCaveBiome) EndBiomes.getBiome(definition.getID())) + ); definition.addFeature(feature).setCaveBiome(); return definition; } - + public void addFloorFeature(Feature feature, int weight) { floorFeatures.add(feature, weight); } - + public void addCeilFeature(Feature feature, int weight) { ceilFeatures.add(feature, weight); } - + public Feature getFloorFeature(Random random) { - return floorFeatures.isEmpty() ? null : floorFeatures.pickRandom(random); + return floorFeatures.isEmpty() ? null : floorFeatures.getOne(random); } - + public Feature getCeilFeature(Random random) { - return ceilFeatures.isEmpty() ? null : ceilFeatures.pickRandom(random); + return ceilFeatures.isEmpty() ? null : ceilFeatures.getOne(random); } - + public float getFloorDensity() { return 0; } - + public float getCeilDensity() { return 0; } - + public BlockState getCeil(BlockPos pos) { return null; } diff --git a/src/main/java/ru/betterend/world/biome/cave/LushAuroraCaveBiome.java b/src/main/java/ru/betterend/world/biome/cave/LushAuroraCaveBiome.java index 5e8ddcb4..52ff7f1b 100644 --- a/src/main/java/ru/betterend/world/biome/cave/LushAuroraCaveBiome.java +++ b/src/main/java/ru/betterend/world/biome/cave/LushAuroraCaveBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.cave; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.registry.EndBlocks; @@ -12,34 +12,39 @@ import ru.betterend.world.biome.BiomeDefinition; public class LushAuroraCaveBiome extends EndCaveBiome { public LushAuroraCaveBiome() { - super(new BiomeDefinition("lush_aurora_cave").setFogColor(150, 30, 68).setFogDensity(2.0F) - .setPlantsColor(108, 25, 46).setWaterAndFogColor(186, 77, 237).setMusic(EndSounds.MUSIC_FOREST) - .setParticles(EndParticles.GLOWING_SPHERE, 0.001F).setSurface(EndBlocks.CAVE_MOSS)); - + super(new BiomeDefinition("lush_aurora_cave") + .setFogColor(150, 30, 68) + .setFogDensity(2.0F) + .setPlantsColor(108, 25, 46) + .setWaterAndFogColor(186, 77, 237) + .setMusic(EndSounds.MUSIC_FOREST) + .setParticles(EndParticles.GLOWING_SPHERE, 0.001F) + .setSurface(EndBlocks.CAVE_MOSS)); + this.addFloorFeature(EndFeatures.BIG_AURORA_CRYSTAL, 1); this.addFloorFeature(EndFeatures.CAVE_BUSH, 5); this.addFloorFeature(EndFeatures.CAVE_GRASS, 40); this.addFloorFeature(EndFeatures.END_STONE_STALAGMITE_CAVEMOSS, 5); - + this.addCeilFeature(EndFeatures.CAVE_BUSH, 1); this.addCeilFeature(EndFeatures.CAVE_PUMPKIN, 1); this.addCeilFeature(EndFeatures.RUBINEA, 3); this.addCeilFeature(EndFeatures.MAGNULA, 1); this.addCeilFeature(EndFeatures.END_STONE_STALACTITE_CAVEMOSS, 10); } - + @Override public float getFloorDensity() { return 0.2F; } - + @Override public float getCeilDensity() { return 0.1F; } - + @Override public BlockState getCeil(BlockPos pos) { - return EndBlocks.CAVE_MOSS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); + return EndBlocks.CAVE_MOSS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); } } diff --git a/src/main/java/ru/betterend/world/biome/land/AmberLandBiome.java b/src/main/java/ru/betterend/world/biome/land/AmberLandBiome.java index ea5ad1ce..43dd0840 100644 --- a/src/main/java/ru/betterend/world/biome/land/AmberLandBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/AmberLandBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndFeatures; @@ -12,15 +12,27 @@ import ru.betterend.world.biome.EndBiome; public class AmberLandBiome extends EndBiome { public AmberLandBiome() { - super(new BiomeDefinition("amber_land").setFogColor(255, 184, 71).setFogDensity(2.0F) - .setPlantsColor(219, 115, 38).setWaterAndFogColor(145, 108, 72).setMusic(EndSounds.MUSIC_FOREST) - .setParticles(EndParticles.AMBER_SPHERE, 0.001F).setSurface(EndBlocks.AMBER_MOSS) - .addFeature(EndFeatures.AMBER_ORE).addFeature(EndFeatures.END_LAKE_RARE) - .addFeature(EndFeatures.HELIX_TREE).addFeature(EndFeatures.LANCELEAF) - .addFeature(EndFeatures.GLOW_PILLAR).addFeature(EndFeatures.AMBER_GRASS) - .addFeature(EndFeatures.AMBER_ROOT).addFeature(EndFeatures.BULB_MOSS) - .addFeature(EndFeatures.BULB_MOSS_WOOD).addFeature(EndFeatures.CHARNIA_ORANGE) - .addFeature(EndFeatures.CHARNIA_RED).addStructureFeature(ConfiguredStructureFeatures.END_CITY) - .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4).addMobSpawn(EndEntities.END_SLIME, 30, 1, 2)); + super(new BiomeDefinition("amber_land") + .setFogColor(255, 184, 71) + .setFogDensity(2.0F) + .setPlantsColor(219, 115, 38) + .setWaterAndFogColor(145, 108, 72) + .setMusic(EndSounds.MUSIC_FOREST) + .setParticles(EndParticles.AMBER_SPHERE, 0.001F) + .setSurface(EndBlocks.AMBER_MOSS) + .addFeature(EndFeatures.AMBER_ORE) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(EndFeatures.HELIX_TREE) + .addFeature(EndFeatures.LANCELEAF) + .addFeature(EndFeatures.GLOW_PILLAR) + .addFeature(EndFeatures.AMBER_GRASS) + .addFeature(EndFeatures.AMBER_ROOT) + .addFeature(EndFeatures.BULB_MOSS) + .addFeature(EndFeatures.BULB_MOSS_WOOD) + .addFeature(EndFeatures.CHARNIA_ORANGE) + .addFeature(EndFeatures.CHARNIA_RED) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4) + .addMobSpawn(EndEntities.END_SLIME, 30, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/BlossomingSpiresBiome.java b/src/main/java/ru/betterend/world/biome/land/BlossomingSpiresBiome.java index 546443bb..8bd7c58c 100644 --- a/src/main/java/ru/betterend/world/biome/land/BlossomingSpiresBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/BlossomingSpiresBiome.java @@ -10,14 +10,26 @@ import ru.betterend.world.biome.EndBiome; public class BlossomingSpiresBiome extends EndBiome { public BlossomingSpiresBiome() { - super(new BiomeDefinition("blossoming_spires").setFogColor(241, 146, 229).setFogDensity(1.7F) - .setPlantsColor(122, 45, 122).setCaves(false).setSurface(EndBlocks.PINK_MOSS) - .setMusic(EndSounds.MUSIC_FOREST).setLoop(EndSounds.AMBIENT_BLOSSOMING_SPIRES) - .addFeature(EndFeatures.SPIRE).addFeature(EndFeatures.FLOATING_SPIRE).addFeature(EndFeatures.TENANEA) - .addFeature(EndFeatures.TENANEA_BUSH).addFeature(EndFeatures.BULB_VINE) - .addFeature(EndFeatures.BUSHY_GRASS).addFeature(EndFeatures.BUSHY_GRASS_WG) - .addFeature(EndFeatures.BLOSSOM_BERRY).addFeature(EndFeatures.TWISTED_MOSS) - .addFeature(EndFeatures.TWISTED_MOSS_WOOD).addFeature(EndFeatures.SILK_MOTH_NEST) - .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4).addMobSpawn(EndEntities.SILK_MOTH, 5, 1, 2)); + super(new BiomeDefinition("blossoming_spires") + .setFogColor(241, 146, 229) + .setFogDensity(1.7F) + .setPlantsColor(122, 45, 122) + .setCaves(false) + .setSurface(EndBlocks.PINK_MOSS) + .setMusic(EndSounds.MUSIC_FOREST) + .setLoop(EndSounds.AMBIENT_BLOSSOMING_SPIRES) + .addFeature(EndFeatures.SPIRE) + .addFeature(EndFeatures.FLOATING_SPIRE) + .addFeature(EndFeatures.TENANEA) + .addFeature(EndFeatures.TENANEA_BUSH) + .addFeature(EndFeatures.BULB_VINE) + .addFeature(EndFeatures.BUSHY_GRASS) + .addFeature(EndFeatures.BUSHY_GRASS_WG) + .addFeature(EndFeatures.BLOSSOM_BERRY) + .addFeature(EndFeatures.TWISTED_MOSS) + .addFeature(EndFeatures.TWISTED_MOSS_WOOD) + .addFeature(EndFeatures.SILK_MOTH_NEST) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4) + .addMobSpawn(EndEntities.SILK_MOTH, 5, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/ChorusForestBiome.java b/src/main/java/ru/betterend/world/biome/land/ChorusForestBiome.java index 343211dd..0e52fc83 100644 --- a/src/main/java/ru/betterend/world/biome/land/ChorusForestBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/ChorusForestBiome.java @@ -1,10 +1,10 @@ package ru.betterend.world.biome.land; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.gen.GenerationStep.Feature; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeatures; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; +import net.minecraft.data.worldgen.Features; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndFeatures; @@ -14,18 +14,30 @@ import ru.betterend.world.biome.EndBiome; public class ChorusForestBiome extends EndBiome { public ChorusForestBiome() { - super(new BiomeDefinition("chorus_forest").setFogColor(87, 26, 87).setFogDensity(1.5F) - .setPlantsColor(122, 45, 122).setWaterAndFogColor(73, 30, 73).setSurface(EndBlocks.CHORUS_NYLIUM) - .setParticles(ParticleTypes.PORTAL, 0.01F).setLoop(EndSounds.AMBIENT_CHORUS_FOREST) - .setMusic(EndSounds.MUSIC_DARK).addFeature(EndFeatures.VIOLECITE_LAYER) - .addFeature(EndFeatures.END_LAKE_RARE).addFeature(EndFeatures.PYTHADENDRON_TREE) - .addFeature(EndFeatures.PYTHADENDRON_BUSH).addFeature(EndFeatures.PURPLE_POLYPORE) - .addFeature(Feature.VEGETAL_DECORATION, ConfiguredFeatures.CHORUS_PLANT) - .addFeature(Feature.VEGETAL_DECORATION, ConfiguredFeatures.CHORUS_PLANT) - .addFeature(EndFeatures.CHORUS_GRASS).addFeature(EndFeatures.CHORUS_MUSHROOM) - .addFeature(EndFeatures.TAIL_MOSS).addFeature(EndFeatures.TAIL_MOSS_WOOD) - .addFeature(EndFeatures.CHARNIA_PURPLE).addFeature(EndFeatures.CHARNIA_RED_RARE) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) + super(new BiomeDefinition("chorus_forest") + .setFogColor(87, 26, 87) + .setFogDensity(1.5F) + .setPlantsColor(122, 45, 122) + .setWaterAndFogColor(73, 30, 73) + .setSurface(EndBlocks.CHORUS_NYLIUM) + .setParticles(ParticleTypes.PORTAL, 0.01F) + .setLoop(EndSounds.AMBIENT_CHORUS_FOREST) + .setMusic(EndSounds.MUSIC_DARK) + .addFeature(EndFeatures.VIOLECITE_LAYER) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(EndFeatures.PYTHADENDRON_TREE) + .addFeature(EndFeatures.PYTHADENDRON_BUSH) + .addFeature(EndFeatures.PURPLE_POLYPORE) + .addFeature(Decoration.VEGETAL_DECORATION, Features.CHORUS_PLANT) + .addFeature(Decoration.VEGETAL_DECORATION, Features.CHORUS_PLANT) + .addFeature(EndFeatures.CHORUS_GRASS) + .addFeature(EndFeatures.CHORUS_MUSHROOM) + .addFeature(EndFeatures.TAIL_MOSS) + .addFeature(EndFeatures.TAIL_MOSS_WOOD) + .addFeature(EndFeatures.CHARNIA_PURPLE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/CrystalMountainsBiome.java b/src/main/java/ru/betterend/world/biome/land/CrystalMountainsBiome.java index 06fcc42e..1b398d92 100644 --- a/src/main/java/ru/betterend/world/biome/land/CrystalMountainsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/CrystalMountainsBiome.java @@ -10,9 +10,13 @@ import ru.betterend.world.biome.EndBiome; public class CrystalMountainsBiome extends EndBiome { public CrystalMountainsBiome() { - super(new BiomeDefinition("crystal_mountains").setPlantsColor(255, 133, 211).setSurface(EndBlocks.CRYSTAL_MOSS) - .setMusic(EndSounds.MUSIC_OPENSPACE).addStructureFeature(EndStructures.MOUNTAIN) - .addFeature(EndFeatures.ROUND_CAVE).addFeature(EndFeatures.CRYSTAL_GRASS) + super(new BiomeDefinition("crystal_mountains") + .setPlantsColor(255, 133, 211) + .setSurface(EndBlocks.CRYSTAL_MOSS) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .addStructureFeature(EndStructures.MOUNTAIN) + .addFeature(EndFeatures.ROUND_CAVE) + .addFeature(EndFeatures.CRYSTAL_GRASS) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/DragonGraveyardsBiome.java b/src/main/java/ru/betterend/world/biome/land/DragonGraveyardsBiome.java index 4ac95163..127d0799 100644 --- a/src/main/java/ru/betterend/world/biome/land/DragonGraveyardsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/DragonGraveyardsBiome.java @@ -10,14 +10,24 @@ import ru.betterend.world.biome.EndBiome; public class DragonGraveyardsBiome extends EndBiome { public DragonGraveyardsBiome() { - super(new BiomeDefinition("dragon_graveyards").setGenChance(0.1F).setFogColor(244, 46, 79).setFogDensity(1.3F) - .setParticles(EndParticles.FIREFLY, 0.0007F).setMusic(EndSounds.MUSIC_OPENSPACE) - .setLoop(EndSounds.AMBIENT_GLOWING_GRASSLANDS).setSurface(EndBlocks.SANGNUM) - .setWaterAndFogColor(203, 59, 167).setPlantsColor(244, 46, 79) - .addFeature(EndFeatures.OBSIDIAN_PILLAR_BASEMENT).addFeature(EndFeatures.FALLEN_PILLAR) - .addFeature(EndFeatures.OBSIDIAN_BOULDER).addFeature(EndFeatures.GIGANTIC_AMARANITA) - .addFeature(EndFeatures.LARGE_AMARANITA).addFeature(EndFeatures.SMALL_AMARANITA) - .addFeature(EndFeatures.GLOBULAGUS).addFeature(EndFeatures.CLAWFERN) + super(new BiomeDefinition("dragon_graveyards") + .setGenChance(0.1F) + .setFogColor(244, 46, 79) + .setFogDensity(1.3F) + .setParticles(EndParticles.FIREFLY, 0.0007F) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .setLoop(EndSounds.AMBIENT_GLOWING_GRASSLANDS) + .setSurface(EndBlocks.SANGNUM) + .setWaterAndFogColor(203, 59, 167) + .setPlantsColor(244, 46, 79) + .addFeature(EndFeatures.OBSIDIAN_PILLAR_BASEMENT) + .addFeature(EndFeatures.FALLEN_PILLAR) + .addFeature(EndFeatures.OBSIDIAN_BOULDER) + .addFeature(EndFeatures.GIGANTIC_AMARANITA) + .addFeature(EndFeatures.LARGE_AMARANITA) + .addFeature(EndFeatures.SMALL_AMARANITA) + .addFeature(EndFeatures.GLOBULAGUS) + .addFeature(EndFeatures.CLAWFERN) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/DryShrublandBiome.java b/src/main/java/ru/betterend/world/biome/land/DryShrublandBiome.java index 77f81198..570c1cb9 100644 --- a/src/main/java/ru/betterend/world/biome/land/DryShrublandBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/DryShrublandBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndSounds; @@ -10,10 +10,18 @@ import ru.betterend.world.biome.EndBiome; public class DryShrublandBiome extends EndBiome { public DryShrublandBiome() { - super(new BiomeDefinition("dry_shrubland").setFogColor(132, 35, 13).setFogDensity(1.2F) - .setWaterAndFogColor(113, 88, 53).setPlantsColor(237, 122, 66).setSurface(EndBlocks.RUTISCUS) - .setMusic(EndSounds.MUSIC_OPENSPACE).addFeature(EndFeatures.ORANGO).addFeature(EndFeatures.AERIDIUM) - .addFeature(EndFeatures.LUTEBUS).addFeature(EndFeatures.LAMELLARIUM) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); + super(new BiomeDefinition("dry_shrubland") + .setFogColor(132, 35, 13) + .setFogDensity(1.2F) + .setWaterAndFogColor(113, 88, 53) + .setPlantsColor(237, 122, 66) + .setSurface(EndBlocks.RUTISCUS) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .addFeature(EndFeatures.ORANGO) + .addFeature(EndFeatures.AERIDIUM) + .addFeature(EndFeatures.LUTEBUS) + .addFeature(EndFeatures.LAMELLARIUM) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/DustWastelandsBiome.java b/src/main/java/ru/betterend/world/biome/land/DustWastelandsBiome.java index cc46c7db..85945dec 100644 --- a/src/main/java/ru/betterend/world/biome/land/DustWastelandsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/DustWastelandsBiome.java @@ -1,8 +1,8 @@ package ru.betterend.world.biome.land; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.world.entity.EntityType; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndSounds; import ru.betterend.world.biome.BiomeDefinition; @@ -10,10 +10,15 @@ import ru.betterend.world.biome.EndBiome; public class DustWastelandsBiome extends EndBiome { public DustWastelandsBiome() { - super(new BiomeDefinition("dust_wastelands").setFogColor(226, 239, 168).setFogDensity(2) - .setWaterAndFogColor(192, 180, 131).setSurface(EndBlocks.ENDSTONE_DUST) - .setParticles(ParticleTypes.WHITE_ASH, 0.01F).setLoop(EndSounds.AMBIENT_DUST_WASTELANDS) - .setMusic(EndSounds.MUSIC_OPENSPACE).addStructureFeature(ConfiguredStructureFeatures.END_CITY) + super(new BiomeDefinition("dust_wastelands") + .setFogColor(226, 239, 168) + .setFogDensity(2) + .setWaterAndFogColor(192, 180, 131) + .setSurface(EndBlocks.ENDSTONE_DUST) + .setParticles(ParticleTypes.WHITE_ASH, 0.01F) + .setLoop(EndSounds.AMBIENT_DUST_WASTELANDS) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .addStructureFeature(StructureFeatures.END_CITY) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/FoggyMushroomlandBiome.java b/src/main/java/ru/betterend/world/biome/land/FoggyMushroomlandBiome.java index 9f2f2184..cff6f813 100644 --- a/src/main/java/ru/betterend/world/biome/land/FoggyMushroomlandBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/FoggyMushroomlandBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndFeatures; @@ -13,20 +13,35 @@ import ru.betterend.world.biome.EndBiome; public class FoggyMushroomlandBiome extends EndBiome { public FoggyMushroomlandBiome() { - super(new BiomeDefinition("foggy_mushroomland").setPlantsColor(73, 210, 209).setFogColor(41, 122, 173) - .setFogDensity(3).setWaterAndFogColor(119, 227, 250) + super(new BiomeDefinition("foggy_mushroomland") + .setPlantsColor(73, 210, 209) + .setFogColor(41, 122, 173) + .setFogDensity(3) + .setWaterAndFogColor(119, 227, 250) .setSurface(EndBlocks.END_MOSS, EndBlocks.END_MYCELIUM) - .setParticles(EndParticles.GLOWING_SPHERE, 0.001F).setLoop(EndSounds.AMBIENT_FOGGY_MUSHROOMLAND) - .setMusic(EndSounds.MUSIC_FOREST).addStructureFeature(EndStructures.GIANT_MOSSY_GLOWSHROOM) - .addFeature(EndFeatures.END_LAKE).addFeature(EndFeatures.MOSSY_GLOWSHROOM) - .addFeature(EndFeatures.BLUE_VINE).addFeature(EndFeatures.UMBRELLA_MOSS) - .addFeature(EndFeatures.CREEPING_MOSS).addFeature(EndFeatures.DENSE_VINE) - .addFeature(EndFeatures.PEARLBERRY).addFeature(EndFeatures.CYAN_MOSS) - .addFeature(EndFeatures.CYAN_MOSS_WOOD).addFeature(EndFeatures.END_LILY) - .addFeature(EndFeatures.BUBBLE_CORAL).addFeature(EndFeatures.CHARNIA_CYAN) - .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE).addFeature(EndFeatures.CHARNIA_RED_RARE) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EndEntities.DRAGONFLY, 80, 2, 5) - .addMobSpawn(EndEntities.END_FISH, 20, 2, 5).addMobSpawn(EndEntities.CUBOZOA, 10, 3, 8) - .addMobSpawn(EndEntities.END_SLIME, 10, 1, 2).addMobSpawn(EntityType.ENDERMAN, 10, 1, 2)); + .setParticles(EndParticles.GLOWING_SPHERE, 0.001F) + .setLoop(EndSounds.AMBIENT_FOGGY_MUSHROOMLAND) + .setMusic(EndSounds.MUSIC_FOREST) + .addStructureFeature(EndStructures.GIANT_MOSSY_GLOWSHROOM) + .addFeature(EndFeatures.END_LAKE) + .addFeature(EndFeatures.MOSSY_GLOWSHROOM) + .addFeature(EndFeatures.BLUE_VINE) + .addFeature(EndFeatures.UMBRELLA_MOSS) + .addFeature(EndFeatures.CREEPING_MOSS) + .addFeature(EndFeatures.DENSE_VINE) + .addFeature(EndFeatures.PEARLBERRY) + .addFeature(EndFeatures.CYAN_MOSS) + .addFeature(EndFeatures.CYAN_MOSS_WOOD) + .addFeature(EndFeatures.END_LILY) + .addFeature(EndFeatures.BUBBLE_CORAL) + .addFeature(EndFeatures.CHARNIA_CYAN) + .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EndEntities.DRAGONFLY, 80, 2, 5) + .addMobSpawn(EndEntities.END_FISH, 20, 2, 5) + .addMobSpawn(EndEntities.CUBOZOA, 10, 3, 8) + .addMobSpawn(EndEntities.END_SLIME, 10, 1, 2) + .addMobSpawn(EntityType.ENDERMAN, 10, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/GlowingGrasslandsBiome.java b/src/main/java/ru/betterend/world/biome/land/GlowingGrasslandsBiome.java index 69521075..ffef3fe9 100644 --- a/src/main/java/ru/betterend/world/biome/land/GlowingGrasslandsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/GlowingGrasslandsBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndParticles; @@ -11,16 +11,29 @@ import ru.betterend.world.biome.EndBiome; public class GlowingGrasslandsBiome extends EndBiome { public GlowingGrasslandsBiome() { - super(new BiomeDefinition("glowing_grasslands").setFogColor(99, 228, 247).setFogDensity(1.3F) - .setParticles(EndParticles.FIREFLY, 0.001F).setMusic(EndSounds.MUSIC_OPENSPACE) - .setLoop(EndSounds.AMBIENT_GLOWING_GRASSLANDS).setSurface(EndBlocks.END_MOSS) - .setWaterAndFogColor(92, 250, 230).setPlantsColor(73, 210, 209).addFeature(EndFeatures.END_LAKE_RARE) - .addFeature(EndFeatures.LUMECORN).addFeature(EndFeatures.BLOOMING_COOKSONIA) - .addFeature(EndFeatures.SALTEAGO).addFeature(EndFeatures.VAIOLUSH_FERN).addFeature(EndFeatures.FRACTURN) - .addFeature(EndFeatures.UMBRELLA_MOSS_RARE).addFeature(EndFeatures.CREEPING_MOSS_RARE) - .addFeature(EndFeatures.TWISTED_UMBRELLA_MOSS_RARE).addFeature(EndFeatures.CHARNIA_CYAN) - .addFeature(EndFeatures.CHARNIA_GREEN).addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) - .addFeature(EndFeatures.CHARNIA_RED_RARE).addStructureFeature(ConfiguredStructureFeatures.END_CITY) + super(new BiomeDefinition("glowing_grasslands") + .setFogColor(99, 228, 247) + .setFogDensity(1.3F) + .setParticles(EndParticles.FIREFLY, 0.001F) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .setLoop(EndSounds.AMBIENT_GLOWING_GRASSLANDS) + .setSurface(EndBlocks.END_MOSS) + .setWaterAndFogColor(92, 250, 230) + .setPlantsColor(73, 210, 209) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(EndFeatures.LUMECORN) + .addFeature(EndFeatures.BLOOMING_COOKSONIA) + .addFeature(EndFeatures.SALTEAGO) + .addFeature(EndFeatures.VAIOLUSH_FERN) + .addFeature(EndFeatures.FRACTURN) + .addFeature(EndFeatures.UMBRELLA_MOSS_RARE) + .addFeature(EndFeatures.CREEPING_MOSS_RARE) + .addFeature(EndFeatures.TWISTED_UMBRELLA_MOSS_RARE) + .addFeature(EndFeatures.CHARNIA_CYAN) + .addFeature(EndFeatures.CHARNIA_GREEN) + .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addStructureFeature(StructureFeatures.END_CITY) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/LanternWoodsBiome.java b/src/main/java/ru/betterend/world/biome/land/LanternWoodsBiome.java index 5ffd7775..ef96a8c1 100644 --- a/src/main/java/ru/betterend/world/biome/land/LanternWoodsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/LanternWoodsBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndParticles; @@ -11,15 +11,29 @@ import ru.betterend.world.biome.EndBiome; public class LanternWoodsBiome extends EndBiome { public LanternWoodsBiome() { - super(new BiomeDefinition("lantern_woods").setFogColor(189, 82, 70).setFogDensity(1.1F) - .setWaterAndFogColor(171, 234, 226).setPlantsColor(254, 85, 57).setSurface(EndBlocks.RUTISCUS) - .setMusic(EndSounds.MUSIC_FOREST).setParticles(EndParticles.GLOWING_SPHERE, 0.001F) - .addFeature(EndFeatures.END_LAKE_NORMAL).addFeature(EndFeatures.FLAMAEA) - .addFeature(EndFeatures.LUCERNIA).addFeature(EndFeatures.LUCERNIA_BUSH).addFeature(EndFeatures.FILALUX) - .addFeature(EndFeatures.AERIDIUM).addFeature(EndFeatures.LAMELLARIUM) - .addFeature(EndFeatures.BOLUX_MUSHROOM).addFeature(EndFeatures.AURANT_POLYPORE) - .addFeature(EndFeatures.POND_ANEMONE).addFeature(EndFeatures.CHARNIA_ORANGE) - .addFeature(EndFeatures.CHARNIA_RED).addFeature(EndFeatures.RUSCUS).addFeature(EndFeatures.RUSCUS_WOOD) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); + super(new BiomeDefinition("lantern_woods") + .setFogColor(189, 82, 70) + .setFogDensity(1.1F) + .setWaterAndFogColor(171, 234, 226) + .setPlantsColor(254, 85, 57) + .setSurface(EndBlocks.RUTISCUS) + .setMusic(EndSounds.MUSIC_FOREST) + .setParticles(EndParticles.GLOWING_SPHERE, 0.001F) + .addFeature(EndFeatures.END_LAKE_NORMAL) + .addFeature(EndFeatures.FLAMAEA) + .addFeature(EndFeatures.LUCERNIA) + .addFeature(EndFeatures.LUCERNIA_BUSH) + .addFeature(EndFeatures.FILALUX) + .addFeature(EndFeatures.AERIDIUM) + .addFeature(EndFeatures.LAMELLARIUM) + .addFeature(EndFeatures.BOLUX_MUSHROOM) + .addFeature(EndFeatures.AURANT_POLYPORE) + .addFeature(EndFeatures.POND_ANEMONE) + .addFeature(EndFeatures.CHARNIA_ORANGE) + .addFeature(EndFeatures.CHARNIA_RED) + .addFeature(EndFeatures.RUSCUS) + .addFeature(EndFeatures.RUSCUS_WOOD) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/MegalakeBiome.java b/src/main/java/ru/betterend/world/biome/land/MegalakeBiome.java index ad87875c..998c1adc 100644 --- a/src/main/java/ru/betterend/world/biome/land/MegalakeBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/MegalakeBiome.java @@ -11,17 +11,31 @@ import ru.betterend.world.biome.EndBiome; public class MegalakeBiome extends EndBiome { public MegalakeBiome() { - super(new BiomeDefinition("megalake").setPlantsColor(73, 210, 209).setFogColor(178, 209, 248) - .setWaterAndFogColor(96, 163, 255).setFogDensity(1.75F).setMusic(EndSounds.MUSIC_WATER) - .setLoop(EndSounds.AMBIENT_MEGALAKE).setSurface(EndBlocks.END_MOSS, EndBlocks.ENDSTONE_DUST) - .setDepth(0F).addStructureFeature(EndStructures.MEGALAKE).addFeature(EndFeatures.END_LOTUS) - .addFeature(EndFeatures.END_LOTUS_LEAF).addFeature(EndFeatures.BUBBLE_CORAL_RARE) - .addFeature(EndFeatures.END_LILY_RARE).addFeature(EndFeatures.UMBRELLA_MOSS) - .addFeature(EndFeatures.CREEPING_MOSS).addFeature(EndFeatures.PEARLBERRY) - .addFeature(EndFeatures.CHARNIA_CYAN).addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) - .addFeature(EndFeatures.CHARNIA_RED_RARE).addFeature(EndFeatures.MENGER_SPONGE) - .addMobSpawn(EndEntities.DRAGONFLY, 50, 1, 3).addMobSpawn(EndEntities.END_FISH, 50, 3, 8) - .addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8).addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) + super(new BiomeDefinition("megalake") + .setPlantsColor(73, 210, 209) + .setFogColor(178, 209, 248) + .setWaterAndFogColor(96, 163, 255) + .setFogDensity(1.75F) + .setMusic(EndSounds.MUSIC_WATER) + .setLoop(EndSounds.AMBIENT_MEGALAKE) + .setSurface(EndBlocks.END_MOSS, EndBlocks.ENDSTONE_DUST) + .setDepth(0F) + .addStructureFeature(EndStructures.MEGALAKE) + .addFeature(EndFeatures.END_LOTUS) + .addFeature(EndFeatures.END_LOTUS_LEAF) + .addFeature(EndFeatures.BUBBLE_CORAL_RARE) + .addFeature(EndFeatures.END_LILY_RARE) + .addFeature(EndFeatures.UMBRELLA_MOSS) + .addFeature(EndFeatures.CREEPING_MOSS) + .addFeature(EndFeatures.PEARLBERRY) + .addFeature(EndFeatures.CHARNIA_CYAN) + .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addFeature(EndFeatures.MENGER_SPONGE) + .addMobSpawn(EndEntities.DRAGONFLY, 50, 1, 3) + .addMobSpawn(EndEntities.END_FISH, 50, 3, 8) + .addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8) + .addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) .addMobSpawn(EntityType.ENDERMAN, 10, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/MegalakeGroveBiome.java b/src/main/java/ru/betterend/world/biome/land/MegalakeGroveBiome.java index 3380f1da..93ca8dab 100644 --- a/src/main/java/ru/betterend/world/biome/land/MegalakeGroveBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/MegalakeGroveBiome.java @@ -12,18 +12,33 @@ import ru.betterend.world.biome.EndBiome; public class MegalakeGroveBiome extends EndBiome { public MegalakeGroveBiome() { - super(new BiomeDefinition("megalake_grove").setPlantsColor(73, 210, 209).setFogColor(178, 209, 248) - .setWaterAndFogColor(96, 163, 255).setFogDensity(2.0F).setParticles(EndParticles.GLOWING_SPHERE, 0.001F) - .setMusic(EndSounds.MUSIC_WATER).setLoop(EndSounds.AMBIENT_MEGALAKE_GROVE) - .setSurface(EndBlocks.END_MOSS).setDepth(0F).addStructureFeature(EndStructures.MEGALAKE_SMALL) - .addFeature(EndFeatures.LACUGROVE).addFeature(EndFeatures.END_LOTUS) - .addFeature(EndFeatures.END_LOTUS_LEAF).addFeature(EndFeatures.BUBBLE_CORAL_RARE) - .addFeature(EndFeatures.END_LILY_RARE).addFeature(EndFeatures.UMBRELLA_MOSS) - .addFeature(EndFeatures.PEARLBERRY).addFeature(EndFeatures.CREEPING_MOSS) - .addFeature(EndFeatures.CHARNIA_CYAN).addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) - .addFeature(EndFeatures.CHARNIA_RED_RARE).addFeature(EndFeatures.MENGER_SPONGE) - .addMobSpawn(EndEntities.DRAGONFLY, 20, 1, 3).addMobSpawn(EndEntities.END_FISH, 20, 3, 8) - .addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8).addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) + super(new BiomeDefinition("megalake_grove") + .setPlantsColor(73, 210, 209) + .setFogColor(178, 209, 248) + .setWaterAndFogColor(96, 163, 255) + .setFogDensity(2.0F) + .setParticles(EndParticles.GLOWING_SPHERE, 0.001F) + .setMusic(EndSounds.MUSIC_WATER) + .setLoop(EndSounds.AMBIENT_MEGALAKE_GROVE) + .setSurface(EndBlocks.END_MOSS) + .setDepth(0F) + .addStructureFeature(EndStructures.MEGALAKE_SMALL) + .addFeature(EndFeatures.LACUGROVE) + .addFeature(EndFeatures.END_LOTUS) + .addFeature(EndFeatures.END_LOTUS_LEAF) + .addFeature(EndFeatures.BUBBLE_CORAL_RARE) + .addFeature(EndFeatures.END_LILY_RARE) + .addFeature(EndFeatures.UMBRELLA_MOSS) + .addFeature(EndFeatures.PEARLBERRY) + .addFeature(EndFeatures.CREEPING_MOSS) + .addFeature(EndFeatures.CHARNIA_CYAN) + .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addFeature(EndFeatures.MENGER_SPONGE) + .addMobSpawn(EndEntities.DRAGONFLY, 20, 1, 3) + .addMobSpawn(EndEntities.END_FISH, 20, 3, 8) + .addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8) + .addMobSpawn(EndEntities.END_SLIME, 5, 1, 2) .addMobSpawn(EntityType.ENDERMAN, 10, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/NeonOasisBiome.java b/src/main/java/ru/betterend/world/biome/land/NeonOasisBiome.java index 9332aa0e..13fca7d6 100644 --- a/src/main/java/ru/betterend/world/biome/land/NeonOasisBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/NeonOasisBiome.java @@ -1,8 +1,8 @@ package ru.betterend.world.biome.land; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.world.entity.EntityType; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndSounds; @@ -11,10 +11,17 @@ import ru.betterend.world.biome.EndBiome; public class NeonOasisBiome extends EndBiome { public NeonOasisBiome() { - super(new BiomeDefinition("neon_oasis").setGenChance(0.5F).setFogColor(226, 239, 168).setFogDensity(2) - .setWaterAndFogColor(192, 180, 131).setSurface(EndBlocks.ENDSTONE_DUST, EndBlocks.END_MOSS) - .setParticles(ParticleTypes.WHITE_ASH, 0.01F).setLoop(EndSounds.AMBIENT_DUST_WASTELANDS) - .setMusic(EndSounds.MUSIC_OPENSPACE).addFeature(EndFeatures.NEON_CACTUS) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); + super(new BiomeDefinition("neon_oasis") + .setGenChance(0.5F) + .setFogColor(226, 239, 168) + .setFogDensity(2) + .setWaterAndFogColor(192, 180, 131) + .setSurface(EndBlocks.ENDSTONE_DUST, EndBlocks.END_MOSS) + .setParticles(ParticleTypes.WHITE_ASH, 0.01F) + .setLoop(EndSounds.AMBIENT_DUST_WASTELANDS) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .addFeature(EndFeatures.NEON_CACTUS) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/PaintedMountainsBiome.java b/src/main/java/ru/betterend/world/biome/land/PaintedMountainsBiome.java index b158608c..08e502a1 100644 --- a/src/main/java/ru/betterend/world/biome/land/PaintedMountainsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/PaintedMountainsBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.entity.EntityType; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndSounds; import ru.betterend.registry.EndStructures; @@ -10,10 +10,16 @@ import ru.betterend.world.biome.EndBiome; public class PaintedMountainsBiome extends EndBiome { public PaintedMountainsBiome() { - super(new BiomeDefinition("painted_mountains").setFogColor(226, 239, 168).setFogDensity(2).setCaves(false) - .setWaterAndFogColor(192, 180, 131).setMusic(EndSounds.MUSIC_OPENSPACE) - .setLoop(EndSounds.AMBIENT_DUST_WASTELANDS).setSurface(EndBlocks.ENDSTONE_DUST) - .setParticles(ParticleTypes.WHITE_ASH, 0.01F).addStructureFeature(EndStructures.PAINTED_MOUNTAIN) + super(new BiomeDefinition("painted_mountains") + .setFogColor(226, 239, 168) + .setFogDensity(2) + .setCaves(false) + .setWaterAndFogColor(192, 180, 131) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .setLoop(EndSounds.AMBIENT_DUST_WASTELANDS) + .setSurface(EndBlocks.ENDSTONE_DUST) + .setParticles(ParticleTypes.WHITE_ASH, 0.01F) + .addStructureFeature(EndStructures.PAINTED_MOUNTAIN) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/ShadowForestBiome.java b/src/main/java/ru/betterend/world/biome/land/ShadowForestBiome.java index 0ee6a1f5..d27dc451 100644 --- a/src/main/java/ru/betterend/world/biome/land/ShadowForestBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/ShadowForestBiome.java @@ -1,8 +1,8 @@ package ru.betterend.world.biome.land; -import net.minecraft.world.entity.EntityType; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.world.entity.EntityType; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndFeatures; @@ -12,18 +12,32 @@ import ru.betterend.world.biome.EndBiome; public class ShadowForestBiome extends EndBiome { public ShadowForestBiome() { - super(new BiomeDefinition("shadow_forest").setFogColor(0, 0, 0).setFogDensity(2.5F).setPlantsColor(45, 45, 45) - .setWaterAndFogColor(42, 45, 80).setSurface(EndBlocks.SHADOW_GRASS) - .setParticles(ParticleTypes.MYCELIUM, 0.01F).setLoop(EndSounds.AMBIENT_CHORUS_FOREST) - .setMusic(EndSounds.MUSIC_DARK).addFeature(EndFeatures.VIOLECITE_LAYER) - .addFeature(EndFeatures.END_LAKE_RARE).addFeature(EndFeatures.DRAGON_TREE) - .addFeature(EndFeatures.DRAGON_TREE_BUSH).addFeature(EndFeatures.SHADOW_PLANT) - .addFeature(EndFeatures.MURKWEED).addFeature(EndFeatures.NEEDLEGRASS) - .addFeature(EndFeatures.SHADOW_BERRY).addFeature(EndFeatures.TWISTED_VINE) - .addFeature(EndFeatures.PURPLE_POLYPORE).addFeature(EndFeatures.TAIL_MOSS) - .addFeature(EndFeatures.TAIL_MOSS_WOOD).addFeature(EndFeatures.CHARNIA_PURPLE) - .addFeature(EndFeatures.CHARNIA_RED_RARE).addStructureFeature(ConfiguredStructureFeatures.END_CITY) - .addMobSpawn(EndEntities.SHADOW_WALKER, 80, 2, 4).addMobSpawn(EntityType.ENDERMAN, 40, 1, 4) + super(new BiomeDefinition("shadow_forest") + .setFogColor(0, 0, 0) + .setFogDensity(2.5F) + .setPlantsColor(45, 45, 45) + .setWaterAndFogColor(42, 45, 80) + .setSurface(EndBlocks.SHADOW_GRASS) + .setParticles(ParticleTypes.MYCELIUM, 0.01F) + .setLoop(EndSounds.AMBIENT_CHORUS_FOREST) + .setMusic(EndSounds.MUSIC_DARK) + .addFeature(EndFeatures.VIOLECITE_LAYER) + .addFeature(EndFeatures.END_LAKE_RARE) + .addFeature(EndFeatures.DRAGON_TREE) + .addFeature(EndFeatures.DRAGON_TREE_BUSH) + .addFeature(EndFeatures.SHADOW_PLANT) + .addFeature(EndFeatures.MURKWEED) + .addFeature(EndFeatures.NEEDLEGRASS) + .addFeature(EndFeatures.SHADOW_BERRY) + .addFeature(EndFeatures.TWISTED_VINE) + .addFeature(EndFeatures.PURPLE_POLYPORE) + .addFeature(EndFeatures.TAIL_MOSS) + .addFeature(EndFeatures.TAIL_MOSS_WOOD) + .addFeature(EndFeatures.CHARNIA_PURPLE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EndEntities.SHADOW_WALKER, 80, 2, 4) + .addMobSpawn(EntityType.ENDERMAN, 40, 1, 4) .addMobSpawn(EntityType.PHANTOM, 1, 1, 2)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/SulphurSpringsBiome.java b/src/main/java/ru/betterend/world/biome/land/SulphurSpringsBiome.java index 161efd76..a1a50d00 100644 --- a/src/main/java/ru/betterend/world/biome/land/SulphurSpringsBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/SulphurSpringsBiome.java @@ -11,15 +11,27 @@ import ru.betterend.world.surface.SurfaceBuilders; public class SulphurSpringsBiome extends EndBiome { public SulphurSpringsBiome() { - super(new BiomeDefinition("sulphur_springs").setSurface(SurfaceBuilders.SULPHURIC_SURFACE) - .setMusic(EndSounds.MUSIC_OPENSPACE).setLoop(EndSounds.AMBIENT_SULPHUR_SPRINGS) - .setWaterColor(25, 90, 157).setWaterFogColor(30, 65, 61).setFogColor(207, 194, 62).setFogDensity(1.5F) - .setCaves(false).setDepth(0F).setParticles(EndParticles.SULPHUR_PARTICLE, 0.001F) - .addFeature(EndFeatures.GEYSER).addFeature(EndFeatures.SURFACE_VENT) - .addFeature(EndFeatures.SULPHURIC_LAKE).addFeature(EndFeatures.SULPHURIC_CAVE) - .addFeature(EndFeatures.HYDRALUX).addFeature(EndFeatures.CHARNIA_GREEN) - .addFeature(EndFeatures.CHARNIA_ORANGE).addFeature(EndFeatures.CHARNIA_RED_RARE) - .addMobSpawn(EndEntities.END_FISH, 50, 3, 8).addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8) + super(new BiomeDefinition("sulphur_springs") + .setSurface(SurfaceBuilders.SULPHURIC_SURFACE) + .setMusic(EndSounds.MUSIC_OPENSPACE) + .setLoop(EndSounds.AMBIENT_SULPHUR_SPRINGS) + .setWaterColor(25, 90, 157) + .setWaterFogColor(30, 65, 61) + .setFogColor(207, 194, 62) + .setFogDensity(1.5F) + .setCaves(false) + .setDepth(0F) + .setParticles(EndParticles.SULPHUR_PARTICLE, 0.001F) + .addFeature(EndFeatures.GEYSER) + .addFeature(EndFeatures.SURFACE_VENT) + .addFeature(EndFeatures.SULPHURIC_LAKE) + .addFeature(EndFeatures.SULPHURIC_CAVE) + .addFeature(EndFeatures.HYDRALUX) + .addFeature(EndFeatures.CHARNIA_GREEN) + .addFeature(EndFeatures.CHARNIA_ORANGE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addMobSpawn(EndEntities.END_FISH, 50, 3, 8) + .addMobSpawn(EndEntities.CUBOZOA, 50, 3, 8) .addMobSpawn(EntityType.ENDERMAN, 50, 1, 4)); } } diff --git a/src/main/java/ru/betterend/world/biome/land/UmbrellaJungleBiome.java b/src/main/java/ru/betterend/world/biome/land/UmbrellaJungleBiome.java index 29c8e5eb..9da34de6 100644 --- a/src/main/java/ru/betterend/world/biome/land/UmbrellaJungleBiome.java +++ b/src/main/java/ru/betterend/world/biome/land/UmbrellaJungleBiome.java @@ -1,7 +1,7 @@ package ru.betterend.world.biome.land; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeatures; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndParticles; @@ -11,18 +11,33 @@ import ru.betterend.world.biome.EndBiome; public class UmbrellaJungleBiome extends EndBiome { public UmbrellaJungleBiome() { - super(new BiomeDefinition("umbrella_jungle").setFogColor(87, 223, 221).setWaterAndFogColor(119, 198, 253) - .setFoliageColor(27, 183, 194).setFogDensity(2.3F).setParticles(EndParticles.JUNGLE_SPORE, 0.001F) - .setMusic(EndSounds.MUSIC_FOREST).setLoop(EndSounds.AMBIENT_UMBRELLA_JUNGLE) - .setSurface(EndBlocks.JUNGLE_MOSS).addFeature(EndFeatures.END_LAKE) - .addFeature(EndFeatures.UMBRELLA_TREE).addFeature(EndFeatures.JELLYSHROOM) - .addFeature(EndFeatures.TWISTED_UMBRELLA_MOSS).addFeature(EndFeatures.SMALL_JELLYSHROOM_FLOOR) - .addFeature(EndFeatures.JUNGLE_GRASS).addFeature(EndFeatures.CYAN_MOSS) - .addFeature(EndFeatures.CYAN_MOSS_WOOD).addFeature(EndFeatures.JUNGLE_FERN_WOOD) - .addFeature(EndFeatures.SMALL_JELLYSHROOM_WALL).addFeature(EndFeatures.SMALL_JELLYSHROOM_WOOD) - .addFeature(EndFeatures.SMALL_JELLYSHROOM_CEIL).addFeature(EndFeatures.JUNGLE_VINE) - .addFeature(EndFeatures.CHARNIA_CYAN).addFeature(EndFeatures.CHARNIA_GREEN) - .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE).addFeature(EndFeatures.CHARNIA_RED_RARE) - .addStructureFeature(ConfiguredStructureFeatures.END_CITY).addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); + super(new BiomeDefinition("umbrella_jungle") + .setFogColor(87, 223, 221) + .setWaterAndFogColor(119, 198, 253) + .setFoliageColor(27, 183, 194) + .setFogDensity(2.3F) + .setParticles(EndParticles.JUNGLE_SPORE, 0.001F) + .setMusic(EndSounds.MUSIC_FOREST) + .setLoop(EndSounds.AMBIENT_UMBRELLA_JUNGLE) + .setSurface(EndBlocks.JUNGLE_MOSS) + .addFeature(EndFeatures.END_LAKE) + .addFeature(EndFeatures.UMBRELLA_TREE) + .addFeature(EndFeatures.JELLYSHROOM) + .addFeature(EndFeatures.TWISTED_UMBRELLA_MOSS) + .addFeature(EndFeatures.SMALL_JELLYSHROOM_FLOOR) + .addFeature(EndFeatures.JUNGLE_GRASS) + .addFeature(EndFeatures.CYAN_MOSS) + .addFeature(EndFeatures.CYAN_MOSS_WOOD) + .addFeature(EndFeatures.JUNGLE_FERN_WOOD) + .addFeature(EndFeatures.SMALL_JELLYSHROOM_WALL) + .addFeature(EndFeatures.SMALL_JELLYSHROOM_WOOD) + .addFeature(EndFeatures.SMALL_JELLYSHROOM_CEIL) + .addFeature(EndFeatures.JUNGLE_VINE) + .addFeature(EndFeatures.CHARNIA_CYAN) + .addFeature(EndFeatures.CHARNIA_GREEN) + .addFeature(EndFeatures.CHARNIA_LIGHT_BLUE) + .addFeature(EndFeatures.CHARNIA_RED_RARE) + .addStructureFeature(StructureFeatures.END_CITY) + .addMobSpawn(EntityType.ENDERMAN, 50, 1, 2)); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/world/features/BiomeIslandFeature.java b/src/main/java/ru/betterend/world/features/BiomeIslandFeature.java index 16658b53..9d880546 100644 --- a/src/main/java/ru/betterend/world/features/BiomeIslandFeature.java +++ b/src/main/java/ru/betterend/world/features/BiomeIslandFeature.java @@ -1,17 +1,16 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.gen.surfacebuilder.SurfaceConfig; -import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.BlocksHelper; import ru.betterend.util.sdf.SDF; @@ -31,10 +30,10 @@ public class BiomeIslandFeature extends DefaultFeature { public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { Biome biome = world.getBiome(pos); - SurfaceConfig surfaceConfig = biome.getGenerationSettings().getSurfaceBuilderConfig(); + SurfaceBuilderConfiguration surfaceConfig = biome.getGenerationSettings().getSurfaceBuilderConfig(); BlockState topMaterial = surfaceConfig.getTopMaterial(); if (BlocksHelper.isFluid(topMaterial)) { - topBlock = ((TernarySurfaceConfig) surfaceConfig).getUnderwaterMaterial(); + topBlock = ((SurfaceBuilderBaseConfiguration) surfaceConfig).getUnderwaterMaterial(); } else { topBlock = topMaterial; } @@ -55,13 +54,12 @@ public class BiomeIslandFeature extends DefaultFeature { }); sdfCone = new SDFTranslate().setTranslate(0, -2, 0).setSource(sdfCone); sdfCone = new SDFDisplacement().setFunction(pos -> { - float deltaX = Math.abs(pos.getX()); - float deltaY = Math.abs(pos.getY()); - float deltaZ = Math.abs(pos.getZ()); + float deltaX = Math.abs(pos.x()); + float deltaY = Math.abs(pos.y()); + float deltaZ = Math.abs(pos.z()); if (deltaY < 2.0f && (deltaX < 3.0f || deltaZ < 3.0F)) return 0.0f; - return (float) simplexNoise.eval(CENTER.getX() + pos.getX(), CENTER.getY() + pos.getY(), - CENTER.getZ() + pos.getZ()); + return (float) simplexNoise.eval(CENTER.getX() + pos.x(), CENTER.getY() + pos.y(), CENTER.getZ() + pos.z()); }).setSource(sdfCone) .setReplaceFunction(state -> BlocksHelper.isFluid(state) || state.getMaterial().isReplaceable()); return sdfCone; diff --git a/src/main/java/ru/betterend/world/features/BlueVineFeature.java b/src/main/java/ru/betterend/world/features/BlueVineFeature.java index b74d5057..92fd0862 100644 --- a/src/main/java/ru/betterend/world/features/BlueVineFeature.java +++ b/src/main/java/ru/betterend/world/features/BlueVineFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; @@ -11,25 +10,24 @@ import ru.betterend.util.MHelper; public class BlueVineFeature extends ScatterFeature { private boolean small; - + public BlueVineFeature() { super(5); } @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - float d = MHelper.length(center.getX() - blockPos.getX(), center.getZ() - blockPos.getZ()) / radius * 0.6F - + random.nextFloat() * 0.4F; + float d = MHelper.length(center.getX() - blockPos.getX(), center.getZ() - blockPos.getZ()) / radius * 0.6F + random.nextFloat() * 0.4F; small = d > 0.5F; - return EndBlocks.BLUE_VINE_SEED.canPlaceAt(AIR, world, blockPos); + return EndBlocks.BLUE_VINE_SEED.canSurvive(AIR, world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { if (small) { - BlocksHelper.setWithoutUpdate(world, blockPos, - EndBlocks.BLUE_VINE_SEED.defaultBlockState().with(EndPlantWithAgeBlock.AGE, random.nextInt(4))); - } else { + BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.BLUE_VINE_SEED.defaultBlockState().setValue(EndPlantWithAgeBlock.AGE, random.nextInt(4))); + } + else { EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.BLUE_VINE_SEED); seed.growAdult(world, random, blockPos); } diff --git a/src/main/java/ru/betterend/world/features/CavePlantFeature.java b/src/main/java/ru/betterend/world/features/CavePlantFeature.java index 63c6b393..c3ed7edb 100644 --- a/src/main/java/ru/betterend/world/features/CavePlantFeature.java +++ b/src/main/java/ru/betterend/world/features/CavePlantFeature.java @@ -1,15 +1,14 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; import ru.betterend.util.BlocksHelper; public class CavePlantFeature extends FullHeightScatterFeature { private final Block plant; - + public CavePlantFeature(Block plant, int radius) { super(radius); this.plant = plant; @@ -17,11 +16,11 @@ public class CavePlantFeature extends FullHeightScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return plant.canPlaceAt(world.getBlockState(blockPos), world, blockPos); + return plant.canSurvive(world.getBlockState(blockPos), world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { BlocksHelper.setWithoutUpdate(world, blockPos, plant); } } diff --git a/src/main/java/ru/betterend/world/features/CavePumpkinFeature.java b/src/main/java/ru/betterend/world/features/CavePumpkinFeature.java index 83e477e7..09016953 100644 --- a/src/main/java/ru/betterend/world/features/CavePumpkinFeature.java +++ b/src/main/java/ru/betterend/world/features/CavePumpkinFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkGenerator; @@ -15,17 +14,17 @@ public class CavePumpkinFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.up()).isIn(EndTags.GEN_TERRAIN) || !world.isAir(pos) - || !world.isAir(pos.below())) { + if (!world.getBlockState(pos.above()).is(EndTags.GEN_TERRAIN) || !world.isEmptyBlock(pos) + || !world.isEmptyBlock(pos.below())) { return false; } int age = random.nextInt(4); BlocksHelper.setWithoutUpdate(world, pos, - EndBlocks.CAVE_PUMPKIN_SEED.defaultBlockState().with(BlockProperties.AGE, age)); + EndBlocks.CAVE_PUMPKIN_SEED.defaultBlockState().setValue(BlockProperties.AGE, age)); if (age > 1) { BlocksHelper.setWithoutUpdate(world, pos.below(), - EndBlocks.CAVE_PUMPKIN.defaultBlockState().with(BlockProperties.SMALL, age < 3)); + EndBlocks.CAVE_PUMPKIN.defaultBlockState().setValue(BlockProperties.SMALL, age < 3)); } return true; diff --git a/src/main/java/ru/betterend/world/features/CharniaFeature.java b/src/main/java/ru/betterend/world/features/CharniaFeature.java index 57636909..c8022a39 100644 --- a/src/main/java/ru/betterend/world/features/CharniaFeature.java +++ b/src/main/java/ru/betterend/world/features/CharniaFeature.java @@ -6,7 +6,7 @@ public class CharniaFeature extends UnderwaterPlantFeature { public CharniaFeature(Block plant) { super(plant, 6); } - + @Override protected int getChance() { return 3; diff --git a/src/main/java/ru/betterend/world/features/CrashedShipFeature.java b/src/main/java/ru/betterend/world/features/CrashedShipFeature.java index 4ac58a3b..64a5838e 100644 --- a/src/main/java/ru/betterend/world/features/CrashedShipFeature.java +++ b/src/main/java/ru/betterend/world/features/CrashedShipFeature.java @@ -1,25 +1,24 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.structure.Structure; -import net.minecraft.structure.Structure.StructureBlockInfo; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.structure.processor.BlockIgnoreStructureProcessor; -import net.minecraft.structure.processor.StructureProcessor; -import net.minecraft.structure.processor.StructureProcessorType; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.BlockIgnoreProcessor; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; +import net.minecraft.world.level.material.Material; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -28,13 +27,12 @@ import ru.betterend.util.StructureHelper; public class CrashedShipFeature extends NBTStructureFeature { private static final StructureProcessor REPLACER; private static final String STRUCTURE_PATH = "/data/minecraft/structures/end_city/ship.nbt"; - private Structure structure; + private StructureTemplate structure; @Override - protected Structure getStructure(WorldGenLevel world, BlockPos pos, Random random) { + protected StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random) { if (structure == null) { - structure = world.toServerWorld().getStructureManager() - .getStructureOrBlank(new ResourceLocation("end_city/ship")); + structure = world.getLevel().getStructureManager().getOrCreate(new ResourceLocation("end_city/ship")); if (structure == null) { structure = StructureHelper.readStructure(STRUCTURE_PATH); } @@ -49,21 +47,21 @@ public class CrashedShipFeature extends NBTStructureFeature { if (x * x + z * z < 3600) { return false; } - return pos.getY() > 5 && world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN); + return pos.getY() > 5 && world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN); } @Override protected Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random) { - return Rotation.random(random); + return Rotation.getRandom(random); } @Override - protected BlockMirror getMirror(WorldGenLevel world, BlockPos pos, Random random) { - return BlockMirror.values()[random.nextInt(3)]; + protected Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random) { + return Mirror.values()[random.nextInt(3)]; } @Override - protected int getYOffset(Structure structure, WorldGenLevel world, BlockPos pos, Random random) { + protected int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random) { int min = structure.getSize().getY() >> 3; int max = structure.getSize().getY() >> 2; return -MHelper.randRange(min, max, random); @@ -79,45 +77,44 @@ public class CrashedShipFeature extends NBTStructureFeature { NoneFeatureConfiguration featureConfig) { center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8); center = getGround(world, center); - BlockBox bounds = makeBox(center); + BoundingBox bounds = makeBox(center); if (!canSpawn(world, center, random)) { return false; } - Structure structure = getStructure(world, center, random); + StructureTemplate structure = getStructure(world, center, random); Rotation rotation = getRotation(world, center, random); - BlockMirror mirror = getMirror(world, center, random); - BlockPos offset = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN); - center = center.add(0, getYOffset(structure, world, center, random) + 0.5, 0); - StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror); - center = center.add(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); + Mirror mirror = getMirror(world, center, random); + BlockPos offset = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO); + center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0); + StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror); + center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); - BlockBox structB = structure.calculateBoundingBox(placementData, center); + BoundingBox structB = structure.getBoundingBox(placementData, center); bounds = StructureHelper.intersectBoxes(bounds, structB); addStructureData(placementData); - structure.place(world, center, placementData.setBoundingBox(bounds), random); + structure.placeInWorldChunk(world, center, placementData.setBoundingBox(bounds), random); StructureHelper.erodeIntense(world, bounds, random); - BlocksHelper.fixBlocks(world, new BlockPos(bounds.minX, bounds.minY, bounds.minZ), - new BlockPos(bounds.maxX, bounds.maxY, bounds.maxZ)); + BlocksHelper.fixBlocks(world, new BlockPos(bounds.x0, bounds.y0, bounds.z0), + new BlockPos(bounds.x1, bounds.y1, bounds.z1)); return true; } @Override - protected void addStructureData(StructurePlacementData data) { - data.addProcessor(BlockIgnoreStructureProcessor.IGNORE_AIR_AND_STRUCTURE_BLOCKS).addProcessor(REPLACER) - .setIgnoreEntities(true); + protected void addStructureData(StructurePlaceSettings data) { + data.addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR).addProcessor(REPLACER).setIgnoreEntities(true); } static { REPLACER = new StructureProcessor() { @Override - public StructureBlockInfo process(WorldView worldView, BlockPos pos, BlockPos blockPos, + public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, - StructurePlacementData structurePlacementData) { + StructurePlaceSettings structurePlacementData) { BlockState state = structureBlockInfo2.state; if (state.is(Blocks.SPAWNER) || state.getMaterial().equals(Material.WOOL)) { return new StructureBlockInfo(structureBlockInfo2.pos, AIR, null); diff --git a/src/main/java/ru/betterend/world/features/DefaultFeature.java b/src/main/java/ru/betterend/world/features/DefaultFeature.java index ede487d5..afaf1197 100644 --- a/src/main/java/ru/betterend/world/features/DefaultFeature.java +++ b/src/main/java/ru/betterend/world/features/DefaultFeature.java @@ -1,42 +1,42 @@ package ru.betterend.world.features; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.Heightmap.Types; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.util.BlocksHelper; public abstract class DefaultFeature extends Feature { protected static final BlockState AIR = Blocks.AIR.defaultBlockState(); protected static final BlockState WATER = Blocks.WATER.defaultBlockState(); - + public DefaultFeature() { super(NoneFeatureConfiguration.CODEC); } - + public static int getYOnSurface(WorldGenLevel world, int x, int z) { return world.getHeight(Types.WORLD_SURFACE, x, z); } - + public static int getYOnSurfaceWG(WorldGenLevel world, int x, int z) { return world.getHeight(Types.WORLD_SURFACE_WG, x, z); } - + public static BlockPos getPosOnSurface(WorldGenLevel world, BlockPos pos) { return world.getHeightmapPos(Types.WORLD_SURFACE, pos); } - + public static BlockPos getPosOnSurfaceWG(WorldGenLevel world, BlockPos pos) { return world.getHeightmapPos(Types.WORLD_SURFACE_WG, pos); } - + public static BlockPos getPosOnSurfaceRaycast(WorldGenLevel world, BlockPos pos) { return getPosOnSurfaceRaycast(world, pos, 256); } - + public static BlockPos getPosOnSurfaceRaycast(WorldGenLevel world, BlockPos pos, int dist) { int h = BlocksHelper.downRay(world, pos, dist); return pos.below(h); diff --git a/src/main/java/ru/betterend/world/features/DoublePlantFeature.java b/src/main/java/ru/betterend/world/features/DoublePlantFeature.java index 38bdabb6..8f1fa22a 100644 --- a/src/main/java/ru/betterend/world/features/DoublePlantFeature.java +++ b/src/main/java/ru/betterend/world/features/DoublePlantFeature.java @@ -1,11 +1,10 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -14,29 +13,29 @@ public class DoublePlantFeature extends ScatterFeature { private final Block smallPlant; private final Block largePlant; private Block plant; - + public DoublePlantFeature(Block smallPlant, Block largePlant, int radius) { super(radius); this.smallPlant = smallPlant; this.largePlant = largePlant; } - + @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - float d = MHelper.length(center.getX() - blockPos.getX(), center.getZ() - blockPos.getZ()) / radius * 0.6F - + random.nextFloat() * 0.4F; + float d = MHelper.length(center.getX() - blockPos.getX(), center.getZ() - blockPos.getZ()) / radius * 0.6F + random.nextFloat() * 0.4F; plant = d < 0.5F ? largePlant : smallPlant; - return plant.canPlaceAt(plant.defaultBlockState(), world, blockPos); + return plant.canSurvive(plant.defaultBlockState(), world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { if (plant instanceof DoublePlantBlock) { int rot = random.nextInt(4); - BlockState state = plant.defaultBlockState().with(DoublePlantBlock.ROTATION, rot); + BlockState state = plant.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot); BlocksHelper.setWithoutUpdate(world, blockPos, state); - BlocksHelper.setWithoutUpdate(world, blockPos.up(), state.with(DoublePlantBlock.TOP, true)); - } else { + BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(DoublePlantBlock.TOP, true)); + } + else { BlocksHelper.setWithoutUpdate(world, blockPos, plant); } } diff --git a/src/main/java/ru/betterend/world/features/EndFeature.java b/src/main/java/ru/betterend/world/features/EndFeature.java index ac26405d..d9328029 100644 --- a/src/main/java/ru/betterend/world/features/EndFeature.java +++ b/src/main/java/ru/betterend/world/features/EndFeature.java @@ -1,23 +1,23 @@ package ru.betterend.world.features; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.structure.rule.BlockMatchRuleTest; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.data.BuiltinRegistries; import net.minecraft.core.Registry; -import net.minecraft.world.gen.CountConfig; -import net.minecraft.world.gen.GenerationStep; -import net.minecraft.world.gen.decorator.ChanceDecoratorConfig; -import net.minecraft.world.gen.decorator.Decorator; -import net.minecraft.world.gen.decorator.RangeDecoratorConfig; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.Features; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeatures; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.FeatureConfig; -import net.minecraft.world.level.levelgen.feature.OreFeatureConfig; +import net.minecraft.world.level.levelgen.feature.configurations.CountConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; +import net.minecraft.world.level.levelgen.feature.configurations.RangeDecoratorConfiguration; +import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration; +import net.minecraft.world.level.levelgen.placement.FeatureDecorator; +import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; import ru.betterend.BetterEnd; import ru.betterend.blocks.complex.StoneMaterial; import ru.betterend.world.features.terrain.OreLayerFeature; @@ -25,117 +25,100 @@ import ru.betterend.world.features.terrain.OreLayerFeature; public class EndFeature { private Feature feature; private ConfiguredFeature featureConfigured; - private GenerationStep.Feature featureStep; - - protected EndFeature() { - } - - public EndFeature(Feature feature, ConfiguredFeature configuredFeature, - GenerationStep.Feature featureStep) { + private GenerationStep.Decoration featureStep; + + protected EndFeature() {} + + public EndFeature(Feature feature, ConfiguredFeature configuredFeature, GenerationStep.Decoration featureStep) { this.featureStep = featureStep; this.feature = feature; this.featureConfigured = configuredFeature; } - - public EndFeature(String name, Feature feature, GenerationStep.Feature featureStep, - ConfiguredFeature configuredFeature) { + + public EndFeature(String name, Feature feature, GenerationStep.Decoration featureStep, ConfiguredFeature configuredFeature) { ResourceLocation id = BetterEnd.makeID(name); this.featureStep = featureStep; this.feature = Registry.register(Registry.FEATURE, id, feature); this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, configuredFeature); } - + public EndFeature(String name, Feature feature) { ResourceLocation id = BetterEnd.makeID(name); - this.featureStep = GenerationStep.Feature.VEGETAL_DECORATION; + this.featureStep = GenerationStep.Decoration.VEGETAL_DECORATION; this.feature = Registry.register(Registry.FEATURE, id, feature); - this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, feature - .configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(100)))); + this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(100)))); } - + public EndFeature(String name, Feature feature, int density) { ResourceLocation id = BetterEnd.makeID(name); - this.featureStep = GenerationStep.Feature.VEGETAL_DECORATION; + this.featureStep = GenerationStep.Decoration.VEGETAL_DECORATION; this.feature = Registry.register(Registry.FEATURE, id, feature); - this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, - feature.configure(FeatureConfig.DEFAULT).decorate(ConfiguredFeatures.Decorators.SQUARE_HEIGHTMAP) - .repeatRandomly(density)); + this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, feature.configured(FeatureConfiguration.NONE).decorated(Features.Decorators.HEIGHTMAP_SQUARE).countRandom(density)); } - + public static EndFeature makeRawGenFeature(String name, Feature feature, int chance) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(chance))); - return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); + return new EndFeature(name, feature, GenerationStep.Decoration.RAW_GENERATION, configured); } - + public static EndFeature makeLakeFeature(String name, Feature feature, int chance) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.WATER_LAKE.configure(new ChanceDecoratorConfig(chance))); - return new EndFeature(name, feature, GenerationStep.Feature.LAKES, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.WATER_LAKE.configured(new ChanceDecoratorConfiguration(chance))); + return new EndFeature(name, feature, GenerationStep.Decoration.LAKES, configured); } - - public static EndFeature makeOreFeature(String name, Block blockOre, int veins, int veinSize, int offset, int minY, - int maxY) { + + public static EndFeature makeOreFeature(String name, Block blockOre, int veins, int veinSize, int offset, int minY, int maxY) { EndFeature newFeature = new EndFeature(); - OreFeatureConfig featureConfig = new OreFeatureConfig(new BlockMatchRuleTest(Blocks.END_STONE), - blockOre.defaultBlockState(), veinSize); - RangeDecoratorConfig rangeDecorator = new RangeDecoratorConfig(offset, minY, maxY); - ConfiguredFeature oreFeature = Feature.ORE.configure(featureConfig) - .decorate(Decorator.RANGE.configure(rangeDecorator)).spreadHorizontally().repeat(veins); + OreConfiguration featureConfig = new OreConfiguration(new BlockMatchTest(Blocks.END_STONE), blockOre.defaultBlockState(), veinSize); + RangeDecoratorConfiguration rangeDecorator = new RangeDecoratorConfiguration(offset, minY, maxY); + ConfiguredFeature oreFeature = Feature.ORE.configured(featureConfig) + .decorated(FeatureDecorator.RANGE.configured(rangeDecorator)) + .squared() + .count(veins); newFeature.feature = Feature.ORE; - newFeature.featureStep = GenerationStep.Feature.UNDERGROUND_ORES; - newFeature.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, BetterEnd.makeID(name), - oreFeature); - + newFeature.featureStep = GenerationStep.Decoration.UNDERGROUND_ORES; + newFeature.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, BetterEnd.makeID(name), oreFeature); + return newFeature; } - - public static EndFeature makeLayerFeature(String name, BlockState state, float radius, int minY, int maxY, - int count) { + + public static EndFeature makeLayerFeature(String name, BlockState state, float radius, int minY, int maxY, int count) { OreLayerFeature layer = new OreLayerFeature(state, radius, minY, maxY); - ConfiguredFeature configured = layer.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.COUNT.configure(new CountConfig(count))); - return new EndFeature(name, layer, GenerationStep.Feature.UNDERGROUND_ORES, configured); + ConfiguredFeature configured = layer.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); + return new EndFeature(name, layer, GenerationStep.Decoration.UNDERGROUND_ORES, configured); } - + public static EndFeature makeLayerFeature(String name, Block block, float radius, int minY, int maxY, int count) { OreLayerFeature layer = new OreLayerFeature(block.defaultBlockState(), radius, minY, maxY); - ConfiguredFeature configured = layer.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.COUNT.configure(new CountConfig(count))); - return new EndFeature(name, layer, GenerationStep.Feature.UNDERGROUND_ORES, configured); + ConfiguredFeature configured = layer.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); + return new EndFeature(name, layer, GenerationStep.Decoration.UNDERGROUND_ORES, configured); } - - public static EndFeature makeLayerFeature(String name, StoneMaterial material, float radius, int minY, int maxY, - int count) { + + public static EndFeature makeLayerFeature(String name, StoneMaterial material, float radius, int minY, int maxY, int count) { OreLayerFeature layer = new OreLayerFeature(material.stone.defaultBlockState(), radius, minY, maxY); - ConfiguredFeature configured = layer.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.COUNT.configure(new CountConfig(count))); - return new EndFeature(name, layer, GenerationStep.Feature.UNDERGROUND_ORES, configured); + ConfiguredFeature configured = layer.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); + return new EndFeature(name, layer, GenerationStep.Decoration.UNDERGROUND_ORES, configured); } - + public static EndFeature makeChunkFeature(String name, Feature feature) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.COUNT.configure(new CountConfig(1))); - return new EndFeature(name, feature, GenerationStep.Feature.LOCAL_MODIFICATIONS, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1))); + return new EndFeature(name, feature, GenerationStep.Decoration.LOCAL_MODIFICATIONS, configured); } - + public static EndFeature makeChansedFeature(String name, Feature feature, int chance) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(chance))); - return new EndFeature(name, feature, GenerationStep.Feature.SURFACE_STRUCTURES, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); + return new EndFeature(name, feature, GenerationStep.Decoration.SURFACE_STRUCTURES, configured); } - + public static EndFeature makeCountRawFeature(String name, Feature feature, int chance) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT) - .decorate(Decorator.COUNT.configure(new CountConfig(chance))); - return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(chance))); + return new EndFeature(name, feature, GenerationStep.Decoration.RAW_GENERATION, configured); } - + public static EndFeature makeFeatureConfigured(String name, Feature feature) { - ConfiguredFeature configured = feature.configure(FeatureConfig.DEFAULT); - return new EndFeature(name, feature, GenerationStep.Feature.RAW_GENERATION, configured); + ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE); + return new EndFeature(name, feature, GenerationStep.Decoration.RAW_GENERATION, configured); } - + public Feature getFeature() { return feature; } @@ -144,7 +127,7 @@ public class EndFeature { return featureConfigured; } - public GenerationStep.Feature getFeatureStep() { + public GenerationStep.Decoration getFeatureStep() { return featureStep; } } diff --git a/src/main/java/ru/betterend/world/features/EndLilyFeature.java b/src/main/java/ru/betterend/world/features/EndLilyFeature.java index 598a3afc..6172ddf4 100644 --- a/src/main/java/ru/betterend/world/features/EndLilyFeature.java +++ b/src/main/java/ru/betterend/world/features/EndLilyFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.EndLilySeedBlock; @@ -13,11 +12,11 @@ public class EndLilyFeature extends UnderwaterPlantScatter { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { EndLilySeedBlock seed = (EndLilySeedBlock) EndBlocks.END_LILY_SEED; seed.grow(world, random, blockPos); } - + @Override protected int getChance() { return 15; diff --git a/src/main/java/ru/betterend/world/features/EndLotusFeature.java b/src/main/java/ru/betterend/world/features/EndLotusFeature.java index 6de29310..ce462ce3 100644 --- a/src/main/java/ru/betterend/world/features/EndLotusFeature.java +++ b/src/main/java/ru/betterend/world/features/EndLotusFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.EndLotusSeedBlock; @@ -13,11 +12,11 @@ public class EndLotusFeature extends UnderwaterPlantScatter { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { EndLotusSeedBlock seed = (EndLotusSeedBlock) EndBlocks.END_LOTUS_SEED; seed.grow(world, random, blockPos); } - + @Override protected int getChance() { return 15; diff --git a/src/main/java/ru/betterend/world/features/EndLotusLeafFeature.java b/src/main/java/ru/betterend/world/features/EndLotusLeafFeature.java index 3ea237c6..9701f584 100644 --- a/src/main/java/ru/betterend/world/features/EndLotusLeafFeature.java +++ b/src/main/java/ru/betterend/world/features/EndLotusLeafFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.EndLotusLeafBlock; import ru.betterend.registry.EndBlocks; @@ -19,48 +18,46 @@ public class EndLotusLeafFeature extends ScatterFeature { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { if (canGenerate(world, blockPos)) { generateLeaf(world, blockPos); } } - + @Override protected int getChance() { return 15; } - + @Override protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) { return getPosOnSurface(world, pos); } - + private void generateLeaf(WorldGenLevel world, BlockPos pos) { MutableBlockPos p = new MutableBlockPos(); BlockState leaf = EndBlocks.END_LOTUS_LEAF.defaultBlockState(); - BlocksHelper.setWithoutUpdate(world, pos, leaf.with(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM)); - for (Direction move : BlocksHelper.HORIZONTAL) { - BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf - .with(EndLotusLeafBlock.HORIZONTAL_FACING, move).with(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE)); + BlocksHelper.setWithoutUpdate(world, pos, leaf.setValue(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM)); + for (Direction move: BlocksHelper.HORIZONTAL) { + BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, move).setValue(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE)); } - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i ++) { Direction d1 = BlocksHelper.HORIZONTAL[i]; Direction d2 = BlocksHelper.HORIZONTAL[(i + 1) & 3]; - BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), - leaf.with(EndLotusLeafBlock.HORIZONTAL_FACING, d1).with(EndLotusLeafBlock.SHAPE, TripleShape.TOP)); + BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, d1).setValue(EndLotusLeafBlock.SHAPE, TripleShape.TOP)); } } - + private boolean canGenerate(WorldGenLevel world, BlockPos pos) { MutableBlockPos p = new MutableBlockPos(); p.setY(pos.getY()); int count = 0; - for (int x = -1; x < 2; x++) { + for (int x = -1; x < 2; x ++) { p.setX(pos.getX() + x); - for (int z = -1; z < 2; z++) { + for (int z = -1; z < 2; z ++) { p.setZ(pos.getZ() + z); - if (world.isAir(p) && world.getBlockState(p.below()).is(Blocks.WATER)) - count++; + if (world.isEmptyBlock(p) && world.getBlockState(p.below()).is(Blocks.WATER)) + count ++; } } return count == 9; @@ -68,6 +65,6 @@ public class EndLotusLeafFeature extends ScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return world.isAir(blockPos) && world.getBlockState(blockPos.below()).is(Blocks.WATER); + return world.isEmptyBlock(blockPos) && world.getBlockState(blockPos.below()).is(Blocks.WATER); } } diff --git a/src/main/java/ru/betterend/world/features/FilaluxFeature.java b/src/main/java/ru/betterend/world/features/FilaluxFeature.java index e263c2f5..8ad288b0 100644 --- a/src/main/java/ru/betterend/world/features/FilaluxFeature.java +++ b/src/main/java/ru/betterend/world/features/FilaluxFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.registry.EndBlocks; @@ -19,13 +18,13 @@ public class FilaluxFeature extends SkyScatterFeature { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { BlockState vine = EndBlocks.FILALUX.defaultBlockState(); BlockState wings = EndBlocks.FILALUX_WINGS.defaultBlockState(); BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.FILALUX_LANTERN); - BlocksHelper.setWithoutUpdate(world, blockPos.up(), wings.with(Properties.FACING, Direction.UP)); - for (Direction dir : BlocksHelper.HORIZONTAL) { - BlocksHelper.setWithoutUpdate(world, blockPos.offset(dir), wings.with(Properties.FACING, dir)); + BlocksHelper.setWithoutUpdate(world, blockPos.above(), wings.setValue(BlockStateProperties.FACING, Direction.UP)); + for (Direction dir: BlocksHelper.HORIZONTAL) { + BlocksHelper.setWithoutUpdate(world, blockPos.relative(dir), wings.setValue(BlockStateProperties.FACING, dir)); } int length = MHelper.randRange(1, 3, random); for (int i = 1; i <= length; i++) { @@ -33,7 +32,7 @@ public class FilaluxFeature extends SkyScatterFeature { if (i > 1) { shape = i == length ? TripleShape.BOTTOM : TripleShape.MIDDLE; } - BlocksHelper.setWithoutUpdate(world, blockPos.down(i), vine.with(BlockProperties.TRIPLE_SHAPE, shape)); + BlocksHelper.setWithoutUpdate(world, blockPos.below(i), vine.setValue(BlockProperties.TRIPLE_SHAPE, shape)); } } } diff --git a/src/main/java/ru/betterend/world/features/FullHeightScatterFeature.java b/src/main/java/ru/betterend/world/features/FullHeightScatterFeature.java index 7253dd35..4de057f0 100644 --- a/src/main/java/ru/betterend/world/features/FullHeightScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/FullHeightScatterFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.world.Heightmap; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -22,12 +21,12 @@ public abstract class FullHeightScatterFeature extends DefaultFeature { public abstract boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius); - public abstract void place(WorldGenLevel world, Random random, BlockPos blockPos); + public abstract void generate(WorldGenLevel world, Random random, BlockPos blockPos); @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos center, NoneFeatureConfiguration featureConfig) { - int maxY = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, center.getX(), center.getZ()); + int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, center.getX(), center.getZ()); int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY); for (int y = maxY; y > minY; y--) { POS.set(center.getX(), y, center.getZ()); diff --git a/src/main/java/ru/betterend/world/features/GlowPillarFeature.java b/src/main/java/ru/betterend/world/features/GlowPillarFeature.java index f63576e4..64aea15c 100644 --- a/src/main/java/ru/betterend/world/features/GlowPillarFeature.java +++ b/src/main/java/ru/betterend/world/features/GlowPillarFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; @@ -14,15 +13,15 @@ public class GlowPillarFeature extends ScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return EndBlocks.GLOWING_PILLAR_SEED.canPlaceAt(AIR, world, blockPos); + return EndBlocks.GLOWING_PILLAR_SEED.canSurvive(AIR, world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.GLOWING_PILLAR_SEED); seed.growAdult(world, random, blockPos); } - + @Override protected int getChance() { return 10; diff --git a/src/main/java/ru/betterend/world/features/HydraluxFeature.java b/src/main/java/ru/betterend/world/features/HydraluxFeature.java index a4004fee..08f7f35c 100644 --- a/src/main/java/ru/betterend/world/features/HydraluxFeature.java +++ b/src/main/java/ru/betterend/world/features/HydraluxFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.HydraluxSaplingBlock; @@ -13,11 +12,11 @@ public class HydraluxFeature extends UnderwaterPlantScatter { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { HydraluxSaplingBlock seed = (HydraluxSaplingBlock) EndBlocks.HYDRALUX_SAPLING; seed.grow(world, random, blockPos); } - + @Override protected int getChance() { return 15; diff --git a/src/main/java/ru/betterend/world/features/InvertedScatterFeature.java b/src/main/java/ru/betterend/world/features/InvertedScatterFeature.java index fd900d57..4478357d 100644 --- a/src/main/java/ru/betterend/world/features/InvertedScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/InvertedScatterFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.world.Heightmap; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -22,16 +21,16 @@ public abstract class InvertedScatterFeature extends DefaultFeature { public abstract boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius); - public abstract void place(WorldGenLevel world, Random random, BlockPos blockPos); + public abstract void generate(WorldGenLevel world, Random random, BlockPos blockPos); @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos center, NoneFeatureConfiguration featureConfig) { - int maxY = world.getTopY(Heightmap.Type.WORLD_SURFACE, center.getX(), center.getZ()); + int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ()); int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY); for (int y = maxY; y > minY; y--) { POS.set(center.getX(), y, center.getZ()); - if (world.getBlockState(POS).isAir() && !world.getBlockState(POS.up()).isAir()) { + if (world.getBlockState(POS).isAir() && !world.getBlockState(POS.above()).isAir()) { float r = MHelper.randRange(radius * 0.5F, radius, random); int count = MHelper.floor(r * r * MHelper.randRange(0.5F, 1.5F, random)); for (int i = 0; i < count; i++) { diff --git a/src/main/java/ru/betterend/world/features/LanceleafFeature.java b/src/main/java/ru/betterend/world/features/LanceleafFeature.java index aaff0656..6724b0b0 100644 --- a/src/main/java/ru/betterend/world/features/LanceleafFeature.java +++ b/src/main/java/ru/betterend/world/features/LanceleafFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; @@ -14,15 +13,15 @@ public class LanceleafFeature extends ScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return EndBlocks.LANCELEAF_SEED.canPlaceAt(AIR, world, blockPos); + return EndBlocks.LANCELEAF_SEED.canSurvive(AIR, world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.LANCELEAF_SEED); seed.growAdult(world, random, blockPos); } - + @Override protected int getChance() { return 5; diff --git a/src/main/java/ru/betterend/world/features/ListFeature.java b/src/main/java/ru/betterend/world/features/ListFeature.java index 69c2dd13..15c980c4 100644 --- a/src/main/java/ru/betterend/world/features/ListFeature.java +++ b/src/main/java/ru/betterend/world/features/ListFeature.java @@ -2,26 +2,25 @@ package ru.betterend.world.features; import java.util.List; import java.util.Random; - -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import ru.betterend.registry.EndTags; import ru.betterend.util.StructureHelper; public class ListFeature extends NBTStructureFeature { private final List list; private StructureInfo selected; - + public ListFeature(List list) { this.list = list; } - + @Override - protected Structure getStructure(WorldGenLevel world, BlockPos pos, Random random) { + protected StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random) { selected = list.get(random.nextInt(list.size())); return selected.getStructure(); } @@ -30,21 +29,21 @@ public class ListFeature extends NBTStructureFeature { protected boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random) { int cx = pos.getX() >> 4; int cz = pos.getZ() >> 4; - return ((cx + cz) & 1) == 0 && pos.getY() > 58 && world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN); + return ((cx + cz) & 1) == 0 && pos.getY() > 58 && world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN); } @Override protected Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random) { - return Rotation.random(random); + return Rotation.getRandom(random); } @Override - protected BlockMirror getMirror(WorldGenLevel world, BlockPos pos, Random random) { - return BlockMirror.values()[random.nextInt(3)]; + protected Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random) { + return Mirror.values()[random.nextInt(3)]; } @Override - protected int getYOffset(Structure structure, WorldGenLevel world, BlockPos pos, Random random) { + protected int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random) { return selected.offsetY; } @@ -52,25 +51,24 @@ public class ListFeature extends NBTStructureFeature { protected TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random) { return selected.terrainMerge; } - + @Override - protected void addStructureData(StructurePlacementData data) { - } - + protected void addStructureData(StructurePlaceSettings data) {} + public static final class StructureInfo { public final TerrainMerge terrainMerge; public final String structurePath; public final int offsetY; - - private Structure structure; - + + private StructureTemplate structure; + public StructureInfo(String structurePath, int offsetY, TerrainMerge terrainMerge) { this.terrainMerge = terrainMerge; this.structurePath = structurePath; this.offsetY = offsetY; } - - public Structure getStructure() { + + public StructureTemplate getStructure() { if (structure == null) { structure = StructureHelper.readStructure(structurePath); } diff --git a/src/main/java/ru/betterend/world/features/MengerSpongeFeature.java b/src/main/java/ru/betterend/world/features/MengerSpongeFeature.java index 5a20b737..669c8f7f 100644 --- a/src/main/java/ru/betterend/world/features/MengerSpongeFeature.java +++ b/src/main/java/ru/betterend/world/features/MengerSpongeFeature.java @@ -2,34 +2,33 @@ package ru.betterend.world.features; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; public class MengerSpongeFeature extends UnderwaterPlantScatter { private static final Function REPLACE; - + public MengerSpongeFeature(int radius) { super(radius); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.MENGER_SPONGE_WET); if (random.nextBoolean()) { - for (Direction dir : BlocksHelper.DIRECTIONS) { - BlockPos pos = blockPos.offset(dir); + for (Direction dir: BlocksHelper.DIRECTIONS) { + BlockPos pos = blockPos.relative(dir); if (REPLACE.apply(world.getBlockState(pos))) { BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.MENGER_SPONGE_WET); } } } } - + static { REPLACE = (state) -> { if (state.is(EndBlocks.END_LOTUS_STEM)) { diff --git a/src/main/java/ru/betterend/world/features/NBTStructureFeature.java b/src/main/java/ru/betterend/world/features/NBTStructureFeature.java index f3020bb6..65bb5d14 100644 --- a/src/main/java/ru/betterend/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/betterend/world/features/NBTStructureFeature.java @@ -3,25 +3,24 @@ package ru.betterend.world.features; import java.io.IOException; import java.io.InputStream; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtIo; -import net.minecraft.server.MinecraftServer; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.gen.surfacebuilder.SurfaceConfig; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -30,19 +29,19 @@ import ru.betterend.world.processors.DestructionStructureProcessor; public abstract class NBTStructureFeature extends DefaultFeature { protected static final DestructionStructureProcessor DESTRUCTION = new DestructionStructureProcessor(); - protected abstract Structure getStructure(WorldGenLevel world, BlockPos pos, Random random); + protected abstract StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random); protected abstract boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random); protected abstract Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random); - protected abstract BlockMirror getMirror(WorldGenLevel world, BlockPos pos, Random random); + protected abstract Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random); - protected abstract int getYOffset(Structure structure, WorldGenLevel world, BlockPos pos, Random random); + protected abstract int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random); protected abstract TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random); - protected abstract void addStructureData(StructurePlacementData data); + protected abstract void addStructureData(StructurePlaceSettings data); protected BlockPos getGround(WorldGenLevel world, BlockPos center) { Biome biome = world.getBiome(center); @@ -85,18 +84,18 @@ public abstract class NBTStructureFeature extends DefaultFeature { } int posY = center.getY() + 1; - Structure structure = getStructure(world, center, random); + StructureTemplate structure = getStructure(world, center, random); Rotation rotation = getRotation(world, center, random); - BlockMirror mirror = getMirror(world, center, random); - BlockPos offset = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN); - center = center.add(0, getYOffset(structure, world, center, random) + 0.5, 0); + Mirror mirror = getMirror(world, center, random); + BlockPos offset = StructureTemplate.transform(structure.getSize(), mirror, rotation, BlockPos.ZERO); + center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0); - BlockBox bounds = makeBox(center); - StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror) + BoundingBox bounds = makeBox(center); + StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror) .setBoundingBox(bounds); addStructureData(placementData); - center = center.add(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); - structure.place(world, center, placementData, random); + center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); + structure.placeInWorldChunk(world, center, placementData, random); TerrainMerge merge = getTerrainMerge(world, center, random); int x1 = center.getX(); @@ -125,24 +124,24 @@ public abstract class NBTStructureFeature extends DefaultFeature { mut.setZ(z); mut.setY(surfMax); BlockState state = world.getBlockState(mut); - if (!state.isIn(EndTags.GEN_TERRAIN) && state.isSideSolidFullSquare(world, mut, Direction.DOWN)) { + if (!state.is(EndTags.GEN_TERRAIN) && state.isFaceSturdy(world, mut, Direction.DOWN)) { for (int i = 0; i < 10; i++) { mut.setY(mut.getY() - 1); BlockState stateSt = world.getBlockState(mut); - if (!stateSt.isIn(EndTags.GEN_TERRAIN)) { + if (!stateSt.is(EndTags.GEN_TERRAIN)) { if (merge == TerrainMerge.SURFACE) { - SurfaceConfig config = world.getBiome(mut).getGenerationSettings() + SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings() .getSurfaceBuilderConfig(); - boolean isTop = mut.getY() == surfMax && state.getMaterial().blocksLight(); + boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking(); BlockState top = isTop ? config.getTopMaterial() : config.getUnderMaterial(); BlocksHelper.setWithoutUpdate(world, mut, top); } else { BlocksHelper.setWithoutUpdate(world, mut, state); } } else { - if (stateSt.isIn(EndTags.END_GROUND) && state.getMaterial().blocksLight()) { + if (stateSt.is(EndTags.END_GROUND) && state.getMaterial().isSolidBlocking()) { if (merge == TerrainMerge.SURFACE) { - SurfaceConfig config = world.getBiome(mut).getGenerationSettings() + SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings() .getSurfaceBuilderConfig(); BlocksHelper.setWithoutUpdate(world, mut, config.getUnderMaterial()); } else { @@ -162,15 +161,15 @@ public abstract class NBTStructureFeature extends DefaultFeature { return true; } - protected BlockBox makeBox(BlockPos pos) { + protected BoundingBox makeBox(BlockPos pos) { int sx = ((pos.getX() >> 4) << 4) - 16; int sz = ((pos.getZ() >> 4) << 4) - 16; int ex = sx + 47; int ez = sz + 47; - return BlockBox.create(sx, 0, sz, ex, 255, ez); + return BoundingBox.createProper(sx, 0, sz, ex, 255, ez); } - protected static Structure readStructure(ResourceLocation resource) { + protected static StructureTemplate readStructure(ResourceLocation resource) { String ns = resource.getNamespace(); String nm = resource.getPath(); @@ -185,11 +184,11 @@ public abstract class NBTStructureFeature extends DefaultFeature { return null; } - private static Structure readStructureFromStream(InputStream stream) throws IOException { + private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException { CompoundTag nbttagcompound = NbtIo.readCompressed(stream); - Structure template = new Structure(); - template.fromTag(nbttagcompound); + StructureTemplate template = new StructureTemplate(); + template.load(nbttagcompound); return template; } diff --git a/src/main/java/ru/betterend/world/features/NeonCactusFeature.java b/src/main/java/ru/betterend/world/features/NeonCactusFeature.java index 845e1008..9a018747 100644 --- a/src/main/java/ru/betterend/world/features/NeonCactusFeature.java +++ b/src/main/java/ru/betterend/world/features/NeonCactusFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.BlockProperties; @@ -31,15 +30,16 @@ public class NeonCactusFeature extends DefaultFeature { break; } int size = (h - i) >> 2; - BlocksHelper.setWithUpdate(world, mut, EndBlocks.NEON_CACTUS.defaultBlockState() - .with(BlockProperties.TRIPLE_SHAPE, getBySize(size)).with(Properties.FACING, Direction.UP)); + BlocksHelper.setWithUpdate(world, mut, + EndBlocks.NEON_CACTUS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, getBySize(size)) + .setValue(BlockStateProperties.FACING, Direction.UP)); if (i > 2 && i < (h - 1) && random.nextBoolean()) { int length = h - i - MHelper.randRange(1, 2, random); if (length > 0) { Direction dir2 = hor; hor = hor.getClockWise(); int bsize = i > ((h << 1) / 3) ? 0 : size > 1 ? 1 : size; - branch(world, mut.offset(dir2), dir2, random, length, bsize); + branch(world, mut.relative(dir2), dir2, random, length, bsize); } } mut.move(Direction.UP); @@ -56,8 +56,9 @@ public class NeonCactusFeature extends DefaultFeature { if (!world.getBlockState(mut).getMaterial().isReplaceable()) { return; } - BlocksHelper.setWithUpdate(world, mut, EndBlocks.NEON_CACTUS.defaultBlockState() - .with(BlockProperties.TRIPLE_SHAPE, getBySize(size)).with(Properties.FACING, dir)); + BlocksHelper.setWithUpdate(world, mut, + EndBlocks.NEON_CACTUS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, getBySize(size)) + .setValue(BlockStateProperties.FACING, dir)); if (i == rotIndex) { dir = Direction.UP; size--; @@ -65,7 +66,7 @@ public class NeonCactusFeature extends DefaultFeature { if (i > 1 && i < (length - 1) && random.nextBoolean()) { Direction dir2 = dir == Direction.UP ? hor : Direction.UP; hor = hor.getClockWise(); - branch(world, mut.offset(dir2), dir2, random, MHelper.randRange(length / 4, length / 2, random), + branch(world, mut.relative(dir2), dir2, random, MHelper.randRange(length / 4, length / 2, random), size > 0 ? size - 1 : size); } mut.move(dir); diff --git a/src/main/java/ru/betterend/world/features/ScatterFeature.java b/src/main/java/ru/betterend/world/features/ScatterFeature.java index ddd6b540..833985ef 100644 --- a/src/main/java/ru/betterend/world/features/ScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/ScatterFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; @@ -22,7 +21,7 @@ public abstract class ScatterFeature extends DefaultFeature { public abstract boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius); - public abstract void place(WorldGenLevel world, Random random, BlockPos blockPos); + public abstract void generate(WorldGenLevel world, Random random, BlockPos blockPos); protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) { return getPosOnSurfaceWG(world, pos); @@ -31,7 +30,7 @@ public abstract class ScatterFeature extends DefaultFeature { protected boolean canSpawn(WorldGenLevel world, BlockPos pos) { if (pos.getY() < 5) { return false; - } else if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + } else if (!world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { return false; } return true; diff --git a/src/main/java/ru/betterend/world/features/SilkMothNestFeature.java b/src/main/java/ru/betterend/world/features/SilkMothNestFeature.java index 20f00833..d8383f44 100644 --- a/src/main/java/ru/betterend/world/features/SilkMothNestFeature.java +++ b/src/main/java/ru/betterend/world/features/SilkMothNestFeature.java @@ -1,16 +1,15 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; -import net.minecraft.tags.BlockTags; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.Heightmap; +import net.minecraft.tags.BlockTags; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.BlockProperties; import ru.betterend.registry.EndBlocks; @@ -20,12 +19,12 @@ public class SilkMothNestFeature extends DefaultFeature { private static final MutableBlockPos POS = new MutableBlockPos(); private boolean canGenerate(WorldGenLevel world, BlockPos pos) { - BlockState state = world.getBlockState(pos.up()); - if (state.isIn(BlockTags.LEAVES) || state.isIn(BlockTags.LOGS)) { + BlockState state = world.getBlockState(pos.above()); + if (state.is(BlockTags.LEAVES) || state.is(BlockTags.LOGS)) { state = world.getBlockState(pos); - if ((state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) && world.isAir(pos.below())) { + if ((state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) && world.isEmptyBlock(pos.below())) { for (Direction dir : BlocksHelper.HORIZONTAL) { - if (world.getBlockState(pos.below().offset(dir)).getMaterial().blocksMovement()) { + if (world.getBlockState(pos.below().relative(dir)).getMaterial().blocksMotion()) { return false; } return true; @@ -38,7 +37,7 @@ public class SilkMothNestFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos center, NoneFeatureConfiguration featureConfig) { - int maxY = world.getTopY(Heightmap.Type.WORLD_SURFACE, center.getX(), center.getZ()); + int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ()); int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY); POS.set(center); for (int y = maxY; y > minY; y--) { @@ -46,10 +45,10 @@ public class SilkMothNestFeature extends DefaultFeature { if (canGenerate(world, POS)) { Direction dir = BlocksHelper.randomHorizontal(random); BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.SILK_MOTH_NEST.defaultBlockState() - .with(Properties.HORIZONTAL_FACING, dir).with(BlockProperties.ACTIVE, false)); + .setValue(BlockStateProperties.HORIZONTAL_FACING, dir).setValue(BlockProperties.ACTIVE, false)); POS.setY(y - 1); - BlocksHelper.setWithoutUpdate(world, POS, - EndBlocks.SILK_MOTH_NEST.defaultBlockState().with(Properties.HORIZONTAL_FACING, dir)); + BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.SILK_MOTH_NEST.defaultBlockState() + .setValue(BlockStateProperties.HORIZONTAL_FACING, dir)); return true; } } diff --git a/src/main/java/ru/betterend/world/features/SingleInvertedScatterFeature.java b/src/main/java/ru/betterend/world/features/SingleInvertedScatterFeature.java index 8923635a..20d87cec 100644 --- a/src/main/java/ru/betterend/world/features/SingleInvertedScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/SingleInvertedScatterFeature.java @@ -1,19 +1,18 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.util.BlocksHelper; public class SingleInvertedScatterFeature extends InvertedScatterFeature { private final Block block; - + public SingleInvertedScatterFeature(Block block, int radius) { super(radius); this.block = block; @@ -21,21 +20,21 @@ public class SingleInvertedScatterFeature extends InvertedScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - if (!world.isAir(blockPos)) { + if (!world.isEmptyBlock(blockPos)) { return false; } BlockState state = block.defaultBlockState(); if (block instanceof AttachedBlock) { - state = state.with(Properties.FACING, Direction.DOWN); + state = state.setValue(BlockStateProperties.FACING, Direction.DOWN); } - return state.canPlaceAt(world, blockPos); + return state.canSurvive(world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { BlockState state = block.defaultBlockState(); if (block instanceof AttachedBlock) { - state = state.with(Properties.FACING, Direction.DOWN); + state = state.setValue(BlockStateProperties.FACING, Direction.DOWN); } BlocksHelper.setWithoutUpdate(world, blockPos, state); } diff --git a/src/main/java/ru/betterend/world/features/SinglePlantFeature.java b/src/main/java/ru/betterend/world/features/SinglePlantFeature.java index ef8d6fa5..be176c6b 100644 --- a/src/main/java/ru/betterend/world/features/SinglePlantFeature.java +++ b/src/main/java/ru/betterend/world/features/SinglePlantFeature.java @@ -1,11 +1,10 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.blocks.basis.EndCropBlock; import ru.betterend.blocks.basis.EndPlantWithAgeBlock; @@ -15,55 +14,58 @@ public class SinglePlantFeature extends ScatterFeature { private final Block plant; private final boolean rawHeightmap; private final int chance; - + public SinglePlantFeature(Block plant, int radius) { this(plant, radius, true, 1); } - + public SinglePlantFeature(Block plant, int radius, int chance) { this(plant, radius, true, chance); } - + public SinglePlantFeature(Block plant, int radius, boolean rawHeightmap) { this(plant, radius, rawHeightmap, 1); } - + public SinglePlantFeature(Block plant, int radius, boolean rawHeightmap, int chance) { super(radius); this.plant = plant; this.rawHeightmap = rawHeightmap; this.chance = chance; } - + protected int getChance() { return chance; } - + @Override protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) { return rawHeightmap ? getPosOnSurfaceWG(world, pos) : getPosOnSurface(world, pos); } - + @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return plant.canPlaceAt(plant.defaultBlockState(), world, blockPos); + return plant.canSurvive(plant.defaultBlockState(), world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { if (plant instanceof DoublePlantBlock) { int rot = random.nextInt(4); - BlockState state = plant.defaultBlockState().with(DoublePlantBlock.ROTATION, rot); + BlockState state = plant.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot); BlocksHelper.setWithoutUpdate(world, blockPos, state); - BlocksHelper.setWithoutUpdate(world, blockPos.up(), state.with(DoublePlantBlock.TOP, true)); - } else if (plant instanceof EndCropBlock) { - BlockState state = plant.defaultBlockState().with(EndCropBlock.AGE, 3); + BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(DoublePlantBlock.TOP, true)); + } + else if (plant instanceof EndCropBlock) { + BlockState state = plant.defaultBlockState().setValue(EndCropBlock.AGE, 3); BlocksHelper.setWithoutUpdate(world, blockPos, state); - } else if (plant instanceof EndPlantWithAgeBlock) { + } + else if (plant instanceof EndPlantWithAgeBlock) { int age = random.nextInt(4); - BlockState state = plant.defaultBlockState().with(EndPlantWithAgeBlock.AGE, age); + BlockState state = plant.defaultBlockState().setValue(EndPlantWithAgeBlock.AGE, age); BlocksHelper.setWithoutUpdate(world, blockPos, state); - } else { + } + else { BlocksHelper.setWithoutUpdate(world, blockPos, plant); } } diff --git a/src/main/java/ru/betterend/world/features/SkyScatterFeature.java b/src/main/java/ru/betterend/world/features/SkyScatterFeature.java index 37160826..d2e1eaeb 100644 --- a/src/main/java/ru/betterend/world/features/SkyScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/SkyScatterFeature.java @@ -1,7 +1,6 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -13,7 +12,7 @@ public abstract class SkyScatterFeature extends ScatterFeature { public SkyScatterFeature(int radius) { super(radius); } - + @Override protected int getChance() { return 10; @@ -21,32 +20,32 @@ public abstract class SkyScatterFeature extends ScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - if (!world.isAir(blockPos)) { + if (!world.isEmptyBlock(blockPos)) { return false; } - - for (Direction dir : BlocksHelper.HORIZONTAL) { - if (!world.isAir(blockPos.offset(dir))) { + + for (Direction dir: BlocksHelper.HORIZONTAL) { + if (!world.isEmptyBlock(blockPos.relative(dir))) { return false; } } - + int maxD = getYOffset() + 2; int maxV = getYOffset() - 2; - + return BlocksHelper.upRay(world, blockPos, maxD) > maxV && BlocksHelper.downRay(world, blockPos, maxD) > maxV; } - + @Override protected boolean canSpawn(WorldGenLevel world, BlockPos pos) { return true; } - + @Override protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) { return new BlockPos(pos.getX(), MHelper.randRange(32, 192, world.getRandom()), pos.getZ()); } - + protected boolean getGroundPlant(WorldGenLevel world, MutableBlockPos pos) { pos.setY(pos.getY() + MHelper.randRange(-getYOffset(), getYOffset(), world.getRandom())); return true; diff --git a/src/main/java/ru/betterend/world/features/UnderwaterPlantFeature.java b/src/main/java/ru/betterend/world/features/UnderwaterPlantFeature.java index a2886e60..5b0ce2dc 100644 --- a/src/main/java/ru/betterend/world/features/UnderwaterPlantFeature.java +++ b/src/main/java/ru/betterend/world/features/UnderwaterPlantFeature.java @@ -1,35 +1,35 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.basis.DoublePlantBlock; import ru.betterend.util.BlocksHelper; public class UnderwaterPlantFeature extends UnderwaterPlantScatter { private final Block plant; - + public UnderwaterPlantFeature(Block plant, int radius) { super(radius); this.plant = plant; } - + @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { - return super.canSpawn(world, blockPos) && plant.canPlaceAt(plant.defaultBlockState(), world, blockPos); + return super.canSpawn(world, blockPos) && plant.canSurvive(plant.defaultBlockState(), world, blockPos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { if (plant instanceof DoublePlantBlock) { int rot = random.nextInt(4); - BlockState state = plant.defaultBlockState().with(DoublePlantBlock.ROTATION, rot); + BlockState state = plant.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot); BlocksHelper.setWithoutUpdate(world, blockPos, state); - BlocksHelper.setWithoutUpdate(world, blockPos.up(), state.with(DoublePlantBlock.TOP, true)); - } else { + BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(DoublePlantBlock.TOP, true)); + } + else { BlocksHelper.setWithoutUpdate(world, blockPos, plant); } } diff --git a/src/main/java/ru/betterend/world/features/UnderwaterPlantScatter.java b/src/main/java/ru/betterend/world/features/UnderwaterPlantScatter.java index 35bf1de9..3c40c55f 100644 --- a/src/main/java/ru/betterend/world/features/UnderwaterPlantScatter.java +++ b/src/main/java/ru/betterend/world/features/UnderwaterPlantScatter.java @@ -1,19 +1,18 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; public abstract class UnderwaterPlantScatter extends ScatterFeature { private static final MutableBlockPos POS = new MutableBlockPos(); - + public UnderwaterPlantScatter(int radius) { super(radius); } - + @Override protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) { POS.setX(pos.getX()); @@ -21,32 +20,32 @@ public abstract class UnderwaterPlantScatter extends ScatterFeature { POS.setY(0); return getGround(world, POS).immutable(); } - + @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) { return world.getBlockState(blockPos).is(Blocks.WATER); } - + @Override protected boolean canSpawn(WorldGenLevel world, BlockPos pos) { return world.getBlockState(pos).is(Blocks.WATER); } - + @Override protected boolean getGroundPlant(WorldGenLevel world, MutableBlockPos pos) { return getGround(world, pos).getY() < 128; } - + @Override protected int getYOffset() { return -5; } - + @Override protected int getChance() { return 5; } - + private BlockPos getGround(WorldGenLevel world, MutableBlockPos pos) { while (pos.getY() < 128 && world.getFluidState(pos).isEmpty()) { pos.setY(pos.getY() + 1); diff --git a/src/main/java/ru/betterend/world/features/VineFeature.java b/src/main/java/ru/betterend/world/features/VineFeature.java index 18c8e7c7..3cca3e78 100644 --- a/src/main/java/ru/betterend/world/features/VineFeature.java +++ b/src/main/java/ru/betterend/world/features/VineFeature.java @@ -1,11 +1,10 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.VineBlock; @@ -15,7 +14,7 @@ public class VineFeature extends InvertedScatterFeature { private final Block vineBlock; private final int maxLength; private final boolean vine; - + public VineFeature(Block vineBlock, int maxLength) { super(6); this.vineBlock = vineBlock; @@ -30,7 +29,7 @@ public class VineFeature extends InvertedScatterFeature { } @Override - public void place(WorldGenLevel world, Random random, BlockPos blockPos) { + public void generate(WorldGenLevel world, Random random, BlockPos blockPos) { int h = BlocksHelper.downRay(world, blockPos, random.nextInt(maxLength)) - 1; if (h > 2) { BlockState top = getTopState(); @@ -38,32 +37,33 @@ public class VineFeature extends InvertedScatterFeature { BlockState bottom = getBottomState(); BlocksHelper.setWithoutUpdate(world, blockPos, top); for (int i = 1; i < h; i++) { - BlocksHelper.setWithoutUpdate(world, blockPos.down(i), middle); + BlocksHelper.setWithoutUpdate(world, blockPos.below(i), middle); } - BlocksHelper.setWithoutUpdate(world, blockPos.down(h), bottom); + BlocksHelper.setWithoutUpdate(world, blockPos.below(h), bottom); } } - + private boolean canPlaceBlock(BlockState state, WorldGenLevel world, BlockPos blockPos) { if (vine) { return ((VineBlock) vineBlock).canGenerate(state, world, blockPos); - } else { - return vineBlock.canPlaceAt(state, world, blockPos); + } + else { + return vineBlock.canSurvive(state, world, blockPos); } } - + private BlockState getTopState() { BlockState state = vineBlock.defaultBlockState(); - return vine ? state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP) : state; + return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP) : state; } - + private BlockState getMiggleState() { BlockState state = vineBlock.defaultBlockState(); - return vine ? state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE) : state; + return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE) : state; } - + private BlockState getBottomState() { BlockState state = vineBlock.defaultBlockState(); - return vine ? state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM) : state; + return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM) : state; } } diff --git a/src/main/java/ru/betterend/world/features/WallPlantFeature.java b/src/main/java/ru/betterend/world/features/WallPlantFeature.java index 0f34f39f..54e61ee0 100644 --- a/src/main/java/ru/betterend/world/features/WallPlantFeature.java +++ b/src/main/java/ru/betterend/world/features/WallPlantFeature.java @@ -1,20 +1,19 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.blocks.basis.EndWallPlantBlock; import ru.betterend.util.BlocksHelper; public class WallPlantFeature extends WallScatterFeature { private final Block block; - + public WallPlantFeature(Block block, int radius) { super(radius); this.block = block; @@ -23,22 +22,24 @@ public class WallPlantFeature extends WallScatterFeature { @Override public boolean canGenerate(WorldGenLevel world, Random random, BlockPos pos, Direction dir) { if (block instanceof EndWallPlantBlock) { - BlockState state = block.defaultBlockState().with(EndWallPlantBlock.FACING, dir); - return block.canPlaceAt(state, world, pos); - } else if (block instanceof AttachedBlock) { - BlockState state = block.defaultBlockState().with(Properties.FACING, dir); - return block.canPlaceAt(state, world, pos); + BlockState state = block.defaultBlockState().setValue(EndWallPlantBlock.FACING, dir); + return block.canSurvive(state, world, pos); } - return block.canPlaceAt(block.defaultBlockState(), world, pos); + else if (block instanceof AttachedBlock) { + BlockState state = block.defaultBlockState().setValue(BlockStateProperties.FACING, dir); + return block.canSurvive(state, world, pos); + } + return block.canSurvive(block.defaultBlockState(), world, pos); } @Override - public void place(WorldGenLevel world, Random random, BlockPos pos, Direction dir) { + public void generate(WorldGenLevel world, Random random, BlockPos pos, Direction dir) { BlockState state = block.defaultBlockState(); if (block instanceof EndWallPlantBlock) { - state = state.with(EndWallPlantBlock.FACING, dir); - } else if (block instanceof AttachedBlock) { - state = state.with(Properties.FACING, dir); + state = state.setValue(EndWallPlantBlock.FACING, dir); + } + else if (block instanceof AttachedBlock) { + state = state.setValue(BlockStateProperties.FACING, dir); } BlocksHelper.setWithoutUpdate(world, pos, state); } diff --git a/src/main/java/ru/betterend/world/features/WallPlantOnLogFeature.java b/src/main/java/ru/betterend/world/features/WallPlantOnLogFeature.java index 72855bab..7a4b2681 100644 --- a/src/main/java/ru/betterend/world/features/WallPlantOnLogFeature.java +++ b/src/main/java/ru/betterend/world/features/WallPlantOnLogFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.tags.BlockTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.tags.BlockTags; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; public class WallPlantOnLogFeature extends WallPlantFeature { public WallPlantOnLogFeature(Block block, int radius) { @@ -18,6 +17,6 @@ public class WallPlantOnLogFeature extends WallPlantFeature { public boolean canGenerate(WorldGenLevel world, Random random, BlockPos pos, Direction dir) { BlockPos blockPos = pos.relative(dir.getOpposite()); BlockState blockState = world.getBlockState(blockPos); - return blockState.isIn(BlockTags.LOGS); + return blockState.is(BlockTags.LOGS); } } diff --git a/src/main/java/ru/betterend/world/features/WallScatterFeature.java b/src/main/java/ru/betterend/world/features/WallScatterFeature.java index 7528bf86..052e9dd5 100644 --- a/src/main/java/ru/betterend/world/features/WallScatterFeature.java +++ b/src/main/java/ru/betterend/world/features/WallScatterFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features; import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.Heightmap; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.util.BlocksHelper; import ru.betterend.util.MHelper; @@ -22,12 +21,12 @@ public abstract class WallScatterFeature extends DefaultFeature { public abstract boolean canGenerate(WorldGenLevel world, Random random, BlockPos pos, Direction dir); - public abstract void place(WorldGenLevel world, Random random, BlockPos pos, Direction dir); + public abstract void generate(WorldGenLevel world, Random random, BlockPos pos, Direction dir); @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos center, NoneFeatureConfiguration featureConfig) { - int maxY = world.getTopY(Heightmap.Type.WORLD_SURFACE, center.getX(), center.getZ()); + int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ()); int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY); if (maxY < 10 || maxY < minY) { return false; @@ -41,7 +40,7 @@ public abstract class WallScatterFeature extends DefaultFeature { mut.setY(py + y); for (int z = -radius; z <= radius; z++) { mut.setZ(center.getZ() + z); - if (random.nextInt(4) == 0 && world.isAir(mut)) { + if (random.nextInt(4) == 0 && world.isEmptyBlock(mut)) { shuffle(random); for (Direction dir : DIR) { if (canGenerate(world, random, mut, dir)) { diff --git a/src/main/java/ru/betterend/world/features/bushes/BushFeature.java b/src/main/java/ru/betterend/world/features/bushes/BushFeature.java index dbd7c83c..e557592e 100644 --- a/src/main/java/ru/betterend/world/features/bushes/BushFeature.java +++ b/src/main/java/ru/betterend/world/features/bushes/BushFeature.java @@ -2,16 +2,15 @@ package ru.betterend.world.features.bushes; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -37,8 +36,8 @@ public class BushFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND) - && !world.getBlockState(pos.up()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND) + && !world.getBlockState(pos.above()).getBlock().is(EndTags.END_GROUND)) return false; float radius = MHelper.randRange(1.8F, 3.5F, random); @@ -56,9 +55,9 @@ public class BushFeature extends DefaultFeature { sphere.setReplaceFunction(REPLACE); sphere.addPostProcess((info) -> { if (info.getState().getBlock() instanceof LeavesBlock) { - int distance = info.getPos().getManhattanDistance(pos); + int distance = info.getPos().distManhattan(pos); if (distance < 7) { - return info.getState().with(LeavesBlock.DISTANCE, distance); + return info.getState().setValue(LeavesBlock.DISTANCE, distance); } else { return AIR; } @@ -69,9 +68,10 @@ public class BushFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, pos, stem); for (Direction d : Direction.values()) { BlockPos p = pos.relative(d); - if (world.isAir(p)) { + if (world.isEmptyBlock(p)) { if (leaves instanceof LeavesBlock) { - BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState().with(LeavesBlock.DISTANCE, 1)); + BlocksHelper.setWithoutUpdate(world, p, + leaves.defaultBlockState().setValue(LeavesBlock.DISTANCE, 1)); } else { BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState()); } diff --git a/src/main/java/ru/betterend/world/features/bushes/BushWithOuterFeature.java b/src/main/java/ru/betterend/world/features/bushes/BushWithOuterFeature.java index 9f088dba..4de7f7ec 100644 --- a/src/main/java/ru/betterend/world/features/bushes/BushWithOuterFeature.java +++ b/src/main/java/ru/betterend/world/features/bushes/BushWithOuterFeature.java @@ -2,17 +2,16 @@ package ru.betterend.world.features.bushes; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -41,8 +40,8 @@ public class BushWithOuterFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND) - && !world.getBlockState(pos.up()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND) + && !world.getBlockState(pos.above()).getBlock().is(EndTags.END_GROUND)) return false; float radius = MHelper.randRange(1.8F, 3.5F, random); @@ -60,9 +59,9 @@ public class BushWithOuterFeature extends DefaultFeature { sphere.setReplaceFunction(REPLACE); sphere.addPostProcess((info) -> { if (info.getState().getBlock() instanceof LeavesBlock) { - int distance = info.getPos().getManhattanDistance(pos); + int distance = info.getPos().distManhattan(pos); if (distance < 7) { - return info.getState().with(LeavesBlock.DISTANCE, distance); + return info.getState().setValue(LeavesBlock.DISTANCE, distance); } else { return AIR; } @@ -73,8 +72,8 @@ public class BushWithOuterFeature extends DefaultFeature { MHelper.shuffle(DIRECTIONS, random); for (Direction dir : DIRECTIONS) { if (info.getState(dir).isAir()) { - info.setBlockPos(info.getPos().offset(dir), - outer_leaves.defaultBlockState().with(Properties.FACING, dir)); + info.setBlockPos(info.getPos().relative(dir), + outer_leaves.defaultBlockState().setValue(BlockStateProperties.FACING, dir)); } } } @@ -84,9 +83,10 @@ public class BushWithOuterFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, pos, stem); for (Direction d : Direction.values()) { BlockPos p = pos.relative(d); - if (world.isAir(p)) { + if (world.isEmptyBlock(p)) { if (leaves instanceof LeavesBlock) { - BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState().with(LeavesBlock.DISTANCE, 1)); + BlocksHelper.setWithoutUpdate(world, p, + leaves.defaultBlockState().setValue(LeavesBlock.DISTANCE, 1)); } else { BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState()); } diff --git a/src/main/java/ru/betterend/world/features/bushes/LargeAmaranitaFeature.java b/src/main/java/ru/betterend/world/features/bushes/LargeAmaranitaFeature.java index b4794ae8..45d6f250 100644 --- a/src/main/java/ru/betterend/world/features/bushes/LargeAmaranitaFeature.java +++ b/src/main/java/ru/betterend/world/features/bushes/LargeAmaranitaFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features.bushes; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.BlockProperties; @@ -21,27 +20,27 @@ public class LargeAmaranitaFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; MutableBlockPos mut = new MutableBlockPos().set(pos); int height = MHelper.randRange(2, 3, random); for (int i = 1; i < height; i++) { mut.setY(mut.getY() + 1); - if (!world.isAir(mut)) { + if (!world.isEmptyBlock(mut)) { return false; } } mut.set(pos); BlockState state = EndBlocks.LARGE_AMARANITA_MUSHROOM.defaultBlockState(); - BlocksHelper.setWithUpdate(world, mut, state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); + BlocksHelper.setWithUpdate(world, mut, state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM)); if (height > 2) { BlocksHelper.setWithUpdate(world, mut.move(Direction.UP), - state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); + state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); } BlocksHelper.setWithUpdate(world, mut.move(Direction.UP), - state.with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); + state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); return true; } diff --git a/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java b/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java index 5d323765..0b1cfa55 100644 --- a/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java +++ b/src/main/java/ru/betterend/world/features/bushes/Lumecorn.java @@ -1,12 +1,11 @@ package ru.betterend.world.features.bushes; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.BlockProperties.LumecornShape; @@ -21,28 +20,28 @@ public class Lumecorn extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; int height = MHelper.randRange(4, 7, random); MutableBlockPos mut = new MutableBlockPos().set(pos); for (int i = 1; i < height; i++) { mut.move(Direction.UP); - if (!world.isAir(mut)) { + if (!world.isEmptyBlock(mut)) { return false; } } mut.set(pos); - BlockState topMiddle = EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, + BlockState topMiddle = EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_TOP_MIDDLE); - BlockState middle = EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, + BlockState middle = EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_MIDDLE); - BlockState bottom = EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, + BlockState bottom = EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_BOTTOM); - BlockState top = EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, LumecornShape.LIGHT_TOP); + BlockState top = EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_TOP); if (height == 4) { BlocksHelper.setWithoutUpdate(world, mut, - EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)); + EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)); BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), bottom); BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), topMiddle); BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), top); @@ -50,12 +49,12 @@ public class Lumecorn extends DefaultFeature { } if (random.nextBoolean()) { BlocksHelper.setWithoutUpdate(world, mut, - EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)); + EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)); } else { BlocksHelper.setWithoutUpdate(world, mut, - EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, LumecornShape.BOTTOM_BIG)); + EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_BIG)); BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), - EndBlocks.LUMECORN.defaultBlockState().with(LumecornBlock.SHAPE, LumecornShape.MIDDLE)); + EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.MIDDLE)); height--; } BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), bottom); diff --git a/src/main/java/ru/betterend/world/features/bushes/TenaneaBushFeature.java b/src/main/java/ru/betterend/world/features/bushes/TenaneaBushFeature.java index 3e6edc03..3e0901d2 100644 --- a/src/main/java/ru/betterend/world/features/bushes/TenaneaBushFeature.java +++ b/src/main/java/ru/betterend/world/features/bushes/TenaneaBushFeature.java @@ -3,18 +3,16 @@ package ru.betterend.world.features.bushes; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.FurBlock; @@ -41,7 +39,7 @@ public class TenaneaBushFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; float radius = MHelper.randRange(1.8F, 3.5F, random); @@ -61,7 +59,7 @@ public class TenaneaBushFeature extends DefaultFeature { List support = Lists.newArrayList(); sphere.addPostProcess((info) -> { if (info.getState().getBlock() instanceof LeavesBlock) { - int distance = info.getPos().getManhattanDistance(pos); + int distance = info.getPos().distManhattan(pos); if (distance < 7) { if (random.nextInt(4) == 0 && info.getStateDown().isAir()) { BlockPos d = info.getPos().below(); @@ -71,12 +69,12 @@ public class TenaneaBushFeature extends DefaultFeature { MHelper.shuffle(DIRECTIONS, random); for (Direction d : DIRECTIONS) { if (info.getState(d).isAir()) { - info.setBlockPos(info.getPos().offset(d), - EndBlocks.TENANEA_OUTER_LEAVES.defaultBlockState().with(FurBlock.FACING, d)); + info.setBlockPos(info.getPos().relative(d), + EndBlocks.TENANEA_OUTER_LEAVES.defaultBlockState().setValue(FurBlock.FACING, d)); } } - return info.getState().with(LeavesBlock.DISTANCE, distance); + return info.getState().setValue(LeavesBlock.DISTANCE, distance); } else { return AIR; } @@ -88,28 +86,28 @@ public class TenaneaBushFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, pos, stem); for (Direction d : Direction.values()) { BlockPos p = pos.relative(d); - if (world.isAir(p)) { - BlocksHelper.setWithoutUpdate(world, p, leaves.with(LeavesBlock.DISTANCE, 1)); + if (world.isEmptyBlock(p)) { + BlocksHelper.setWithoutUpdate(world, p, leaves.setValue(LeavesBlock.DISTANCE, 1)); } } MutableBlockPos mut = new MutableBlockPos(); - BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); - BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE); - BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM); support.forEach((bpos) -> { BlockState state = world.getBlockState(bpos); if (state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) { int count = MHelper.randRange(3, 8, random); mut.set(bpos); - if (world.getBlockState(mut.up()).is(EndBlocks.TENANEA_LEAVES)) { + if (world.getBlockState(mut.above()).is(EndBlocks.TENANEA_LEAVES)) { BlocksHelper.setWithoutUpdate(world, mut, top); for (int i = 1; i < count; i++) { mut.setY(mut.getY() - 1); - if (world.isAir(mut.below())) { + if (world.isEmptyBlock(mut.below())) { BlocksHelper.setWithoutUpdate(world, mut, middle); } else { break; diff --git a/src/main/java/ru/betterend/world/features/terrain/BigAuroraCrystalFeature.java b/src/main/java/ru/betterend/world/features/terrain/BigAuroraCrystalFeature.java index ec22a61f..c471ab5f 100644 --- a/src/main/java/ru/betterend/world/features/terrain/BigAuroraCrystalFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/BigAuroraCrystalFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features.terrain; -import java.util.Random; - -import net.minecraft.world.level.material.Material; import com.mojang.math.Vector3f; +import java.util.Random; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -37,7 +36,7 @@ public class BigAuroraCrystalFeature extends DefaultFeature { Vector3f vec = MHelper.randomHorizontal(random); prism = new SDFRotation().setRotation(vec, random.nextFloat()).setSource(prism); prism.setReplaceFunction((bState) -> { - return bState.getMaterial().isReplaceable() || bState.isIn(EndTags.GEN_TERRAIN) + return bState.getMaterial().isReplaceable() || bState.is(EndTags.GEN_TERRAIN) || bState.getMaterial().equals(Material.PLANT) || bState.getMaterial().equals(Material.LEAVES); }); prism.fillRecursive(world, pos); diff --git a/src/main/java/ru/betterend/world/features/terrain/EndLakeFeature.java b/src/main/java/ru/betterend/world/features/terrain/EndLakeFeature.java index 3231fbb6..788dd936 100644 --- a/src/main/java/ru/betterend/world/features/terrain/EndLakeFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/EndLakeFeature.java @@ -1,16 +1,15 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import net.minecraft.fluid.FluidState; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -37,22 +36,22 @@ public class EndLakeFeature extends DefaultFeature { int waterLevel = blockPos.getY(); - BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).up(10), 20); + BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).above(10), 20); if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false; waterLevel = MHelper.min(pos.getY(), waterLevel); - pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).up(10), 20); + pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).above(10), 20); if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false; waterLevel = MHelper.min(pos.getY(), waterLevel); - pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).up(10), 20); + pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).above(10), 20); if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false; waterLevel = MHelper.min(pos.getY(), waterLevel); - pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).up(10), 20); + pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).above(10), 20); if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false; waterLevel = MHelper.min(pos.getY(), waterLevel); @@ -116,11 +115,11 @@ public class EndLakeFeature extends DefaultFeature { r *= r; if (x2 + z2 <= r) { state = world.getBlockState(POS); - if (state.isIn(EndTags.GEN_TERRAIN)) { + if (state.is(EndTags.GEN_TERRAIN)) { BlocksHelper.setWithoutUpdate(world, POS, AIR); } pos = POS.below(); - if (world.getBlockState(pos).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos).is(EndTags.GEN_TERRAIN)) { state = world.getBiome(pos).getGenerationSettings().getSurfaceBuilderConfig() .getTopMaterial(); if (y > waterLevel + 1) @@ -165,24 +164,24 @@ public class EndLakeFeature extends DefaultFeature { if (y2 + x2 + z2 <= r) { state = world.getBlockState(POS); if (canReplace(state)) { - state = world.getBlockState(POS.up()); + state = world.getBlockState(POS.above()); state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state; BlocksHelper.setWithoutUpdate(world, POS, state); } pos = POS.below(); - if (world.getBlockState(pos).getBlock().isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos).getBlock().is(EndTags.GEN_TERRAIN)) { BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.defaultBlockState()); } - pos = POS.up(); + pos = POS.above(); while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState().isEmpty()) { BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR); - pos = pos.up(); + pos = pos.above(); } } // Make border else if (y < waterLevel && y2 + x2 + z2 <= rb) { - if (world.isAir(POS.up())) { + if (world.isEmptyBlock(POS.above())) { state = world.getBiome(POS).getGenerationSettings().getSurfaceBuilderConfig() .getTopMaterial(); BlocksHelper.setWithoutUpdate(world, POS, @@ -206,9 +205,8 @@ public class EndLakeFeature extends DefaultFeature { } private boolean canReplace(BlockState state) { - return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) - || state.is(EndBlocks.ENDSTONE_DUST) || state.getMaterial().equals(Material.PLANT) - || state.getMaterial().equals(Material.UNDERWATER_PLANT) - || state.getMaterial().equals(Material.UNUSED_PLANT); + return state.getMaterial().isReplaceable() || state.is(EndTags.GEN_TERRAIN) || state.is(EndBlocks.ENDSTONE_DUST) + || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.WATER_PLANT) + || state.getMaterial().equals(Material.CORAL); } } diff --git a/src/main/java/ru/betterend/world/features/terrain/FallenPillarFeature.java b/src/main/java/ru/betterend/world/features/terrain/FallenPillarFeature.java index 53f60237..0cd32d05 100644 --- a/src/main/java/ru/betterend/world/features/terrain/FallenPillarFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/FallenPillarFeature.java @@ -1,15 +1,14 @@ package ru.betterend.world.features.terrain; -import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; import com.mojang.math.Vector3f; +import java.util.Random; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -27,7 +26,7 @@ public class FallenPillarFeature extends DefaultFeature { NoneFeatureConfiguration config) { pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))); - if (!world.getBlockState(pos.down(5)).isIn(EndTags.GEN_TERRAIN)) { + if (!world.getBlockState(pos.below(5)).is(EndTags.GEN_TERRAIN)) { return false; } @@ -51,7 +50,7 @@ public class FallenPillarFeature extends DefaultFeature { } return info.getState(); }).setReplaceFunction((state) -> { - return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) + return state.getMaterial().isReplaceable() || state.is(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT); }).fillRecursive(world, pos); diff --git a/src/main/java/ru/betterend/world/features/terrain/FloatingSpireFeature.java b/src/main/java/ru/betterend/world/features/terrain/FloatingSpireFeature.java index 108edf17..3eefb3d6 100644 --- a/src/main/java/ru/betterend/world/features/terrain/FloatingSpireFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/FloatingSpireFeature.java @@ -2,15 +2,13 @@ package ru.betterend.world.features.terrain; import java.util.List; import java.util.Random; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import com.google.common.collect.Lists; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndFeatures; @@ -50,7 +48,7 @@ public class FloatingSpireFeature extends SpireFeature { sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> { if (info.getStateUp().isAir()) { if (random.nextInt(16) == 0) { - support.add(info.getPos().up()); + support.add(info.getPos().above()); } return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); } else if (info.getState(Direction.UP, 3).isAir()) { diff --git a/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java b/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java index 4ee5f97f..d565d233 100644 --- a/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/GeyserFeature.java @@ -1,20 +1,19 @@ package ru.betterend.world.features.terrain; +import com.mojang.math.Vector3f; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.HorizontalFacingBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.HydrothermalVentBlock; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; @@ -56,7 +55,7 @@ public class GeyserFeature extends DefaultFeature { MutableBlockPos bpos = new MutableBlockPos().set(pos); bpos.setY(bpos.getY() - 1); BlockState state = world.getBlockState(bpos); - while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { + while (state.is(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { bpos.setY(bpos.getY() - 1); state = world.getBlockState(bpos); } @@ -107,7 +106,7 @@ public class GeyserFeature extends DefaultFeature { bowl = new SDFSubtraction().setSourceA(bowl).setSourceB(cut); bowl = new SDFTranslate().setTranslate(radius, py - radius, 0).setSource(bowl); - bowl = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, i * 4F).setSource(bowl); + bowl = new SDFRotation().setRotation(Vector3f.YP, i * 4F).setSource(bowl); sdf = new SDFUnion().setSourceA(sdf).setSourceB(bowl); } sdf.setReplaceFunction(REPLACE2).fillRecursive(world, pos); @@ -165,7 +164,7 @@ public class GeyserFeature extends DefaultFeature { for (int i = 0; i < count; i++) { BlocksHelper.setWithoutUpdate(world, mut, WATER); for (Direction dir : BlocksHelper.HORIZONTAL) { - BlocksHelper.setWithoutUpdate(world, mut.offset(dir), WATER); + BlocksHelper.setWithoutUpdate(world, mut.relative(dir), WATER); } mut.setY(mut.getY() + 1); } @@ -177,24 +176,25 @@ public class GeyserFeature extends DefaultFeature { int dist = MHelper.floor(6 - distRaw) + random.nextInt(2); if (dist >= 0) { state = world.getBlockState(mut); - while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.UNDERWATER_PLANT)) { + while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.WATER_PLANT)) { mut.setY(mut.getY() - 1); state = world.getBlockState(mut); } - if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) { + if (state.is(EndTags.GEN_TERRAIN) + && !world.getBlockState(mut.above()).is(EndBlocks.HYDROTHERMAL_VENT)) { for (int j = 0; j <= dist; j++) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone); MHelper.shuffle(HORIZONTAL, random); for (Direction dir : HORIZONTAL) { - BlockPos p = mut.offset(dir); + BlockPos p = mut.relative(dir); if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.defaultBlockState() - .with(HorizontalFacingBlock.FACING, dir)); + .setValue(HorizontalDirectionalBlock.FACING, dir)); } } mut.setY(mut.getY() + 1); } - state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.ACTIVATED, + state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().setValue(HydrothermalVentBlock.ACTIVATED, distRaw < 2); BlocksHelper.setWithoutUpdate(world, mut, state); mut.setY(mut.getY() + 1); @@ -219,12 +219,12 @@ public class GeyserFeature extends DefaultFeature { mut.setY(mut.getY() - 1); state = world.getBlockState(mut); } - if (state.isIn(EndTags.GEN_TERRAIN)) { + if (state.is(EndTags.GEN_TERRAIN)) { for (int j = 0; j <= dist; j++) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone); mut.setY(mut.getY() + 1); } - state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.ACTIVATED, + state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().setValue(HydrothermalVentBlock.ACTIVATED, distRaw < 2); BlocksHelper.setWithoutUpdate(world, mut, state); mut.setY(mut.getY() + 1); @@ -250,11 +250,11 @@ public class GeyserFeature extends DefaultFeature { static { REPLACE1 = (state) -> { - return state.isAir() || (state.isIn(EndTags.GEN_TERRAIN)); + return state.isAir() || (state.is(EndTags.GEN_TERRAIN)); }; REPLACE2 = (state) -> { - if (state.isIn(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT) + if (state.is(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT) || state.is(EndBlocks.SULPHUR_CRYSTAL)) { return true; } diff --git a/src/main/java/ru/betterend/world/features/terrain/IceStarFeature.java b/src/main/java/ru/betterend/world/features/terrain/IceStarFeature.java index a1db3934..d106c5c9 100644 --- a/src/main/java/ru/betterend/world/features/terrain/IceStarFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/IceStarFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features.terrain; +import com.mojang.math.Vector3f; import java.util.ArrayList; import java.util.List; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.registry.EndBlocks; @@ -45,12 +44,12 @@ public class IceStarFeature extends DefaultFeature { for (Vector3f point : points) { SDF rotated = spike; point = MHelper.normalize(point); - float angle = MHelper.angle(Vector3f.POSITIVE_Y, point); + float angle = MHelper.angle(Vector3f.YP, point); if (angle > 0.01F && angle < 3.14F) { - Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.POSITIVE_Y, point)); + Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.YP, point)); rotated = new SDFRotation().setRotation(axis, angle).setSource(spike); } else if (angle > 1) { - rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(spike); + rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(spike); } sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated); } diff --git a/src/main/java/ru/betterend/world/features/terrain/ObsidianBoulderFeature.java b/src/main/java/ru/betterend/world/features/terrain/ObsidianBoulderFeature.java index 815e810c..a47a0eb5 100644 --- a/src/main/java/ru/betterend/world/features/terrain/ObsidianBoulderFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/ObsidianBoulderFeature.java @@ -1,14 +1,13 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -25,7 +24,7 @@ public class ObsidianBoulderFeature extends DefaultFeature { NoneFeatureConfiguration config) { pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))); - if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + if (!world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { return false; } @@ -40,7 +39,7 @@ public class ObsidianBoulderFeature extends DefaultFeature { } private void makeBoulder(WorldGenLevel world, BlockPos pos, Random random) { - if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) { + if (!world.getBlockState(pos.below()).is(EndTags.END_GROUND)) { return; } @@ -62,7 +61,7 @@ public class ObsidianBoulderFeature extends DefaultFeature { } return info.getState(); }).setReplaceFunction((state) -> { - return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) + return state.getMaterial().isReplaceable() || state.is(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT); }).fillRecursive(world, pos); } diff --git a/src/main/java/ru/betterend/world/features/terrain/ObsidianPillarBasementFeature.java b/src/main/java/ru/betterend/world/features/terrain/ObsidianPillarBasementFeature.java index 08067b32..923b39e6 100644 --- a/src/main/java/ru/betterend/world/features/terrain/ObsidianPillarBasementFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/ObsidianPillarBasementFeature.java @@ -1,15 +1,14 @@ package ru.betterend.world.features.terrain; -import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; import com.mojang.math.Vector3f; +import java.util.Random; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -29,7 +28,7 @@ public class ObsidianPillarBasementFeature extends DefaultFeature { NoneFeatureConfiguration config) { pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))); - if (!world.getBlockState(pos.down(5)).isIn(EndTags.GEN_TERRAIN)) { + if (!world.getBlockState(pos.below(5)).is(EndTags.GEN_TERRAIN)) { return false; } @@ -59,7 +58,7 @@ public class ObsidianPillarBasementFeature extends DefaultFeature { } return info.getState(); }).setReplaceFunction((state) -> { - return state.getMaterial().isReplaceable() || state.isIn(EndTags.GEN_TERRAIN) + return state.getMaterial().isReplaceable() || state.is(EndTags.GEN_TERRAIN) || state.getMaterial().equals(Material.PLANT); }).fillRecursive(world, pos); diff --git a/src/main/java/ru/betterend/world/features/terrain/OreLayerFeature.java b/src/main/java/ru/betterend/world/features/terrain/OreLayerFeature.java index cd73b096..2e8624b3 100644 --- a/src/main/java/ru/betterend/world/features/terrain/OreLayerFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/OreLayerFeature.java @@ -1,11 +1,10 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.noise.OpenSimplexNoise; diff --git a/src/main/java/ru/betterend/world/features/terrain/SingleBlockFeature.java b/src/main/java/ru/betterend/world/features/terrain/SingleBlockFeature.java index 08f7c648..a1f1aca3 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SingleBlockFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SingleBlockFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.registry.EndTags; @@ -23,14 +22,14 @@ public class SingleBlockFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN)) { + if (!world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN)) { return false; } BlockState state = block.defaultBlockState(); - if (block.getStateManager().getProperty("waterlogged") != null) { + if (block.getStateDefinition().getProperty("waterlogged") != null) { boolean waterlogged = !world.getFluidState(pos).isEmpty(); - state = state.with(Properties.WATERLOGGED, waterlogged); + state = state.setValue(BlockStateProperties.WATERLOGGED, waterlogged); } BlocksHelper.setWithoutUpdate(world, pos, state); diff --git a/src/main/java/ru/betterend/world/features/terrain/SmaragdantCrystalFeature.java b/src/main/java/ru/betterend/world/features/terrain/SmaragdantCrystalFeature.java index 6397ca07..66aac613 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SmaragdantCrystalFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SmaragdantCrystalFeature.java @@ -1,12 +1,11 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.registry.EndBlocks; @@ -19,7 +18,7 @@ public class SmaragdantCrystalFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).isIn(EndTags.GEN_TERRAIN)) { + if (!world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN)) { return false; } @@ -38,13 +37,14 @@ public class SmaragdantCrystalFeature extends DefaultFeature { mut.setY(mut.getY() - 1); state = world.getBlockState(mut); } - if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(crystal.getBlock())) { + if (state.is(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.above()).is(crystal.getBlock())) { for (int j = 0; j <= dist; j++) { BlocksHelper.setWithoutUpdate(world, mut, crystal); mut.setY(mut.getY() + 1); } boolean waterlogged = !world.getFluidState(mut).isEmpty(); - BlocksHelper.setWithoutUpdate(world, mut, shard.with(Properties.WATERLOGGED, waterlogged)); + BlocksHelper.setWithoutUpdate(world, mut, + shard.setValue(BlockStateProperties.WATERLOGGED, waterlogged)); } } } diff --git a/src/main/java/ru/betterend/world/features/terrain/SpireFeature.java b/src/main/java/ru/betterend/world/features/terrain/SpireFeature.java index 30617675..980d436d 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SpireFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SpireFeature.java @@ -3,18 +3,16 @@ package ru.betterend.world.features.terrain; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndFeatures; @@ -46,7 +44,7 @@ public class SpireFeature extends DefaultFeature { sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random); } OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong()); - sdf = new SDFDisplacement().setFunction(vec -> { + sdf = new SDFDisplacement().setFunction((vec) -> { return (float) (Math.abs(noise.eval(vec.x() * 0.1, vec.y() * 0.1, vec.z() * 0.1)) * 3F + Math.abs(noise.eval(vec.x() * 0.3, vec.y() * 0.3 + 100, vec.z() * 0.3)) * 1.3F); }).setSource(sdf); diff --git a/src/main/java/ru/betterend/world/features/terrain/StalactiteFeature.java b/src/main/java/ru/betterend/world/features/terrain/StalactiteFeature.java index 3a336a23..bfc53e91 100644 --- a/src/main/java/ru/betterend/world/features/terrain/StalactiteFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/StalactiteFeature.java @@ -1,14 +1,13 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.state.property.Properties; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.basis.StalactiteBlock; @@ -30,7 +29,7 @@ public class StalactiteFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!isGround(world.getBlockState(ceiling ? pos.up() : pos.below()).getBlock())) { + if (!isGround(world.getBlockState(ceiling ? pos.above() : pos.below()).getBlock())) { return false; } @@ -43,7 +42,7 @@ public class StalactiteFeature extends DefaultFeature { mut.setY(pos.getY() + i * dir); BlockState state = world.getBlockState(mut); if (!state.getMaterial().isReplaceable()) { - stalagnate = state.isIn(EndTags.GEN_TERRAIN); + stalagnate = state.is(EndTags.GEN_TERRAIN); height = i; break; } @@ -58,10 +57,10 @@ public class StalactiteFeature extends DefaultFeature { mut.setY(pos.getY() + i * dir); int size = stalagnate ? Mth.clamp((int) (Mth.abs(i - center) + 1), 1, 7) : height - i - 1; boolean waterlogged = !world.getFluidState(mut).isEmpty(); - BlockState base = block.defaultBlockState().with(StalactiteBlock.SIZE, size).with(Properties.WATERLOGGED, - waterlogged); - BlockState state = stalagnate ? base.with(StalactiteBlock.IS_FLOOR, dir > 0 ? i < center : i > center) - : base.with(StalactiteBlock.IS_FLOOR, dir > 0); + BlockState base = block.defaultBlockState().setValue(StalactiteBlock.SIZE, size) + .setValue(BlockStateProperties.WATERLOGGED, waterlogged); + BlockState state = stalagnate ? base.setValue(StalactiteBlock.IS_FLOOR, dir > 0 ? i < center : i > center) + : base.setValue(StalactiteBlock.IS_FLOOR, dir > 0); BlocksHelper.setWithoutUpdate(world, mut, state); } diff --git a/src/main/java/ru/betterend/world/features/terrain/SulphurHillFeature.java b/src/main/java/ru/betterend/world/features/terrain/SulphurHillFeature.java index d75ea8ed..cab6b03f 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SulphurHillFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SulphurHillFeature.java @@ -1,13 +1,12 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.BlockProperties; @@ -46,7 +45,7 @@ public class SulphurHillFeature extends DefaultFeature { int max = radius + 4; MutableBlockPos mut = new MutableBlockPos(); BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState(); - BlockState brimstone = EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true); + BlockState brimstone = EndBlocks.BRIMSTONE.defaultBlockState().setValue(BlockProperties.ACTIVE, true); for (int x = min; x < max; x++) { int x2 = x * x; int px = pos.getX() + x; diff --git a/src/main/java/ru/betterend/world/features/terrain/SulphuricCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/SulphuricCaveFeature.java index 35aa9add..e02cf7cb 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SulphuricCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SulphuricCaveFeature.java @@ -2,20 +2,18 @@ package ru.betterend.world.features.terrain; import java.util.Random; import java.util.Set; - -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.HorizontalFacingBlock; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.Heightmap; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Sets; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.SulphurCrystalBlock; import ru.betterend.noise.OpenSimplexNoise; @@ -35,14 +33,14 @@ public class SulphuricCaveFeature extends DefaultFeature { NoneFeatureConfiguration config) { int radius = MHelper.randRange(10, 30, random); - int top = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); + int top = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); MutableBlockPos bpos = new MutableBlockPos(); bpos.setX(pos.getX()); bpos.setZ(pos.getZ()); bpos.setY(top - 1); BlockState state = world.getBlockState(bpos); - while (!state.isIn(EndTags.GEN_TERRAIN) && bpos.getY() > 5) { + while (!state.is(EndTags.GEN_TERRAIN) && bpos.getY() > 5) { bpos.setY(bpos.getY() - 1); state = world.getBlockState(bpos); } @@ -51,7 +49,7 @@ public class SulphuricCaveFeature extends DefaultFeature { } top = (int) (bpos.getY() - (radius * 1.3F + 5)); - while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { + while (state.is(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { bpos.setY(bpos.getY() - 1); state = world.getBlockState(bpos); } @@ -102,7 +100,7 @@ public class SulphuricCaveFeature extends DefaultFeature { } } else if (dist < r2 * r2) { state = world.getBlockState(mut); - if (state.isIn(EndTags.GEN_TERRAIN) || state.is(Blocks.AIR)) { + if (state.is(EndTags.GEN_TERRAIN) || state.is(Blocks.AIR)) { double v = noise.eval(x * 0.1, y * 0.1, z * 0.1) + noise.eval(x * 0.03, y * 0.03, z * 0.03) * 0.5; if (v > 0.4) { @@ -128,20 +126,20 @@ public class SulphuricCaveFeature extends DefaultFeature { + random.nextInt(2); if (dist > 0) { state = world.getBlockState(mut); - while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.UNDERWATER_PLANT)) { + while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.WATER_PLANT)) { mut.setY(mut.getY() - 1); state = world.getBlockState(mut); } - if (state.isIn(EndTags.GEN_TERRAIN) - && !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) { + if (state.is(EndTags.GEN_TERRAIN) + && !world.getBlockState(mut.above()).is(EndBlocks.HYDROTHERMAL_VENT)) { for (int j = 0; j <= dist; j++) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone); MHelper.shuffle(HORIZONTAL, random); for (Direction dir : HORIZONTAL) { - BlockPos p = mut.offset(dir); + BlockPos p = mut.relative(dir); if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TUBE_WORM.defaultBlockState() - .with(HorizontalFacingBlock.FACING, dir)); + .setValue(HorizontalDirectionalBlock.FACING, dir)); } } mut.setY(mut.getY() + 1); @@ -151,7 +149,7 @@ public class SulphuricCaveFeature extends DefaultFeature { state = world.getBlockState(mut); while (state.is(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState()); - world.getBlockTickScheduler().schedule(mut, EndBlocks.VENT_BUBBLE_COLUMN, + world.getBlockTicks().scheduleTick(mut, EndBlocks.VENT_BUBBLE_COLUMN, MHelper.randRange(8, 32, random)); mut.setY(mut.getY() + 1); state = world.getBlockState(mut); @@ -167,10 +165,10 @@ public class SulphuricCaveFeature extends DefaultFeature { } private boolean isReplaceable(BlockState state) { - return state.isIn(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT) + return state.is(EndTags.GEN_TERRAIN) || state.is(EndBlocks.HYDROTHERMAL_VENT) || state.is(EndBlocks.VENT_BUBBLE_COLUMN) || state.is(EndBlocks.SULPHUR_CRYSTAL) || state.getMaterial().isReplaceable() || state.getMaterial().equals(Material.PLANT) - || state.getMaterial().equals(Material.UNDERWATER_PLANT) || state.getMaterial().equals(Material.LEAVES); + || state.getMaterial().equals(Material.WATER_PLANT) || state.getMaterial().equals(Material.LEAVES); } private void placeBrimstone(WorldGenLevel world, BlockPos pos, Random random) { @@ -184,7 +182,7 @@ public class SulphuricCaveFeature extends DefaultFeature { private BlockState getBrimstone(WorldGenLevel world, BlockPos pos) { for (Direction dir : BlocksHelper.DIRECTIONS) { if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) { - return EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true); + return EndBlocks.BRIMSTONE.defaultBlockState().setValue(BlockProperties.ACTIVE, true); } } return EndBlocks.BRIMSTONE.defaultBlockState(); @@ -195,8 +193,8 @@ public class SulphuricCaveFeature extends DefaultFeature { BlockPos side; if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) { BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState() - .with(SulphurCrystalBlock.WATERLOGGED, true).with(SulphurCrystalBlock.FACING, dir) - .with(SulphurCrystalBlock.AGE, random.nextInt(3)); + .setValue(SulphurCrystalBlock.WATERLOGGED, true).setValue(SulphurCrystalBlock.FACING, dir) + .setValue(SulphurCrystalBlock.AGE, random.nextInt(3)); BlocksHelper.setWithoutUpdate(world, side, state); } } diff --git a/src/main/java/ru/betterend/world/features/terrain/SulphuricLakeFeature.java b/src/main/java/ru/betterend/world/features/terrain/SulphuricLakeFeature.java index 5f1948a4..50de79e8 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SulphuricLakeFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SulphuricLakeFeature.java @@ -2,18 +2,16 @@ package ru.betterend.world.features.terrain; import java.util.Random; import java.util.Set; - -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Fluids; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Fluids; +import com.google.common.collect.Sets; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.SulphurCrystalBlock; import ru.betterend.noise.OpenSimplexNoise; @@ -60,25 +58,25 @@ public class SulphuricLakeFeature extends DefaultFeature { int dist = x2 + z2; if (dist <= r) { POS.setY(getYOnSurface(world, x, z) - 1); - if (world.getBlockState(POS).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(POS).is(EndTags.GEN_TERRAIN)) { if (isBorder(world, POS)) { if (random.nextInt(8) > 0) { brimstone.add(POS.immutable()); if (random.nextBoolean()) { brimstone.add(POS.below()); if (random.nextBoolean()) { - brimstone.add(POS.down(2)); + brimstone.add(POS.below(2)); } } } else { if (!isAbsoluteBorder(world, POS)) { BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER); - world.getFluidTickScheduler().schedule(POS, Fluids.WATER, 0); + world.getLiquidTicks().scheduleTick(POS, Fluids.WATER, 0); brimstone.add(POS.below()); if (random.nextBoolean()) { - brimstone.add(POS.down(2)); + brimstone.add(POS.below(2)); if (random.nextBoolean()) { - brimstone.add(POS.down(3)); + brimstone.add(POS.below(3)); } } } else { @@ -92,8 +90,8 @@ public class SulphuricLakeFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER); brimstone.remove(POS); for (Direction dir : BlocksHelper.HORIZONTAL) { - BlockPos offseted = POS.offset(dir); - if (world.getBlockState(offseted).isIn(EndTags.GEN_TERRAIN)) { + BlockPos offseted = POS.relative(dir); + if (world.getBlockState(offseted).is(EndTags.GEN_TERRAIN)) { brimstone.add(offseted); } } @@ -101,29 +99,29 @@ public class SulphuricLakeFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, POS.move(Direction.DOWN), Blocks.WATER); brimstone.remove(POS); for (Direction dir : BlocksHelper.HORIZONTAL) { - BlockPos offseted = POS.offset(dir); - if (world.getBlockState(offseted).isIn(EndTags.GEN_TERRAIN)) { + BlockPos offseted = POS.relative(dir); + if (world.getBlockState(offseted).is(EndTags.GEN_TERRAIN)) { brimstone.add(offseted); } } } brimstone.add(POS.below()); if (random.nextBoolean()) { - brimstone.add(POS.down(2)); + brimstone.add(POS.below(2)); if (random.nextBoolean()) { - brimstone.add(POS.down(3)); + brimstone.add(POS.below(3)); } } } } } else if (dist < r2) { POS.setY(getYOnSurface(world, x, z) - 1); - if (world.getBlockState(POS).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(POS).is(EndTags.GEN_TERRAIN)) { brimstone.add(POS.immutable()); if (random.nextBoolean()) { brimstone.add(POS.below()); if (random.nextBoolean()) { - brimstone.add(POS.down(2)); + brimstone.add(POS.below(2)); } } } @@ -141,7 +139,7 @@ public class SulphuricLakeFeature extends DefaultFeature { private boolean isBorder(WorldGenLevel world, BlockPos pos) { int y = pos.getY() + 1; for (Direction dir : BlocksHelper.DIRECTIONS) { - if (getYOnSurface(world, pos.getX() + dir.getOffsetX(), pos.getZ() + dir.getOffsetZ()) < y) { + if (getYOnSurface(world, pos.getX() + dir.getStepX(), pos.getZ() + dir.getStepZ()) < y) { return true; } } @@ -151,7 +149,7 @@ public class SulphuricLakeFeature extends DefaultFeature { private boolean isAbsoluteBorder(WorldGenLevel world, BlockPos pos) { int y = pos.getY() - 2; for (Direction dir : BlocksHelper.DIRECTIONS) { - if (getYOnSurface(world, pos.getX() + dir.getOffsetX() * 3, pos.getZ() + dir.getOffsetZ() * 3) < y) { + if (getYOnSurface(world, pos.getX() + dir.getStepX() * 3, pos.getZ() + dir.getStepZ() * 3) < y) { return true; } } @@ -161,9 +159,9 @@ public class SulphuricLakeFeature extends DefaultFeature { private boolean isDeepWater(WorldGenLevel world, BlockPos pos) { int y = pos.getY() + 1; for (Direction dir : BlocksHelper.DIRECTIONS) { - if (getYOnSurface(world, pos.getX() + dir.getOffsetX(), pos.getZ() + dir.getOffsetZ()) < y - || getYOnSurface(world, pos.getX() + dir.getOffsetX() * 2, pos.getZ() + dir.getOffsetZ() * 2) < y - || getYOnSurface(world, pos.getX() + dir.getOffsetX() * 3, pos.getZ() + dir.getOffsetZ() * 3) < y) { + if (getYOnSurface(world, pos.getX() + dir.getStepX(), pos.getZ() + dir.getStepZ()) < y + || getYOnSurface(world, pos.getX() + dir.getStepX() * 2, pos.getZ() + dir.getStepZ() * 2) < y + || getYOnSurface(world, pos.getX() + dir.getStepX() * 3, pos.getZ() + dir.getStepZ() * 3) < y) { return false; } } @@ -181,7 +179,7 @@ public class SulphuricLakeFeature extends DefaultFeature { private BlockState getBrimstone(WorldGenLevel world, BlockPos pos) { for (Direction dir : BlocksHelper.DIRECTIONS) { if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) { - return EndBlocks.BRIMSTONE.defaultBlockState().with(BlockProperties.ACTIVE, true); + return EndBlocks.BRIMSTONE.defaultBlockState().setValue(BlockProperties.ACTIVE, true); } } return EndBlocks.BRIMSTONE.defaultBlockState(); @@ -192,8 +190,8 @@ public class SulphuricLakeFeature extends DefaultFeature { BlockPos side; if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) { BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState() - .with(SulphurCrystalBlock.WATERLOGGED, true).with(SulphurCrystalBlock.FACING, dir) - .with(SulphurCrystalBlock.AGE, random.nextInt(3)); + .setValue(SulphurCrystalBlock.WATERLOGGED, true).setValue(SulphurCrystalBlock.FACING, dir) + .setValue(SulphurCrystalBlock.AGE, random.nextInt(3)); BlocksHelper.setWithoutUpdate(world, side, state); } } diff --git a/src/main/java/ru/betterend/world/features/terrain/SurfaceVentFeature.java b/src/main/java/ru/betterend/world/features/terrain/SurfaceVentFeature.java index 1e75d2ca..1ddf691e 100644 --- a/src/main/java/ru/betterend/world/features/terrain/SurfaceVentFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/SurfaceVentFeature.java @@ -1,11 +1,10 @@ package ru.betterend.world.features.terrain; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.blocks.HydrothermalVentBlock; @@ -21,13 +20,13 @@ public class SurfaceVentFeature extends DefaultFeature { NoneFeatureConfiguration config) { pos = getPosOnSurface(world, new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))); - if (!world.getBlockState(pos.down(3)).isIn(EndTags.GEN_TERRAIN)) { + if (!world.getBlockState(pos.below(3)).is(EndTags.GEN_TERRAIN)) { return false; } MutableBlockPos mut = new MutableBlockPos(); int count = MHelper.randRange(15, 30, random); - BlockState vent = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().with(HydrothermalVentBlock.WATERLOGGED, + BlockState vent = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState().setValue(HydrothermalVentBlock.WATERLOGGED, false); for (int i = 0; i < count; i++) { mut.set(pos).move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, @@ -40,7 +39,8 @@ public class SurfaceVentFeature extends DefaultFeature { mut.setY(mut.getY() - 1); state = world.getBlockState(mut); } - if (state.isIn(EndTags.GEN_TERRAIN) && !world.getBlockState(mut.up()).is(EndBlocks.HYDROTHERMAL_VENT)) { + if (state.is(EndTags.GEN_TERRAIN) + && !world.getBlockState(mut.above()).is(EndBlocks.HYDROTHERMAL_VENT)) { for (int j = 0; j <= dist; j++) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone); mut.setY(mut.getY() + 1); diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/CaveChunkPopulatorFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/CaveChunkPopulatorFeature.java index 96397bb2..d01a6dad 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/CaveChunkPopulatorFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/CaveChunkPopulatorFeature.java @@ -3,18 +3,16 @@ package ru.betterend.world.features.terrain.caves; import java.util.Random; import java.util.Set; import java.util.function.Supplier; - -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import com.google.common.collect.Sets; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; import ru.betterend.world.biome.cave.EndCaveBiome; @@ -45,8 +43,8 @@ public class CaveChunkPopulatorFeature extends DefaultFeature { return true; } - protected void fillSets(int sx, int sz, Chunk chunk, Set floorPositions, Set ceilPositions, - MutableBlockPos min, MutableBlockPos max) { + protected void fillSets(int sx, int sz, ChunkAccess chunk, Set floorPositions, + Set ceilPositions, MutableBlockPos min, MutableBlockPos max) { MutableBlockPos mut = new MutableBlockPos(); MutableBlockPos mut2 = new MutableBlockPos(); MutableBlockPos mut3 = new MutableBlockPos(); @@ -57,16 +55,16 @@ public class CaveChunkPopulatorFeature extends DefaultFeature { mut.setZ(z); mut2.setZ(z); mut2.setY(0); - for (int y = 1; y < chunk.getHeight(); y++) { + for (int y = 1; y < chunk.getMaxBuildHeight(); y++) { mut.setY(y); BlockState top = chunk.getBlockState(mut); BlockState bottom = chunk.getBlockState(mut2); - if (top.isAir() && (bottom.isIn(EndTags.GEN_TERRAIN) || bottom.is(Blocks.STONE))) { + if (top.isAir() && (bottom.is(EndTags.GEN_TERRAIN) || bottom.is(Blocks.STONE))) { mut3.set(mut2).move(sx, 0, sz); floorPositions.add(mut3.immutable()); updateMin(mut3, min); updateMax(mut3, max); - } else if (bottom.isAir() && (top.isIn(EndTags.GEN_TERRAIN) || top.is(Blocks.STONE))) { + } else if (bottom.isAir() && (top.is(EndTags.GEN_TERRAIN) || top.is(Blocks.STONE))) { mut3.set(mut).move(sx, 0, sz); ceilPositions.add(mut3.immutable()); updateMin(mut3, min); @@ -110,7 +108,7 @@ public class CaveChunkPopulatorFeature extends DefaultFeature { if (density > 0 && random.nextFloat() <= density) { Feature feature = biome.getFloorFeature(random); if (feature != null) { - feature.place(world, null, random, pos.up(), null); + feature.place(world, null, random, pos.above(), null); } } }); diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java index b1787b6c..f7f0f99d 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/EndCaveFeature.java @@ -2,20 +2,18 @@ package ru.betterend.world.features.terrain.caves; import java.util.Random; import java.util.Set; - -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.Heightmap; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import com.google.common.collect.Sets; import ru.betterend.interfaces.IBiomeArray; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndTags; @@ -62,11 +60,11 @@ public abstract class EndCaveFeature extends DefaultFeature { mut.set(bpos); if (world.getBlockState(mut).getMaterial().isReplaceable()) { mut.setY(bpos.getY() - 1); - if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(mut).is(EndTags.GEN_TERRAIN)) { floorPositions.add(mut.immutable()); } mut.setY(bpos.getY() + 1); - if (world.getBlockState(mut).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(mut).is(EndTags.GEN_TERRAIN)) { ceilPositions.add(mut.immutable()); } } @@ -82,7 +80,7 @@ public abstract class EndCaveFeature extends DefaultFeature { return true; } - protected abstract Set place(WorldGenLevel world, BlockPos center, int radius, Random random); + protected abstract Set generate(WorldGenLevel world, BlockPos center, int radius, Random random); protected void placeFloor(WorldGenLevel world, EndCaveBiome biome, Set floorPositions, Random random, BlockState surfaceBlock) { @@ -92,7 +90,7 @@ public abstract class EndCaveFeature extends DefaultFeature { if (density > 0 && random.nextFloat() <= density) { Feature feature = biome.getFloorFeature(random); if (feature != null) { - feature.place(world, null, random, pos.up(), null); + feature.place(world, null, random, pos.above(), null); } } }); @@ -119,21 +117,21 @@ public abstract class EndCaveFeature extends DefaultFeature { } private void setBiome(WorldGenLevel world, BlockPos pos, EndCaveBiome biome) { - IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomeArray(); + IBiomeArray array = (IBiomeArray) world.getChunk(pos).getBiomes(); if (array != null) { array.setBiome(biome.getActualBiome(), pos); } } private BlockPos findPos(WorldGenLevel world, BlockPos pos, int radius, Random random) { - int top = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); + int top = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); MutableBlockPos bpos = new MutableBlockPos(); bpos.setX(pos.getX()); bpos.setZ(pos.getZ()); bpos.setY(top - 1); BlockState state = world.getBlockState(bpos); - while (!state.isIn(EndTags.GEN_TERRAIN) && bpos.getY() > 5) { + while (!state.is(EndTags.GEN_TERRAIN) && bpos.getY() > 5) { bpos.setY(bpos.getY() - 1); state = world.getBlockState(bpos); } @@ -142,7 +140,7 @@ public abstract class EndCaveFeature extends DefaultFeature { } top = (int) (bpos.getY() - (radius * 1.3F + 5)); - while (state.isIn(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { + while (state.is(EndTags.GEN_TERRAIN) || !state.getFluidState().isEmpty() && bpos.getY() > 5) { bpos.setY(bpos.getY() - 1); state = world.getBlockState(bpos); } @@ -181,7 +179,7 @@ public abstract class EndCaveFeature extends DefaultFeature { end.setZ(bpos.getZ()); } }); - BlocksHelper.fixBlocks(world, start.add(-5, -5, -5), end.add(5, 5, 5)); + BlocksHelper.fixBlocks(world, start.offset(-5, -5, -5), end.offset(5, 5, 5)); } protected boolean isWaterNear(WorldGenLevel world, BlockPos pos) { diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/RoundCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/RoundCaveFeature.java index 54c96c39..bcdffd3e 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/RoundCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/RoundCaveFeature.java @@ -2,14 +2,12 @@ package ru.betterend.world.features.terrain.caves; import java.util.Random; import java.util.Set; - -import com.google.common.collect.Sets; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Sets; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; @@ -17,19 +15,19 @@ import ru.betterend.util.MHelper; public class RoundCaveFeature extends EndCaveFeature { @Override - protected Set place(WorldGenLevel world, BlockPos center, int radius, Random random) { + protected Set generate(WorldGenLevel world, BlockPos center, int radius, Random random) { OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); - + int x1 = center.getX() - radius - 5; int z1 = center.getZ() - radius - 5; int x2 = center.getX() + radius + 5; int z2 = center.getZ() + radius + 5; int y1 = MHelper.floor(center.getY() - (radius + 5) / 1.6); int y2 = MHelper.floor(center.getY() + (radius + 5) / 1.6); - + double hr = radius * 0.75; double nr = radius * 0.25; - + BlockState state; MutableBlockPos bpos = new MutableBlockPos(); Set blocks = Sets.newHashSet(); @@ -53,13 +51,13 @@ public class RoundCaveFeature extends EndCaveFeature { if (isReplaceable(state) && !isWaterNear(world, bpos)) { BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR); blocks.add(bpos.immutable()); - + while (state.getMaterial().equals(Material.LEAVES)) { BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR); bpos.setY(bpos.getY() + 1); state = world.getBlockState(bpos); } - + bpos.setY(y - 1); while (state.getMaterial().equals(Material.LEAVES)) { BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR); @@ -71,12 +69,14 @@ public class RoundCaveFeature extends EndCaveFeature { } } } - + return blocks; } - + private boolean isReplaceable(BlockState state) { - return state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().isReplaceable() - || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES); + return state.is(EndTags.GEN_TERRAIN) + || state.getMaterial().isReplaceable() + || state.getMaterial().equals(Material.PLANT) + || state.getMaterial().equals(Material.LEAVES); } } diff --git a/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java b/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java index d428fc45..7a3db063 100644 --- a/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java +++ b/src/main/java/ru/betterend/world/features/terrain/caves/TunelCaveFeature.java @@ -1,17 +1,16 @@ package ru.betterend.world.features.terrain.caves; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; import java.util.Set; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; import ru.betterend.registry.EndTags; import ru.betterend.util.BlocksHelper; import ru.betterend.util.SplineHelper; @@ -19,18 +18,17 @@ import ru.betterend.util.sdf.SDF; public class TunelCaveFeature extends EndCaveFeature { private static final Function REPLACE; - + @Override - protected Set place(WorldGenLevel world, BlockPos center, int radius, Random random) { - // OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, - // center.getX(), center.getZ())); + protected Set generate(WorldGenLevel world, BlockPos center, int radius, Random random) { + //OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); float rad = radius * 0.15F; int min = Mth.ceil(rad) - 15; int max = 31 - Mth.floor(rad); List spline = SplineHelper.makeSpline(0, 0, 0, 0, 0, 0, radius / 3); spline = SplineHelper.smoothSpline(spline, 5); SplineHelper.offsetParts(spline, random, 5, radius * 0.4F, 5); - for (Vector3f vec : spline) { + for (Vector3f vec: spline) { float x = Mth.clamp(vec.x(), min, max); float y = Mth.clamp(vec.y(), -radius, radius); float z = Mth.clamp(vec.z(), min, max); @@ -38,16 +36,18 @@ public class TunelCaveFeature extends EndCaveFeature { } SDF sdf = SplineHelper.buildSDF(spline, rad, rad, (vec) -> Blocks.AIR.defaultBlockState()); Set positions = sdf.setReplaceFunction(REPLACE).getPositions(world, center); - for (BlockPos p : positions) { + for (BlockPos p: positions) { BlocksHelper.setWithoutUpdate(world, p, CAVE_AIR); } return positions; } - + static { REPLACE = (state) -> { - return state.isIn(EndTags.GEN_TERRAIN) || state.getMaterial().isReplaceable() - || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES); + return state.is(EndTags.GEN_TERRAIN) + || state.getMaterial().isReplaceable() + || state.getMaterial().equals(Material.PLANT) + || state.getMaterial().equals(Material.LEAVES); }; } } diff --git a/src/main/java/ru/betterend/world/features/trees/DragonTreeFeature.java b/src/main/java/ru/betterend/world/features/trees/DragonTreeFeature.java index 1a890aa4..b9bf59a0 100644 --- a/src/main/java/ru/betterend/world/features/trees/DragonTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/DragonTreeFeature.java @@ -3,19 +3,17 @@ package ru.betterend.world.features.trees; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -44,7 +42,7 @@ public class DragonTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; float size = MHelper.randRange(10, 25, random); @@ -59,10 +57,10 @@ public class DragonTreeFeature extends DefaultFeature { Vector3f last = SplineHelper.getPos(spline, 3.5F); OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong()); float radius = size * MHelper.randRange(0.5F, 0.7F, random); - makeCap(world, pos.offset(last.getX(), last.getY(), last.getZ()), radius, random, noise); + makeCap(world, pos.offset(last.x(), last.y(), last.z()), radius, random, noise); last = spline.get(0); - makeRoots(world, pos.offset(last.getX(), last.getY(), last.getZ()), radius, random); + makeRoots(world, pos.offset(last.x(), last.y(), last.z()), radius, random); radius = MHelper.randRange(1.2F, 2.3F, random); SDF function = SplineHelper.buildSDF(spline, radius, 1.2F, (bpos) -> { @@ -78,7 +76,7 @@ public class DragonTreeFeature extends DefaultFeature { private void makeCap(WorldGenLevel world, BlockPos pos, float radius, Random random, OpenSimplexNoise noise) { int count = (int) radius; - int offset = (int) (BRANCH.get(BRANCH.size() - 1).getY() * radius); + int offset = (int) (BRANCH.get(BRANCH.size() - 1).y() * radius); for (int i = 0; i < count; i++) { float angle = (float) i / (float) count * MHelper.PI2; float scale = radius * MHelper.randRange(0.85F, 1.15F, random); @@ -98,7 +96,7 @@ public class DragonTreeFeature extends DefaultFeature { SplineHelper.scale(branch, scale); SplineHelper.fillSpline(branch, world, EndBlocks.DRAGON_TREE.bark.defaultBlockState(), pos, REPLACE); } - leavesBall(world, pos.up(offset), radius * 1.15F + 2, random, noise); + leavesBall(world, pos.above(offset), radius * 1.15F + 2, random, noise); } private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, Random random) { @@ -111,7 +109,7 @@ public class DragonTreeFeature extends DefaultFeature { SplineHelper.rotateSpline(branch, angle); SplineHelper.scale(branch, scale); Vector3f last = branch.get(branch.size() - 1); - if (world.getBlockState(pos.offset(last.getX(), last.getY(), last.getZ())).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(EndTags.GEN_TERRAIN)) { SplineHelper.fillSpline(branch, world, EndBlocks.DRAGON_TREE.bark.defaultBlockState(), pos, REPLACE); } } @@ -119,7 +117,7 @@ public class DragonTreeFeature extends DefaultFeature { private void leavesBall(WorldGenLevel world, BlockPos pos, float radius, Random random, OpenSimplexNoise noise) { SDF sphere = new SDFSphere().setRadius(radius) - .setBlock(EndBlocks.DRAGON_TREE_LEAVES.defaultBlockState().with(LeavesBlock.DISTANCE, 6)); + .setBlock(EndBlocks.DRAGON_TREE_LEAVES.defaultBlockState().setValue(LeavesBlock.DISTANCE, 6)); SDF sub = new SDFScale().setScale(5).setSource(sphere); sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub); sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub); @@ -155,7 +153,7 @@ public class DragonTreeFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -174,7 +172,7 @@ public class DragonTreeFeature extends DefaultFeature { random.nextGaussian() * 1); boolean place = true; for (Direction d : Direction.values()) { - BlockState state = world.getBlockState(p.offset(d)); + BlockState state = world.getBlockState(p.relative(d)); if (!EndBlocks.DRAGON_TREE.isTreeLog(state) && !state.is(EndBlocks.DRAGON_TREE_LEAVES)) { place = false; break; @@ -191,7 +189,7 @@ public class DragonTreeFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (state.getBlock() == EndBlocks.DRAGON_TREE_LEAVES) { diff --git a/src/main/java/ru/betterend/world/features/trees/GiganticAmaranitaFeature.java b/src/main/java/ru/betterend/world/features/trees/GiganticAmaranitaFeature.java index 24eb7553..af633bfd 100644 --- a/src/main/java/ru/betterend/world/features/trees/GiganticAmaranitaFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/GiganticAmaranitaFeature.java @@ -1,12 +1,9 @@ package ru.betterend.world.features.trees; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -14,8 +11,10 @@ import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.AxisDirection; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -34,7 +33,7 @@ public class GiganticAmaranitaFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; float size = MHelper.randRange(5, 10, random); @@ -52,8 +51,7 @@ public class GiganticAmaranitaFeature extends DefaultFeature { }); Vector3f capPos = spline.get(spline.size() - 1); - makeHead(world, pos.offset(capPos.getX() + 0.5F, capPos.getY() + 1.5F, capPos.getZ() + 0.5F), - Mth.floor(size / 1.6F)); + makeHead(world, pos.offset(capPos.x() + 0.5F, capPos.y() + 1.5F, capPos.z() + 0.5F), Mth.floor(size / 1.6F)); function.setReplaceFunction(REPLACE); function.addPostProcess(POST); @@ -99,7 +97,7 @@ public class GiganticAmaranitaFeature extends DefaultFeature { mut.move(Direction.DOWN); if (world.getBlockState(mut).getMaterial().isReplaceable()) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_FUR.defaultBlockState() - .with(AttachedBlock.FACING, Direction.DOWN)); + .setValue(AttachedBlock.FACING, Direction.DOWN)); } } } @@ -159,18 +157,18 @@ public class GiganticAmaranitaFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN); Axis axis = x < 0 || x > 1 ? Axis.X : Axis.Z; int distance = axis == Axis.X ? x < 0 ? -1 : 1 : z < 0 ? -1 : 1; - BlockPos offseted = mut.offset(axis, distance); + BlockPos offseted = mut.relative(axis, distance); if (world.getBlockState(offseted).getMaterial().isReplaceable()) { Direction dir = Direction.fromAxisAndDirection(axis, distance < 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE); - BlocksHelper.setWithoutUpdate(world, offseted, - EndBlocks.AMARANITA_FUR.defaultBlockState().with(AttachedBlock.FACING, dir)); + BlocksHelper.setWithoutUpdate(world, offseted, EndBlocks.AMARANITA_FUR + .defaultBlockState().setValue(AttachedBlock.FACING, dir)); } mut.move(Direction.DOWN); } if (world.getBlockState(mut).getMaterial().isReplaceable()) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_FUR.defaultBlockState() - .with(AttachedBlock.FACING, Direction.DOWN)); + .setValue(AttachedBlock.FACING, Direction.DOWN)); } } } @@ -273,18 +271,18 @@ public class GiganticAmaranitaFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN); Axis axis = x < 0 || x > 1 ? Axis.X : Axis.Z; int distance = axis == Axis.X ? x < 0 ? -1 : 1 : z < 0 ? -1 : 1; - BlockPos offseted = mut.offset(axis, distance); + BlockPos offseted = mut.relative(axis, distance); if (world.getBlockState(offseted).getMaterial().isReplaceable()) { Direction dir = Direction.fromAxisAndDirection(axis, distance < 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE); - BlocksHelper.setWithoutUpdate(world, offseted, - EndBlocks.AMARANITA_FUR.defaultBlockState().with(AttachedBlock.FACING, dir)); + BlocksHelper.setWithoutUpdate(world, offseted, EndBlocks.AMARANITA_FUR + .defaultBlockState().setValue(AttachedBlock.FACING, dir)); } mut.move(Direction.DOWN); } if (world.getBlockState(mut).getMaterial().isReplaceable()) { BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_FUR.defaultBlockState() - .with(AttachedBlock.FACING, Direction.DOWN)); + .setValue(AttachedBlock.FACING, Direction.DOWN)); } } } @@ -329,7 +327,7 @@ public class GiganticAmaranitaFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) { + if (state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) { return true; } return state.getMaterial().isReplaceable(); diff --git a/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java b/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java index 5f43fa48..2b294fa0 100644 --- a/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/HelixTreeFeature.java @@ -1,19 +1,18 @@ package ru.betterend.world.features.trees; +import com.mojang.math.Vector3f; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.world.phys.AABB; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.phys.AABB; import ru.betterend.blocks.HelixTreeLeavesBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -35,7 +34,7 @@ public class HelixTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlocksHelper.setWithoutUpdate(world, pos, AIR); @@ -55,7 +54,7 @@ public class HelixTreeFeature extends DefaultFeature { SDF sdf = SplineHelper.buildSDF(spline, 1.7F, 0.5F, (p) -> { return EndBlocks.HELIX_TREE.bark.defaultBlockState(); }); - SDF rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(sdf); + SDF rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(sdf); sdf = new SDFUnion().setSourceA(rotated).setSourceB(sdf); Vector3f lastPoint = spline.get(spline.size() - 1); @@ -63,14 +62,14 @@ public class HelixTreeFeature extends DefaultFeature { SDF stem = SplineHelper.buildSDF(spline2, 1.0F, 0.5F, (p) -> { return EndBlocks.HELIX_TREE.bark.defaultBlockState(); }); - stem = new SDFTranslate().setTranslate(lastPoint.getX(), lastPoint.getY(), lastPoint.getZ()).setSource(stem); + stem = new SDFTranslate().setTranslate(lastPoint.x(), lastPoint.y(), lastPoint.z()).setSource(stem); sdf = new SDFSmoothUnion().setRadius(3).setSourceA(sdf).setSourceB(stem); sdf = new SDFScale().setScale(scale).setSource(sdf); dx = 30 * scale; float dy1 = -20 * scale; float dy2 = 100 * scale; - sdf.addPostProcess(POST).fillArea(world, pos, new Box(pos.offset(-dx, dy1, -dx), pos.offset(dx, dy2, dx))); + sdf.addPostProcess(POST).fillArea(world, pos, new AABB(pos.offset(-dx, dy1, -dx), pos.offset(dx, dy2, dx))); SplineHelper.scale(spline, scale); SplineHelper.fillSplineForce(spline, world, EndBlocks.HELIX_TREE.bark.defaultBlockState(), pos, (state) -> { return state.getMaterial().isReplaceable(); @@ -80,7 +79,7 @@ public class HelixTreeFeature extends DefaultFeature { return state.getMaterial().isReplaceable(); }); SplineHelper.scale(spline2, scale); - BlockPos leafStart = pos.offset(lastPoint.getX() + 0.5, lastPoint.getY() + 0.5, lastPoint.getZ() + 0.5); + BlockPos leafStart = pos.offset(lastPoint.x() + 0.5, lastPoint.y() + 0.5, lastPoint.z() + 0.5); SplineHelper.fillSplineForce(spline2, world, EndBlocks.HELIX_TREE.log.defaultBlockState(), leafStart, (state) -> { return state.getMaterial().isReplaceable(); @@ -107,38 +106,38 @@ public class HelixTreeFeature extends DefaultFeature { BlockState leaf = EndBlocks.HELIX_TREE_LEAVES.defaultBlockState(); for (int i = 1; i < spline.size(); i++) { Vector3f point = spline.get(i); - int minY = MHelper.floor(lastPoint.getY()); - int maxY = MHelper.floor(point.getY()); - float div = point.getY() - lastPoint.getY(); + int minY = MHelper.floor(lastPoint.y()); + int maxY = MHelper.floor(point.y()); + float div = point.y() - lastPoint.y(); for (float py = minY; py <= maxY; py += 0.2F) { start.set(0, py, 0); float delta = (float) (py - minY) / div; - float px = Mth.lerp(delta, lastPoint.getX(), point.getX()); - float pz = Mth.lerp(delta, lastPoint.getZ(), point.getZ()); + float px = Mth.lerp(delta, lastPoint.x(), point.x()); + float pz = Mth.lerp(delta, lastPoint.z(), point.z()); end.set(px, py, pz); fillLine(start, end, world, leaf, leafStart, i / 2 - 1); float ax = Math.abs(px); float az = Math.abs(pz); if (ax > az) { - start.set(start.getX(), start.getY(), start.getZ() + az > 0 ? 1 : -1); - end.set(end.getX(), end.getY(), end.getZ() + az > 0 ? 1 : -1); + start.set(start.x(), start.y(), start.z() + az > 0 ? 1 : -1); + end.set(end.x(), end.y(), end.z() + az > 0 ? 1 : -1); } else { - start.set(start.getX() + ax > 0 ? 1 : -1, start.getY(), start.getZ()); - end.set(end.getX() + ax > 0 ? 1 : -1, end.getY(), end.getZ()); + start.set(start.x() + ax > 0 ? 1 : -1, start.y(), start.z()); + end.set(end.x() + ax > 0 ? 1 : -1, end.y(), end.z()); } fillLine(start, end, world, leaf, leafStart, i / 2 - 1); } lastPoint = point; } - leaf = leaf.with(HelixTreeLeavesBlock.COLOR, 7); - leafStart = leafStart.add(0, lastPoint.getY(), 0); + leaf = leaf.setValue(HelixTreeLeavesBlock.COLOR, 7); + leafStart = leafStart.offset(0, lastPoint.y(), 0); if (world.getBlockState(leafStart).isAir()) { BlocksHelper.setWithoutUpdate(world, leafStart, leaf); - leafStart = leafStart.up(); + leafStart = leafStart.above(); if (world.getBlockState(leafStart).isAir()) { BlocksHelper.setWithoutUpdate(world, leafStart, leaf); - leafStart = leafStart.up(); + leafStart = leafStart.above(); if (world.getBlockState(leafStart).isAir()) { BlocksHelper.setWithoutUpdate(world, leafStart, leaf); } @@ -150,17 +149,17 @@ public class HelixTreeFeature extends DefaultFeature { private void fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, int offset) { - float dx = end.getX() - start.getX(); - float dy = end.getY() - start.getY(); - float dz = end.getZ() - start.getZ(); + float dx = end.x() - start.x(); + float dy = end.y() - start.y(); + float dz = end.z() - start.z(); float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz)); int count = MHelper.floor(max + 1); dx /= max; dy /= max; dz /= max; - float x = start.getX(); - float y = start.getY(); - float z = start.getZ(); + float x = start.x(); + float y = start.y(); + float z = start.z(); MutableBlockPos bPos = new MutableBlockPos(); for (int i = 0; i < count; i++) { @@ -168,15 +167,15 @@ public class HelixTreeFeature extends DefaultFeature { int color = MHelper.floor((float) i / (float) count * 7F + 0.5F) + offset; color = Mth.clamp(color, 0, 7); if (world.getBlockState(bPos).getMaterial().isReplaceable()) { - BlocksHelper.setWithoutUpdate(world, bPos, state.with(HelixTreeLeavesBlock.COLOR, color)); + BlocksHelper.setWithoutUpdate(world, bPos, state.setValue(HelixTreeLeavesBlock.COLOR, color)); } x += dx; y += dy; z += dz; } - bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ()); + bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ()); if (world.getBlockState(bPos).getMaterial().isReplaceable()) { - BlocksHelper.setWithoutUpdate(world, bPos, state.with(HelixTreeLeavesBlock.COLOR, 7)); + BlocksHelper.setWithoutUpdate(world, bPos, state.setValue(HelixTreeLeavesBlock.COLOR, 7)); } } diff --git a/src/main/java/ru/betterend/world/features/trees/JellyshroomFeature.java b/src/main/java/ru/betterend/world/features/trees/JellyshroomFeature.java index 94bedc0d..d553bc59 100644 --- a/src/main/java/ru/betterend/world/features/trees/JellyshroomFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/JellyshroomFeature.java @@ -3,17 +3,15 @@ package ru.betterend.world.features.trees; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.blocks.JellyshroomCapBlock; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -35,7 +33,7 @@ public class JellyshroomFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlockState bark = EndBlocks.JELLYSHROOM.bark.defaultBlockState(); @@ -56,7 +54,7 @@ public class JellyshroomFeature extends DefaultFeature { final float membraneRadius = radius; SDF cap = makeCap(membraneRadius, random, membrane); final Vector3f last = spline.get(spline.size() - 1); - cap = new SDFTranslate().setTranslate(last.getX(), last.getY(), last.getZ()).setSource(cap); + cap = new SDFTranslate().setTranslate(last.x(), last.y(), last.z()).setSource(cap); sdf = new SDFSmoothUnion().setRadius(3F).setSourceA(sdf).setSourceB(cap); sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> { if (EndBlocks.JELLYSHROOM.isTreeLog(info.getState())) { @@ -65,11 +63,11 @@ public class JellyshroomFeature extends DefaultFeature { return EndBlocks.JELLYSHROOM.log.defaultBlockState(); } } else if (info.getState().is(EndBlocks.JELLYSHROOM_CAP_PURPLE)) { - float dx = info.getPos().getX() - pos.getX() - last.getX(); - float dz = info.getPos().getZ() - pos.getZ() - last.getZ(); + float dx = info.getPos().getX() - pos.getX() - last.x(); + float dz = info.getPos().getZ() - pos.getZ() - last.z(); float distance = MHelper.length(dx, dz) / membraneRadius * 7F; int color = Mth.clamp(MHelper.floor(distance), 0, 7); - return info.getState().with(JellyshroomCapBlock.COLOR, color); + return info.getState().setValue(JellyshroomCapBlock.COLOR, color); } return info.getState(); }).fillRecursive(world, pos); @@ -89,7 +87,7 @@ public class JellyshroomFeature extends DefaultFeature { SplineHelper.rotateSpline(branch, angle); SplineHelper.scale(branch, scale); Vector3f last = branch.get(branch.size() - 1); - if (world.getBlockState(pos.offset(last.getX(), last.getY(), last.getZ())).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(EndTags.GEN_TERRAIN)) { SplineHelper.fillSpline(branch, world, wood, pos, REPLACE); } } @@ -118,7 +116,7 @@ public class JellyshroomFeature extends DefaultFeature { SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0)); REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) { + if (state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT)) { return true; } return state.getMaterial().isReplaceable(); diff --git a/src/main/java/ru/betterend/world/features/trees/LacugroveFeature.java b/src/main/java/ru/betterend/world/features/trees/LacugroveFeature.java index d71d222e..2c235cd0 100644 --- a/src/main/java/ru/betterend/world/features/trees/LacugroveFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/LacugroveFeature.java @@ -1,19 +1,18 @@ package ru.betterend.world.features.trees; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -36,7 +35,7 @@ public class LacugroveFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).is(EndTags.END_GROUND)) return false; float size = MHelper.randRange(15, 25, random); @@ -52,7 +51,7 @@ public class LacugroveFeature extends DefaultFeature { float radius = MHelper.randRange(6F, 8F, random); radius *= (size - 15F) / 20F + 1F; Vector3f center = spline.get(4); - leavesBall(world, pos.offset(center.getX(), center.getY(), center.getZ()), radius, random, noise); + leavesBall(world, pos.offset(center.x(), center.y(), center.z()), radius, random, noise); radius = MHelper.randRange(1.2F, 1.8F, random); SDF function = SplineHelper.buildSDF(spline, radius, 0.7F, (bpos) -> { @@ -81,7 +80,7 @@ public class LacugroveFeature extends DefaultFeature { boolean generate = false; for (int y = minY; y < maxY; y++) { mut.setY(y); - if (world.getBlockState(mut).isIn(EndTags.END_GROUND)) { + if (world.getBlockState(mut).is(EndTags.END_GROUND)) { generate = true; break; } @@ -92,7 +91,7 @@ public class LacugroveFeature extends DefaultFeature { mut.setY(y); BlockState state = world.getBlockState(mut); if (state.getMaterial().isReplaceable() || state.getMaterial().equals(Material.PLANT) - || state.isIn(EndTags.END_GROUND)) { + || state.is(EndTags.END_GROUND)) { BlocksHelper.setWithoutUpdate(world, mut, y == top ? EndBlocks.LACUGROVE.bark : EndBlocks.LACUGROVE.log); } else { @@ -109,7 +108,7 @@ public class LacugroveFeature extends DefaultFeature { private void leavesBall(WorldGenLevel world, BlockPos pos, float radius, Random random, OpenSimplexNoise noise) { SDF sphere = new SDFSphere().setRadius(radius) - .setBlock(EndBlocks.LACUGROVE_LEAVES.defaultBlockState().with(LeavesBlock.DISTANCE, 6)); + .setBlock(EndBlocks.LACUGROVE_LEAVES.defaultBlockState().setValue(LeavesBlock.DISTANCE, 6)); sphere = new SDFDisplacement().setFunction((vec) -> { return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3; }).setSource(sphere); @@ -143,7 +142,7 @@ public class LacugroveFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -162,7 +161,7 @@ public class LacugroveFeature extends DefaultFeature { random.nextGaussian() * 1); boolean place = true; for (Direction d : Direction.values()) { - BlockState state = world.getBlockState(p.offset(d)); + BlockState state = world.getBlockState(p.relative(d)); if (!EndBlocks.LACUGROVE.isTreeLog(state) && !state.is(EndBlocks.LACUGROVE_LEAVES)) { place = false; break; @@ -179,7 +178,7 @@ public class LacugroveFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (EndBlocks.LACUGROVE.isTreeLog(state)) { diff --git a/src/main/java/ru/betterend/world/features/trees/LucerniaFeature.java b/src/main/java/ru/betterend/world/features/trees/LucerniaFeature.java index cbf386bb..4ad56fb5 100644 --- a/src/main/java/ru/betterend/world/features/trees/LucerniaFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/LucerniaFeature.java @@ -3,19 +3,17 @@ package ru.betterend.world.features.trees; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.FurBlock; @@ -44,7 +42,7 @@ public class LucerniaFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; float size = MHelper.randRange(12, 20, random); @@ -61,8 +59,7 @@ public class LucerniaFeature extends DefaultFeature { Vector3f last = spline.get(spline.size() - 1); float leavesRadius = (size * 0.13F + MHelper.randRange(0.8F, 1.5F, random)) * 1.4F; OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong()); - leavesBall(world, pos.offset(last.getX(), last.getY(), last.getZ()), leavesRadius, random, noise, - config != null); + leavesBall(world, pos.offset(last.x(), last.y(), last.z()), leavesRadius, random, noise, config != null); } makeRoots(world, pos.offset(0, MHelper.randRange(3, 5, random), 0), size * 0.35F, random); @@ -73,7 +70,7 @@ public class LucerniaFeature extends DefaultFeature { private void leavesBall(WorldGenLevel world, BlockPos pos, float radius, Random random, OpenSimplexNoise noise, boolean natural) { SDF sphere = new SDFSphere().setRadius(radius) - .setBlock(EndBlocks.LUCERNIA_LEAVES.defaultBlockState().with(LeavesBlock.DISTANCE, 6)); + .setBlock(EndBlocks.LUCERNIA_LEAVES.defaultBlockState().setValue(LeavesBlock.DISTANCE, 6)); SDF sub = new SDFScale().setScale(5).setSource(sphere); sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub); sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub); @@ -95,10 +92,10 @@ public class LucerniaFeature extends DefaultFeature { } } - BlockState top = EndBlocks.FILALUX.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); - BlockState middle = EndBlocks.FILALUX.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState top = EndBlocks.FILALUX.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); + BlockState middle = EndBlocks.FILALUX.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE); - BlockState bottom = EndBlocks.FILALUX.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState bottom = EndBlocks.FILALUX.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM); BlockState outer = EndBlocks.LUCERNIA_OUTER_LEAVES.defaultBlockState(); @@ -121,7 +118,7 @@ public class LucerniaFeature extends DefaultFeature { MHelper.shuffle(DIRECTIONS, random); for (Direction d : DIRECTIONS) { if (info.getState(d).isAir()) { - info.setBlockPos(info.getPos().offset(d), outer.with(FurBlock.FACING, d)); + info.setBlockPos(info.getPos().relative(d), outer.setValue(FurBlock.FACING, d)); } } @@ -141,7 +138,7 @@ public class LucerniaFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -159,11 +156,11 @@ public class LucerniaFeature extends DefaultFeature { if (state.isAir() || state.is(EndBlocks.LUCERNIA_OUTER_LEAVES)) { int count = MHelper.randRange(3, 8, random); mut.set(bpos); - if (world.getBlockState(mut.up()).is(EndBlocks.LUCERNIA_LEAVES)) { + if (world.getBlockState(mut.above()).is(EndBlocks.LUCERNIA_LEAVES)) { BlocksHelper.setWithoutUpdate(world, mut, top); for (int i = 1; i < count; i++) { mut.setY(mut.getY() - 1); - if (world.isAir(mut.below())) { + if (world.isEmptyBlock(mut.below())) { BlocksHelper.setWithoutUpdate(world, mut, middle); } else { break; @@ -185,7 +182,7 @@ public class LucerniaFeature extends DefaultFeature { SplineHelper.rotateSpline(branch, angle); SplineHelper.scale(branch, scale); Vector3f last = branch.get(branch.size() - 1); - if (world.getBlockState(pos.offset(last.getX(), last.getY(), last.getZ())).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(EndTags.GEN_TERRAIN)) { SplineHelper.fillSplineForce(branch, world, EndBlocks.LUCERNIA.bark.defaultBlockState(), pos, REPLACE); } } @@ -193,7 +190,7 @@ public class LucerniaFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (state.getBlock() == EndBlocks.LUCERNIA_LEAVES) { diff --git a/src/main/java/ru/betterend/world/features/trees/MossyGlowshroomFeature.java b/src/main/java/ru/betterend/world/features/trees/MossyGlowshroomFeature.java index 453ed3e9..d51eaac2 100644 --- a/src/main/java/ru/betterend/world/features/trees/MossyGlowshroomFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/MossyGlowshroomFeature.java @@ -1,17 +1,16 @@ package ru.betterend.world.features.trees; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.blocks.MossyGlowshroomCapBlock; import ru.betterend.blocks.basis.FurBlock; import ru.betterend.noise.OpenSimplexNoise; @@ -75,7 +74,7 @@ public class MossyGlowshroomFeature extends DefaultFeature { BlocksHelper.setWithoutUpdate(world, blockPos, AIR); CENTER.set(blockPos.getX(), 0, blockPos.getZ()); - HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ()); + HEAD_POS.setTranslate(pos.x(), pos.y(), pos.z()); ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2); FUNCTION.setSourceA(sdf); @@ -83,7 +82,7 @@ public class MossyGlowshroomFeature extends DefaultFeature { if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) { if (random.nextBoolean() && info.getStateUp().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) { info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState() - .with(MossyGlowshroomCapBlock.TRANSITION, true)); + .setValue(MossyGlowshroomCapBlock.TRANSITION, true)); return info.getState(); } else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { @@ -93,7 +92,7 @@ public class MossyGlowshroomFeature extends DefaultFeature { } else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) { if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) { info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState() - .with(MossyGlowshroomCapBlock.TRANSITION, true)); + .setValue(MossyGlowshroomCapBlock.TRANSITION, true)); return info.getState(); } @@ -102,14 +101,14 @@ public class MossyGlowshroomFeature extends DefaultFeature { } else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) { for (Direction dir : BlocksHelper.HORIZONTAL) { if (info.getState(dir) == AIR) { - info.setBlockPos(info.getPos().offset(dir), - EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().with(FurBlock.FACING, dir)); + info.setBlockPos(info.getPos().relative(dir), + EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, dir)); } } if (info.getStateDown().getBlock() != EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) { - info.setBlockPos(info.getPos().below(), - EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().with(FurBlock.FACING, Direction.DOWN)); + info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState() + .setValue(FurBlock.FACING, Direction.DOWN)); } } return info.getState(); @@ -144,12 +143,10 @@ public class MossyGlowshroomFeature extends DefaultFeature { OpenSimplexNoise noise = new OpenSimplexNoise(1234); cones = new SDFCoordModify().setFunction((pos) -> { - float dist = MHelper.length(pos.getX(), pos.getZ()); - float y = pos.getY() - + (float) noise.eval(pos.getX() * 0.1 + CENTER.getX(), pos.getZ() * 0.1 + CENTER.getZ()) * dist - * 0.3F + float dist = MHelper.length(pos.x(), pos.z()); + float y = pos.y() + (float) noise.eval(pos.x() * 0.1 + CENTER.x(), pos.z() * 0.1 + CENTER.z()) * dist * 0.3F - dist * 0.15F; - pos.set(pos.getX(), y, pos.getZ()); + pos.set(pos.x(), y, pos.z()); }).setSource(cones); HEAD_POS = (SDFTranslate) new SDFTranslate() @@ -164,7 +161,7 @@ public class MossyGlowshroomFeature extends DefaultFeature { .setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(ROOTS_ROT)); REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (state.getMaterial().equals(Material.PLANT)) { diff --git a/src/main/java/ru/betterend/world/features/trees/PythadendronTreeFeature.java b/src/main/java/ru/betterend/world/features/trees/PythadendronTreeFeature.java index ac727c80..17254bee 100644 --- a/src/main/java/ru/betterend/world/features/trees/PythadendronTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/PythadendronTreeFeature.java @@ -1,19 +1,18 @@ package ru.betterend.world.features.trees; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; import java.util.function.Function; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndTags; @@ -48,8 +47,8 @@ public class PythadendronTreeFeature extends DefaultFeature { int depth = MHelper.floor((size - 10F) * 3F / 10F + 1F); float bsize = (10F - (size - 10F)) / 10F + 1.5F; - branch(last.getX(), last.getY(), last.getZ(), size * bsize, MHelper.randRange(0, MHelper.PI2, random), random, - depth, world, pos); + branch(last.x(), last.y(), last.z(), size * bsize, MHelper.randRange(0, MHelper.PI2, random), random, depth, + world, pos); SDF function = SplineHelper.buildSDF(spline, 1.7F, 1.1F, (bpos) -> { return EndBlocks.PYTHADENDRON.bark.defaultBlockState(); @@ -93,10 +92,10 @@ public class PythadendronTreeFeature extends DefaultFeature { OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt()); if (depth < 3) { if (s1) { - leavesBall(world, pos.offset(pos1.getX(), pos1.getY(), pos1.getZ()), random, noise); + leavesBall(world, pos.offset(pos1.x(), pos1.y(), pos1.z()), random, noise); } if (s2) { - leavesBall(world, pos.offset(pos2.getX(), pos2.getY(), pos2.getZ()), random, noise); + leavesBall(world, pos.offset(pos2.x(), pos2.y(), pos2.z()), random, noise); } } @@ -106,10 +105,10 @@ public class PythadendronTreeFeature extends DefaultFeature { float angle2 = angle + (float) Math.PI * 0.5F + MHelper.randRange(-0.1F, 0.1F, random); if (s1) { - branch(pos1.getX(), pos1.getY(), pos1.getZ(), size1, angle1, random, depth - 1, world, pos); + branch(pos1.x(), pos1.y(), pos1.z(), size1, angle1, random, depth - 1, world, pos); } if (s2) { - branch(pos2.getX(), pos2.getY(), pos2.getZ(), size2, angle2, random, depth - 1, world, pos); + branch(pos2.x(), pos2.y(), pos2.z(), size2, angle2, random, depth - 1, world, pos); } } @@ -117,7 +116,7 @@ public class PythadendronTreeFeature extends DefaultFeature { float radius = MHelper.randRange(4.5F, 6.5F, random); SDF sphere = new SDFSphere().setRadius(radius) - .setBlock(EndBlocks.PYTHADENDRON_LEAVES.defaultBlockState().with(LeavesBlock.DISTANCE, 6)); + .setBlock(EndBlocks.PYTHADENDRON_LEAVES.defaultBlockState().setValue(LeavesBlock.DISTANCE, 6)); sphere = new SDFScale3D().setScale(1, 0.6F, 1).setSource(sphere); sphere = new SDFDisplacement().setFunction((vec) -> { return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3; @@ -152,7 +151,7 @@ public class PythadendronTreeFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -167,7 +166,7 @@ public class PythadendronTreeFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (state.getBlock() == EndBlocks.PYTHADENDRON_LEAVES) { diff --git a/src/main/java/ru/betterend/world/features/trees/TenaneaFeature.java b/src/main/java/ru/betterend/world/features/trees/TenaneaFeature.java index 627989c6..6a9164a2 100644 --- a/src/main/java/ru/betterend/world/features/trees/TenaneaFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/TenaneaFeature.java @@ -3,19 +3,17 @@ package ru.betterend.world.features.trees; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.LeavesBlock; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.basis.FurBlock; @@ -43,7 +41,7 @@ public class TenaneaFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; float size = MHelper.randRange(7, 10, random); @@ -60,7 +58,7 @@ public class TenaneaFeature extends DefaultFeature { Vector3f last = spline.get(spline.size() - 1); float leavesRadius = (size * 0.3F + MHelper.randRange(0.8F, 1.5F, random)) * 1.4F; OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong()); - leavesBall(world, pos.offset(last.getX(), last.getY(), last.getZ()), leavesRadius, random, noise); + leavesBall(world, pos.offset(last.x(), last.y(), last.z()), leavesRadius, random, noise); } return true; @@ -68,7 +66,7 @@ public class TenaneaFeature extends DefaultFeature { private void leavesBall(WorldGenLevel world, BlockPos pos, float radius, Random random, OpenSimplexNoise noise) { SDF sphere = new SDFSphere().setRadius(radius) - .setBlock(EndBlocks.TENANEA_LEAVES.defaultBlockState().with(LeavesBlock.DISTANCE, 6)); + .setBlock(EndBlocks.TENANEA_LEAVES.defaultBlockState().setValue(LeavesBlock.DISTANCE, 6)); SDF sub = new SDFScale().setScale(5).setSource(sphere); sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub); sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub); @@ -90,11 +88,11 @@ public class TenaneaFeature extends DefaultFeature { } } - BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP); - BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE); - BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, + BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM); BlockState outer = EndBlocks.TENANEA_OUTER_LEAVES.defaultBlockState(); @@ -117,7 +115,7 @@ public class TenaneaFeature extends DefaultFeature { MHelper.shuffle(DIRECTIONS, random); for (Direction d : DIRECTIONS) { if (info.getState(d).isAir()) { - info.setBlockPos(info.getPos().offset(d), outer.with(FurBlock.FACING, d)); + info.setBlockPos(info.getPos().relative(d), outer.setValue(FurBlock.FACING, d)); } } @@ -137,7 +135,7 @@ public class TenaneaFeature extends DefaultFeature { if (state.getBlock() instanceof LeavesBlock) { int distance = state.getValue(LeavesBlock.DISTANCE); if (d < distance) { - info.setState(mut, state.with(LeavesBlock.DISTANCE, d)); + info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d)); } } } @@ -155,11 +153,11 @@ public class TenaneaFeature extends DefaultFeature { if (state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) { int count = MHelper.randRange(3, 8, random); mut.set(bpos); - if (world.getBlockState(mut.up()).is(EndBlocks.TENANEA_LEAVES)) { + if (world.getBlockState(mut.above()).is(EndBlocks.TENANEA_LEAVES)) { BlocksHelper.setWithoutUpdate(world, mut, top); for (int i = 1; i < count; i++) { mut.setY(mut.getY() - 1); - if (world.isAir(mut.below())) { + if (world.isEmptyBlock(mut.below())) { BlocksHelper.setWithoutUpdate(world, mut, middle); } else { break; @@ -173,7 +171,7 @@ public class TenaneaFeature extends DefaultFeature { static { REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND)) { + if (state.is(EndTags.END_GROUND)) { return true; } if (state.getBlock() == EndBlocks.TENANEA_LEAVES) { diff --git a/src/main/java/ru/betterend/world/features/trees/UmbrellaTreeFeature.java b/src/main/java/ru/betterend/world/features/trees/UmbrellaTreeFeature.java index dc7ba0e8..b2ab2b2a 100644 --- a/src/main/java/ru/betterend/world/features/trees/UmbrellaTreeFeature.java +++ b/src/main/java/ru/betterend/world/features/trees/UmbrellaTreeFeature.java @@ -3,19 +3,17 @@ package ru.betterend.world.features.trees; import java.util.List; import java.util.Random; import java.util.function.Function; - -import com.google.common.collect.Lists; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.Material; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.material.Material; +import com.google.common.collect.Lists; +import com.mojang.math.Vector3f; import ru.betterend.blocks.UmbrellaTreeClusterBlock; import ru.betterend.blocks.UmbrellaTreeMembraneBlock; import ru.betterend.registry.EndBlocks; @@ -42,16 +40,16 @@ public class UmbrellaTreeFeature extends DefaultFeature { @Override public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) { - if (!world.getBlockState(pos.below()).getBlock().isIn(EndTags.END_GROUND)) + if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND)) return false; BlockState wood = EndBlocks.UMBRELLA_TREE.bark.defaultBlockState(); - BlockState membrane = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState().with(UmbrellaTreeMembraneBlock.COLOR, - 1); - BlockState center = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState().with(UmbrellaTreeMembraneBlock.COLOR, - 0); - BlockState fruit = EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState().with(UmbrellaTreeClusterBlock.NATURAL, - true); + BlockState membrane = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState() + .setValue(UmbrellaTreeMembraneBlock.COLOR, 1); + BlockState center = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState() + .setValue(UmbrellaTreeMembraneBlock.COLOR, 0); + BlockState fruit = EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState() + .setValue(UmbrellaTreeClusterBlock.NATURAL, true); float size = MHelper.randRange(10, 20, random); int count = (int) (size * 0.15F); @@ -123,7 +121,7 @@ public class UmbrellaTreeFeature extends DefaultFeature { } int color = MHelper.floor(d / min.radius * 7); color = Mth.clamp(color, 1, 7); - return info.getState().with(UmbrellaTreeMembraneBlock.COLOR, color); + return info.getState().setValue(UmbrellaTreeMembraneBlock.COLOR, color); } return info.getState(); }).fillRecursive(world, pos); @@ -156,7 +154,7 @@ public class UmbrellaTreeFeature extends DefaultFeature { SplineHelper.rotateSpline(branch, angle); SplineHelper.scale(branch, scale); Vector3f last = branch.get(branch.size() - 1); - if (world.getBlockState(pos.offset(last.getX(), last.getY(), last.getZ())).isIn(EndTags.GEN_TERRAIN)) { + if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(EndTags.GEN_TERRAIN)) { SplineHelper.fillSplineForce(branch, world, wood, pos, REPLACE); } } @@ -186,8 +184,8 @@ public class UmbrellaTreeFeature extends DefaultFeature { MutableBlockPos mut = new MutableBlockPos().set(px, py, pz); for (int i = 0; i < 8; i++) { mut.move(Direction.DOWN); - if (world.isAir(mut)) { - BlockState state = world.getBlockState(mut.up()); + if (world.isEmptyBlock(mut)) { + BlockState state = world.getBlockState(mut.above()); if (state.is(EndBlocks.UMBRELLA_TREE_MEMBRANE) && state.getValue(UmbrellaTreeMembraneBlock.COLOR) < 2) { BlocksHelper.setWithoutUpdate(world, mut, fruit); } @@ -206,7 +204,7 @@ public class UmbrellaTreeFeature extends DefaultFeature { SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0)); REPLACE = (state) -> { - if (state.isIn(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) + if (state.is(EndTags.END_GROUND) || state.getMaterial().equals(Material.PLANT) || state.is(EndBlocks.UMBRELLA_TREE_MEMBRANE)) { return true; } diff --git a/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java b/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java index ef6ce5a8..e5bd64d9 100644 --- a/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java +++ b/src/main/java/ru/betterend/world/generator/BetterEndBiomeSource.java @@ -1,19 +1,17 @@ package ru.betterend.world.generator; import java.util.List; - +import net.minecraft.core.Registry; +import net.minecraft.resources.RegistryLookupCodec; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.TheEndBiomeSource; +import net.minecraft.world.level.levelgen.WorldgenRandom; +import net.minecraft.world.level.levelgen.synth.SimplexNoise; import com.google.common.collect.Lists; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; - -import net.minecraft.util.math.noise.SimplexNoiseSampler; -import net.minecraft.core.Registry; -import net.minecraft.util.registry.RegistryLookupCodec; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.biome.source.BiomeSource; -import net.minecraft.world.biome.source.TheEndBiomeSource; -import net.minecraft.world.gen.ChunkRandom; import ru.betterend.BetterEnd; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; @@ -23,7 +21,7 @@ import ru.betterend.world.biome.EndBiome; public class BetterEndBiomeSource extends BiomeSource { public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { - return instance.group(RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter((theEndBiomeSource) -> { + return instance.group(RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> { return theEndBiomeSource.biomeRegistry; }), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> { return theEndBiomeSource.seed; @@ -31,7 +29,7 @@ public class BetterEndBiomeSource extends BiomeSource { }); private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324); private final Registry biomeRegistry; - private final SimplexNoiseSampler noise; + private final SimplexNoise noise; private final Biome centerBiome; private final Biome barrens; private BiomeMap mapLand; @@ -40,27 +38,27 @@ public class BetterEndBiomeSource extends BiomeSource { public BetterEndBiomeSource(Registry biomeRegistry, long seed) { super(getBiomes(biomeRegistry)); - + this.mapLand = new BiomeMap(seed, GeneratorOptions.getBiomeSizeLand(), EndBiomes.LAND_BIOMES); this.mapVoid = new BiomeMap(seed, GeneratorOptions.getBiomeSizeVoid(), EndBiomes.VOID_BIOMES); this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END); this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS); this.biomeRegistry = biomeRegistry; this.seed = seed; - - ChunkRandom chunkRandom = new ChunkRandom(seed); - chunkRandom.consume(17292); - this.noise = new SimplexNoiseSampler(chunkRandom); + + WorldgenRandom chunkRandom = new WorldgenRandom(seed); + chunkRandom.consumeCount(17292); + this.noise = new SimplexNoise(chunkRandom); EndBiomes.mutateRegistry(biomeRegistry); EndTags.addTerrainTags(biomeRegistry); FeaturesHelper.addFeatures(biomeRegistry); } - + private static List getBiomes(Registry biomeRegistry) { List list = Lists.newArrayList(); biomeRegistry.forEach((biome) -> { - if (EndBiomes.hasBiome(biomeRegistry.getId(biome))) { + if (EndBiomes.hasBiome(biomeRegistry.getKey(biome))) { list.add(biome); } }); @@ -68,58 +66,58 @@ public class BetterEndBiomeSource extends BiomeSource { } @Override - public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { + public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ) { boolean hasVoid = !GeneratorOptions.useNewGenerator() || !GeneratorOptions.noRingVoid(); long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; - + long dist = i + j; if (hasVoid) { - if (dist <= 65536L) - return this.centerBiome; - } else if (dist <= 625L) { - dist += noise.sample(i * 0.2, j * 0.2) * 10; + if (dist <= 65536L) return this.centerBiome; + } + else if (dist <= 625L) { + dist += noise.getValue(i * 0.2, j * 0.2) * 10; if (dist <= 625L) { return this.centerBiome; } } - + if (biomeX == 0 && biomeZ == 0) { mapLand.clearCache(); mapVoid.clearCache(); } - + if (GeneratorOptions.useNewGenerator()) { if (TerrainGenerator.isLand(biomeX, biomeZ)) { return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); - } else { + } + else { return mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); } - } else { - float height = TheEndBiomeSource.getNoiseAt(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) - + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5; - + } + else { + float height = TheEndBiomeSource.getHeightValue(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5; + if (height > -20F && height < -5F) { return barrens; } - - EndBiome endBiome = height < -10F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) - : mapLand.getBiome(biomeX << 2, biomeZ << 2); + + EndBiome endBiome = height < -10F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2); return endBiome.getActualBiome(); } } - + public Biome getLandBiome(int biomeX, int biomeY, int biomeZ) { boolean hasVoid = !GeneratorOptions.useNewGenerator() || !GeneratorOptions.noRingVoid(); long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; - + long dist = i + j; if (hasVoid) { - if (dist <= 65536L) - return this.centerBiome; - } else if (dist <= 625L) { - dist += noise.sample(i * 0.2, j * 0.2) * 10; + if (dist <= 65536L) return this.centerBiome; + } + else if (dist <= 625L) { + dist += noise.getValue(i * 0.2, j * 0.2) * 10; if (dist <= 625L) { return this.centerBiome; } @@ -133,7 +131,7 @@ public class BetterEndBiomeSource extends BiomeSource { } @Override - protected Codec getCodec() { + protected Codec codec() { return CODEC; } diff --git a/src/main/java/ru/betterend/world/generator/BiomeMap.java b/src/main/java/ru/betterend/world/generator/BiomeMap.java index bcc73d85..5a12b27b 100644 --- a/src/main/java/ru/betterend/world/generator/BiomeMap.java +++ b/src/main/java/ru/betterend/world/generator/BiomeMap.java @@ -1,17 +1,15 @@ package ru.betterend.world.generator; import java.util.Map; - +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.levelgen.WorldgenRandom; import com.google.common.collect.Maps; - -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.gen.ChunkRandom; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; import ru.betterend.world.biome.EndBiome; public class BiomeMap { - private static final ChunkRandom RANDOM = new ChunkRandom(); + private static final WorldgenRandom RANDOM = new WorldgenRandom(); private final Map maps = Maps.newHashMap(); private final int size; @@ -70,7 +68,7 @@ public class BiomeMap { ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH)); BiomeChunk chunk = maps.get(cpos); if (chunk == null) { - RANDOM.setTerrainSeed(cpos.x, cpos.z); + RANDOM.setBaseChunkSeed(cpos.x, cpos.z); chunk = new BiomeChunk(this, RANDOM, picker); maps.put(cpos, chunk); } diff --git a/src/main/java/ru/betterend/world/generator/BiomePicker.java b/src/main/java/ru/betterend/world/generator/BiomePicker.java index 159f4a53..b237a1e5 100644 --- a/src/main/java/ru/betterend/world/generator/BiomePicker.java +++ b/src/main/java/ru/betterend/world/generator/BiomePicker.java @@ -3,11 +3,9 @@ package ru.betterend.world.generator; import java.util.List; import java.util.Random; import java.util.Set; - +import net.minecraft.resources.ResourceLocation; import com.google.common.collect.Lists; import com.google.common.collect.Sets; - -import net.minecraft.resources.ResourceLocation; import ru.betterend.world.biome.EndBiome; public class BiomePicker { @@ -17,38 +15,38 @@ public class BiomePicker { private float maxChance = 0; private int biomeCount = 0; private WeighTree tree; - + public void addBiome(EndBiome biome) { maxChance = biome.mutateGenChance(maxChance); immutableIDs.add(biome.getID()); maxChanceUnmutable = maxChance; biomes.add(biome); - biomeCount++; + biomeCount ++; } - + public void addBiomeMutable(EndBiome biome) { biomes.add(biome); } - + public void clearMutables() { maxChance = maxChanceUnmutable; for (int i = biomes.size() - 1; i >= biomeCount; i--) { biomes.remove(i); } } - + public EndBiome getBiome(Random random) { return biomes.isEmpty() ? null : tree.getBiome(random.nextFloat() * maxChance); } - + public List getBiomes() { return biomes; } - + public boolean containsImmutable(ResourceLocation id) { return immutableIDs.contains(id); } - + public void removeMutableBiome(ResourceLocation id) { for (int i = biomeCount; i < biomes.size(); i++) { EndBiome biome = biomes.get(i); @@ -58,7 +56,7 @@ public class BiomePicker { } } } - + public void rebuild() { if (biomes.isEmpty()) { return; diff --git a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java index 7db78346..b9b34d4c 100644 --- a/src/main/java/ru/betterend/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/betterend/world/generator/GeneratorOptions.java @@ -23,10 +23,10 @@ public class GeneratorOptions { public static LayerOptions smallOptions; private static boolean changeSpawn; private static BlockPos spawn; - private static BlockPos portal = BlockPos.ORIGIN; + private static BlockPos portal = BlockPos.ZERO; private static boolean replacePortal; private static boolean replacePillars; - + public static void init() { biomeSizeLand = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeLand", 256); biomeSizeVoid = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeVoid", 256); @@ -35,23 +35,21 @@ public class GeneratorOptions { hasDragonFights = Configs.GENERATOR_CONFIG.getBooleanRoot("hasDragonFights", true); swapOverworldToEnd = Configs.GENERATOR_CONFIG.getBooleanRoot("swapOverworldToEnd", false); changeChorusPlant = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", "changeChorusPlant", true); - removeChorusFromVanillaBiomes = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", - "removeChorusFromVanillaBiomes", true); + removeChorusFromVanillaBiomes = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", "removeChorusFromVanillaBiomes", true); newGenerator = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "useNewGenerator", true); noRingVoid = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "noRingVoid", false); generateCentralIsland = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "generateCentralIsland", true); endCityFailChance = Configs.GENERATOR_CONFIG.getInt("customGenerator", "endCityFailChance", 5); generateObsidianPlatform = Configs.GENERATOR_CONFIG.getBooleanRoot("generateObsidianPlatform", true); - bigOptions = new LayerOptions("customGenerator.layers.bigIslands", Configs.GENERATOR_CONFIG, 300, 200, 70, 10, - false); - mediumOptions = new LayerOptions("customGenerator.layers.mediumIslands", Configs.GENERATOR_CONFIG, 150, 100, 70, - 20, true); - smallOptions = new LayerOptions("customGenerator.layers.smallIslands", Configs.GENERATOR_CONFIG, 60, 50, 70, 30, - false); + bigOptions = new LayerOptions("customGenerator.layers.bigIslands", Configs.GENERATOR_CONFIG, 300, 200, 70, 10, false); + mediumOptions = new LayerOptions("customGenerator.layers.mediumIslands", Configs.GENERATOR_CONFIG, 150, 100, 70, 20, true); + smallOptions = new LayerOptions("customGenerator.layers.smallIslands", Configs.GENERATOR_CONFIG, 60, 50, 70, 30, false); changeSpawn = Configs.GENERATOR_CONFIG.getBoolean("spawn", "changeSpawn", false); - spawn = new BlockPos(Configs.GENERATOR_CONFIG.getInt("spawn.point", "x", 20), - Configs.GENERATOR_CONFIG.getInt("spawn.point", "y", 65), - Configs.GENERATOR_CONFIG.getInt("spawn.point", "z", 0)); + spawn = new BlockPos( + Configs.GENERATOR_CONFIG.getInt("spawn.point", "x", 20), + Configs.GENERATOR_CONFIG.getInt("spawn.point", "y", 65), + Configs.GENERATOR_CONFIG.getInt("spawn.point", "z", 0) + ); replacePortal = Configs.GENERATOR_CONFIG.getBoolean("portal", "customEndPortal", true); replacePillars = Configs.GENERATOR_CONFIG.getBoolean("spikes", "customObsidianSpikes", true); } @@ -59,7 +57,7 @@ public class GeneratorOptions { public static int getBiomeSizeLand() { return Mth.clamp(biomeSizeLand, 1, 8192); } - + public static int getBiomeSizeVoid() { return Mth.clamp(biomeSizeVoid, 1, 8192); } @@ -67,15 +65,15 @@ public class GeneratorOptions { public static boolean hasPortal() { return hasPortal; } - + public static boolean hasPillars() { return hasPillars; } - + public static boolean hasDragonFights() { return hasDragonFights; } - + public static boolean swapOverworldToEnd() { return swapOverworldToEnd; } @@ -87,23 +85,23 @@ public class GeneratorOptions { public static boolean removeChorusFromVanillaBiomes() { return removeChorusFromVanillaBiomes; } - + public static boolean noRingVoid() { return noRingVoid; } - + public static boolean useNewGenerator() { return newGenerator; } - + public static boolean hasCentralIsland() { return generateCentralIsland; } - + public static boolean generateObsidianPlatform() { return generateObsidianPlatform; } - + public static int getEndCityFailChance() { return endCityFailChance; } @@ -123,11 +121,11 @@ public class GeneratorOptions { public static void setPortalPos(BlockPos portal) { GeneratorOptions.portal = portal; } - + public static boolean replacePortal() { return replacePortal; } - + public static boolean replacePillars() { return replacePillars; } diff --git a/src/main/java/ru/betterend/world/generator/IslandLayer.java b/src/main/java/ru/betterend/world/generator/IslandLayer.java index 16ea3d49..7fcc6919 100644 --- a/src/main/java/ru/betterend/world/generator/IslandLayer.java +++ b/src/main/java/ru/betterend/world/generator/IslandLayer.java @@ -4,11 +4,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Random; - +import net.minecraft.core.BlockPos; import com.google.common.collect.Lists; import com.google.common.collect.Maps; - -import net.minecraft.core.BlockPos; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; import ru.betterend.util.sdf.SDF; @@ -22,7 +20,7 @@ public class IslandLayer { private static final Random RANDOM = new Random(); private final SDFRadialNoiseMap noise; private final SDF island; - + private final List positions = new ArrayList(9); private final Map islands = Maps.newHashMap(); private final OpenSimplexNoise density; @@ -30,34 +28,33 @@ public class IslandLayer { private int lastX = Integer.MIN_VALUE; private int lastZ = Integer.MIN_VALUE; private final LayerOptions options; - + public IslandLayer(int seed, LayerOptions options) { this.density = new OpenSimplexNoise(seed); this.options = options; this.seed = seed; - + SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F); SDF cone2 = makeCone(0.4F, 0.5F, 0.1F, -0.1F); SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F); SDF cone4 = makeCone(0.45F, 0, 0.02F, 0.03F); - + SDF coneBottom = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2); SDF coneTop = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4); - noise = (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSeed(seed).setRadius(0.5F).setIntensity(0.2F) - .setSource(coneTop); + noise = (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSeed(seed).setRadius(0.5F).setIntensity(0.2F).setSource(coneTop); island = new SDFSmoothUnion().setRadius(0.01F).setSourceA(noise).setSourceB(coneBottom); } - + private int getSeed(int x, int z) { int h = seed + x * 374761393 + z * 668265263; h = (h ^ (h >> 13)) * 1274126177; return h ^ (h >> 16); } - + public void updatePositions(double x, double z) { int ix = MHelper.floor(x / options.distance); int iz = MHelper.floor(z / options.distance); - + if (lastX != ix || lastZ != iz) { lastX = ix; lastZ = iz; @@ -80,7 +77,7 @@ public class IslandLayer { } } } - + if (GeneratorOptions.hasCentralIsland() && ix < 4 && iz < 4 && ix > -4 && iz > -4) { List remove = Lists.newArrayList(); positions.forEach((pos) -> { @@ -95,13 +92,14 @@ public class IslandLayer { } } } - + private SDF getIsland(BlockPos pos) { SDF island = islands.get(pos); if (island == null) { if (pos.getX() == 0 && pos.getZ() == 0) { island = new SDFScale().setScale(1.3F).setSource(this.island); - } else { + } + else { RANDOM.setSeed(getSeed(pos.getX(), pos.getZ())); island = new SDFScale().setScale(RANDOM.nextFloat() + 0.5F).setSource(this.island); } @@ -110,74 +108,78 @@ public class IslandLayer { noise.setOffset(pos.getX(), pos.getZ()); return island; } - + private float getRelativeDistance(SDF sdf, BlockPos center, double px, double py, double pz) { float x = (float) (px - center.getX()) / options.scale; float y = (float) (py - center.getY()) / options.scale; float z = (float) (pz - center.getZ()) / options.scale; return sdf.getDistance(x, y, z); } - + private float calculateSDF(double x, double y, double z) { float distance = 10; - for (BlockPos pos : positions) { + for (BlockPos pos: positions) { SDF island = getIsland(pos); float dist = getRelativeDistance(island, pos, x, y, z); distance = MHelper.min(distance, dist); } return distance; } - + public float getDensity(double x, double y, double z) { return -calculateSDF(x, y, z); } - + public float getDensity(double x, double y, double z, float height) { noise.setIntensity(height); noise.setRadius(0.5F / (1 + height)); return -calculateSDF(x, y, z); } - + public void clearCache() { if (islands.size() > 128) { islands.clear(); } } - + private static SDF makeCone(float radiusBottom, float radiusTop, float height, float minY) { float hh = height * 0.5F; SDF sdf = new SDFCappedCone().setHeight(hh).setRadius1(radiusBottom).setRadius2(radiusTop); return new SDFTranslate().setTranslate(0, minY + hh, 0).setSource(sdf); } - - /* - * private static NativeImage loadMap(String path) { InputStream stream = - * IslandLayer.class.getResourceAsStream(path); if (stream != null) { try { - * NativeImage map = NativeImage.read(stream); stream.close(); return map; } - * catch (IOException e) { BetterEnd.LOGGER.warning(e.getMessage()); } } return - * null; } - */ - - /* - * static { NativeImage map = loadMap("/assets/" + BetterEnd.MOD_ID + - * "/textures/heightmaps/mountain_1.png"); - * - * SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F); SDF cone2 = makeCone(0.4F, 0.5F, - * 0.1F, -0.1F); SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F); SDF cone4 = - * makeCone(0.45F, 0, 0.02F, 0.03F); - * - * SDF coneBottom = new - * SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2); SDF - * coneTop = new - * SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4); - * - * SDF map1 = new - * SDFHeightmap().setMap(map).setIntensity(0.3F).setSource(coneTop); NOISE = - * (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSource(coneTop); - * - * ISLAND = new SDF[] { new - * SDFSmoothUnion().setRadius(0.01F).setSourceA(coneTop).setSourceB(coneBottom), - * new SDFSmoothUnion().setRadius(0.01F).setSourceA(map1).setSourceB(coneBottom) - * }; } - */ + + /*private static NativeImage loadMap(String path) { + InputStream stream = IslandLayer.class.getResourceAsStream(path); + if (stream != null) { + try { + NativeImage map = NativeImage.read(stream); + stream.close(); + return map; + } + catch (IOException e) { + BetterEnd.LOGGER.warning(e.getMessage()); + } + } + return null; + }*/ + + /*static { + NativeImage map = loadMap("/assets/" + BetterEnd.MOD_ID + "/textures/heightmaps/mountain_1.png"); + + SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F); + SDF cone2 = makeCone(0.4F, 0.5F, 0.1F, -0.1F); + SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F); + SDF cone4 = makeCone(0.45F, 0, 0.02F, 0.03F); + + SDF coneBottom = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2); + SDF coneTop = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4); + + SDF map1 = new SDFHeightmap().setMap(map).setIntensity(0.3F).setSource(coneTop); + NOISE = (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSource(coneTop); + + ISLAND = new SDF[] { + new SDFSmoothUnion().setRadius(0.01F).setSourceA(coneTop).setSourceB(coneBottom), + new SDFSmoothUnion().setRadius(0.01F).setSourceA(map1).setSourceB(coneBottom) + }; + }*/ } diff --git a/src/main/java/ru/betterend/world/generator/LayerOptions.java b/src/main/java/ru/betterend/world/generator/LayerOptions.java index 95371497..9c57bd3c 100644 --- a/src/main/java/ru/betterend/world/generator/LayerOptions.java +++ b/src/main/java/ru/betterend/world/generator/LayerOptions.java @@ -13,9 +13,8 @@ public class LayerOptions { public final int maxY; public final long centerDist; public final boolean hasCentralIsland; - - public LayerOptions(String name, PathConfig config, float distance, float scale, int center, int heightVariation, - boolean hasCentral) { + + public LayerOptions(String name, PathConfig config, float distance, float scale, int center, int heightVariation, boolean hasCentral) { this.distance = clampDistance(config.getFloat(name, "distance[1-8192]", distance)); this.scale = clampScale(config.getFloat(name, "scale[0.1-1024]", scale)); this.center = clampCenter(config.getInt(name, "averageHeight[0-255]", center)); @@ -26,23 +25,23 @@ public class LayerOptions { this.centerDist = Mth.floor(1000 / this.distance); this.hasCentralIsland = config.getBoolean(name, "hasCentralIsland", hasCentral); } - + private float clampDistance(float value) { return Mth.clamp(value, 1, 8192); } - + private float clampScale(float value) { return Mth.clamp(value, 0.1F, 1024); } - + private float clampCoverage(float value) { return 0.9999F - Mth.clamp(value, 0, 1) * 2; } - + private int clampCenter(int value) { return Mth.clamp(value, 0, 255); } - + private int clampVariation(int value) { return Mth.clamp(value, 0, 255); } diff --git a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java index 151a6a58..6b2818d8 100644 --- a/src/main/java/ru/betterend/world/generator/TerrainGenerator.java +++ b/src/main/java/ru/betterend/world/generator/TerrainGenerator.java @@ -4,12 +4,10 @@ import java.awt.Point; import java.util.List; import java.util.Random; import java.util.concurrent.locks.ReentrantLock; - -import com.google.common.collect.Lists; - import net.minecraft.util.Mth; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.source.BiomeSource; +import net.minecraft.world.level.biome.BiomeSource; +import com.google.common.collect.Lists; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; @@ -19,18 +17,17 @@ public class TerrainGenerator { private static final double SCALE_Y = 4.0; private static final float[] COEF; private static final Point[] OFFS; - + private static IslandLayer largeIslands; private static IslandLayer mediumIslands; private static IslandLayer smallIslands; private static OpenSimplexNoise noise1; private static OpenSimplexNoise noise2; - - /* - * public static boolean canGenerate(int x, int z) { return - * GeneratorOptions.noRingVoid() || (long) x + (long) z > CENTER; } - */ - + + /*public static boolean canGenerate(int x, int z) { + return GeneratorOptions.noRingVoid() || (long) x + (long) z > CENTER; + }*/ + public static void initNoise(long seed) { Random random = new Random(seed); largeIslands = new IslandLayer(random.nextInt(), GeneratorOptions.bigOptions); @@ -39,27 +36,25 @@ public class TerrainGenerator { noise1 = new OpenSimplexNoise(random.nextInt()); noise2 = new OpenSimplexNoise(random.nextInt()); } - + public static void fillTerrainDensity(double[] buffer, int x, int z, BiomeSource biomeSource) { LOCKER.lock(); - + largeIslands.clearCache(); mediumIslands.clearCache(); smallIslands.clearCache(); - - double distortion1 = noise1.eval(x * 0.1, z * 0.1) * 20 + noise2.eval(x * 0.2, z * 0.2) * 10 - + noise1.eval(x * 0.4, z * 0.4) * 5; - double distortion2 = noise2.eval(x * 0.1, z * 0.1) * 20 + noise1.eval(x * 0.2, z * 0.2) * 10 - + noise2.eval(x * 0.4, z * 0.4) * 5; + + double distortion1 = noise1.eval(x * 0.1, z * 0.1) * 20 + noise2.eval(x * 0.2, z * 0.2) * 10 + noise1.eval(x * 0.4, z * 0.4) * 5; + double distortion2 = noise2.eval(x * 0.1, z * 0.1) * 20 + noise1.eval(x * 0.2, z * 0.2) * 10 + noise2.eval(x * 0.4, z * 0.4) * 5; double px = (double) x * SCALE_XZ + distortion1; double pz = (double) z * SCALE_XZ + distortion2; - + largeIslands.updatePositions(px, pz); mediumIslands.updatePositions(px, pz); smallIslands.updatePositions(px, pz); - + float height = getAverageDepth(biomeSource, x << 1, z << 1) * 0.5F; - + for (int y = 0; y < buffer.length; y++) { double py = (double) y * SCALE_Y; float dist = largeIslands.getDensity(px, py, pz, height); @@ -72,10 +67,10 @@ public class TerrainGenerator { } buffer[y] = dist; } - + LOCKER.unlock(); } - + private static float getAverageDepth(BiomeSource biomeSource, int x, int z) { if (getBiome(biomeSource, x, z).getDepth() < 0.1F) { return 0F; @@ -88,37 +83,34 @@ public class TerrainGenerator { } return depth; } - + private static Biome getBiome(BiomeSource biomeSource, int x, int z) { if (biomeSource instanceof BetterEndBiomeSource) { return ((BetterEndBiomeSource) biomeSource).getLandBiome(x, 0, z); } - return biomeSource.getBiomeForNoiseGen(x, 0, z); + return biomeSource.getNoiseBiome(x, 0, z); } - + /** * Check if this is land - * * @param x - biome pos x * @param z - biome pos z */ public static boolean isLand(int x, int z) { LOCKER.lock(); - + double px = (x >> 1) + 0.5; double pz = (z >> 1) + 0.5; - - double distortion1 = noise1.eval(px * 0.1, pz * 0.1) * 20 + noise2.eval(px * 0.2, pz * 0.2) * 10 - + noise1.eval(px * 0.4, pz * 0.4) * 5; - double distortion2 = noise2.eval(px * 0.1, pz * 0.1) * 20 + noise1.eval(px * 0.2, pz * 0.2) * 10 - + noise2.eval(px * 0.4, pz * 0.4) * 5; + + double distortion1 = noise1.eval(px * 0.1, pz * 0.1) * 20 + noise2.eval(px * 0.2, pz * 0.2) * 10 + noise1.eval(px * 0.4, pz * 0.4) * 5; + double distortion2 = noise2.eval(px * 0.1, pz * 0.1) * 20 + noise1.eval(px * 0.2, pz * 0.2) * 10 + noise2.eval(px * 0.4, pz * 0.4) * 5; px = px * SCALE_XZ + distortion1; pz = pz * SCALE_XZ + distortion2; - + largeIslands.updatePositions(px, pz); mediumIslands.updatePositions(px, pz); smallIslands.updatePositions(px, pz); - + for (int y = 0; y < 32; y++) { double py = (double) y * SCALE_Y; float dist = largeIslands.getDensity(px, py, pz); @@ -134,34 +126,31 @@ public class TerrainGenerator { return true; } } - + LOCKER.unlock(); return false; } - + /** * Get something like height - * * @param x - block pos x * @param z - block pos z */ public static int getHeight(int x, int z) { LOCKER.lock(); - + double px = (double) x / 8.0; double pz = (double) z / 8.0; - - double distortion1 = noise1.eval(px * 0.1, pz * 0.1) * 20 + noise2.eval(px * 0.2, pz * 0.2) * 10 - + noise1.eval(px * 0.4, pz * 0.4) * 5; - double distortion2 = noise2.eval(px * 0.1, pz * 0.1) * 20 + noise1.eval(px * 0.2, pz * 0.2) * 10 - + noise2.eval(px * 0.4, pz * 0.4) * 5; + + double distortion1 = noise1.eval(px * 0.1, pz * 0.1) * 20 + noise2.eval(px * 0.2, pz * 0.2) * 10 + noise1.eval(px * 0.4, pz * 0.4) * 5; + double distortion2 = noise2.eval(px * 0.1, pz * 0.1) * 20 + noise1.eval(px * 0.2, pz * 0.2) * 10 + noise2.eval(px * 0.4, pz * 0.4) * 5; px = (double) x * SCALE_XZ + distortion1; pz = (double) z * SCALE_XZ + distortion2; - + largeIslands.updatePositions(px, pz); mediumIslands.updatePositions(px, pz); smallIslands.updatePositions(px, pz); - + for (int y = 32; y >= 0; y--) { double py = (double) y * SCALE_Y; float dist = largeIslands.getDensity(px, py, pz); @@ -177,11 +166,11 @@ public class TerrainGenerator { return Mth.floor(Mth.clamp(y + dist, y, y + 1) * SCALE_Y); } } - + LOCKER.unlock(); return 0; } - + static { float sum = 0; List coef = Lists.newArrayList(); @@ -192,7 +181,7 @@ public class TerrainGenerator { if (dist <= 1) { sum += dist; coef.add(dist); - pos.offset(new Point(x, z)); + pos.add(new Point(x, z)); } } } diff --git a/src/main/java/ru/betterend/world/processors/DestructionStructureProcessor.java b/src/main/java/ru/betterend/world/processors/DestructionStructureProcessor.java index 2ff4898c..92d2b335 100644 --- a/src/main/java/ru/betterend/world/processors/DestructionStructureProcessor.java +++ b/src/main/java/ru/betterend/world/processors/DestructionStructureProcessor.java @@ -1,28 +1,24 @@ package ru.betterend.world.processors; -import net.minecraft.structure.Structure.StructureBlockInfo; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.structure.processor.StructureProcessor; -import net.minecraft.structure.processor.StructureProcessorType; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; import ru.betterend.registry.EndBlocks; import ru.betterend.util.MHelper; public class DestructionStructureProcessor extends StructureProcessor { private int chance = 4; - + public void setChance(int chance) { this.chance = chance; } - + @Override - public StructureBlockInfo process(WorldView worldView, BlockPos pos, BlockPos blockPos, - StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, - StructurePlacementData structurePlacementData) { - if (!structureBlockInfo2.state.is(EndBlocks.ETERNAL_PEDESTAL) - && !structureBlockInfo2.state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) - && MHelper.RANDOM.nextInt(chance) == 0) { + public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) { + if (!structureBlockInfo2.state.is(EndBlocks.ETERNAL_PEDESTAL) && !structureBlockInfo2.state.is(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && MHelper.RANDOM.nextInt(chance) == 0) { return null; } return structureBlockInfo2; diff --git a/src/main/java/ru/betterend/world/processors/TerrainStructureProcessor.java b/src/main/java/ru/betterend/world/processors/TerrainStructureProcessor.java index be56fcf7..a937a1c7 100644 --- a/src/main/java/ru/betterend/world/processors/TerrainStructureProcessor.java +++ b/src/main/java/ru/betterend/world/processors/TerrainStructureProcessor.java @@ -1,24 +1,21 @@ package ru.betterend.world.processors; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.structure.Structure.StructureBlockInfo; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.structure.processor.StructureProcessor; -import net.minecraft.structure.processor.StructureProcessorType; import net.minecraft.core.BlockPos; -import net.minecraft.world.WorldView; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo; public class TerrainStructureProcessor extends StructureProcessor { @Override - public StructureBlockInfo process(WorldView worldView, BlockPos pos, BlockPos blockPos, - StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, - StructurePlacementData structurePlacementData) { + public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) { BlockPos bpos = structureBlockInfo2.pos; - if (structureBlockInfo2.state.is(Blocks.END_STONE) && worldView.isAir(bpos.up())) { - BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings() - .getSurfaceBuilderConfig().getTopMaterial(); - return new StructureBlockInfo(bpos, top, structureBlockInfo2.tag); + if (structureBlockInfo2.state.is(Blocks.END_STONE) && worldView.isEmptyBlock(bpos.above())) { + BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); + return new StructureBlockInfo(bpos, top, structureBlockInfo2.nbt); } return structureBlockInfo2; } diff --git a/src/main/java/ru/betterend/world/structures/EndStructureFeature.java b/src/main/java/ru/betterend/world/structures/EndStructureFeature.java index 05377e2c..396fc2a1 100644 --- a/src/main/java/ru/betterend/world/structures/EndStructureFeature.java +++ b/src/main/java/ru/betterend/world/structures/EndStructureFeature.java @@ -3,31 +3,32 @@ package ru.betterend.world.structures; import java.util.Random; import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; -import net.minecraft.resources.ResourceLocation; import net.minecraft.data.BuiltinRegistries; -import net.minecraft.world.gen.GenerationStep; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import ru.betterend.BetterEnd; public class EndStructureFeature { private static final Random RANDOM = new Random(354); private final StructureFeature structure; private final ConfiguredStructureFeature featureConfigured; - private final GenerationStep.Feature featureStep; - - public EndStructureFeature(String name, StructureFeature structure, - GenerationStep.Feature step, int spacing, int separation) { + private final GenerationStep.Decoration featureStep; + + public EndStructureFeature(String name, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { ResourceLocation id = BetterEnd.makeID(name); - + this.featureStep = step; - this.structure = FabricStructureBuilder.create(id, structure).step(step) - .defaultConfig(spacing, separation, RANDOM.nextInt(8192)).register(); + this.structure = FabricStructureBuilder.create(id, structure) + .step(step) + .defaultConfig(spacing, separation, RANDOM.nextInt(8192)) + .register(); - this.featureConfigured = this.structure.configure(NoneFeatureConfiguration.DEFAULT); - - BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); + this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); + + BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); } public StructureFeature getStructure() { @@ -38,7 +39,7 @@ public class EndStructureFeature { return featureConfigured; } - public GenerationStep.Feature getFeatureStep() { + public GenerationStep.Decoration getFeatureStep() { return featureStep; } } diff --git a/src/main/java/ru/betterend/world/structures/StructureWorld.java b/src/main/java/ru/betterend/world/structures/StructureWorld.java index b6cf310c..9374441e 100644 --- a/src/main/java/ru/betterend/world/structures/StructureWorld.java +++ b/src/main/java/ru/betterend/world/structures/StructureWorld.java @@ -3,17 +3,16 @@ package ru.betterend.world.structures; import java.util.Map; import com.google.common.collect.Maps; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.util.math.BlockBox; -import net.minecraft.core.BlockPos; -import net.minecraft.util.math.ChunkPos; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.levelgen.structure.BoundingBox; public class StructureWorld { private Map parts = Maps.newHashMap(); @@ -25,10 +24,9 @@ public class StructureWorld { private int maxX = Integer.MIN_VALUE; private int maxY = Integer.MIN_VALUE; private int maxZ = Integer.MIN_VALUE; - - public StructureWorld() { - } - + + public StructureWorld() {} + public StructureWorld(CompoundTag tag) { minX = tag.getInt("minX"); maxX = tag.getInt("maxX"); @@ -36,7 +34,7 @@ public class StructureWorld { maxY = tag.getInt("maxY"); minZ = tag.getInt("minZ"); maxZ = tag.getInt("maxZ"); - + ListTag map = tag.getList("parts", 10); map.forEach((element) -> { CompoundTag compound = (CompoundTag) element; @@ -46,49 +44,43 @@ public class StructureWorld { parts.put(new ChunkPos(x, z), part); }); } - + public void setBlock(BlockPos pos, BlockState state) { ChunkPos cPos = new ChunkPos(pos); - + if (cPos.equals(lastPos)) { lastPart.addBlock(pos, state); return; } - + Part part = parts.get(cPos); if (part == null) { part = new Part(); parts.put(cPos, part); - - if (cPos.x < minX) - minX = cPos.x; - if (cPos.x > maxX) - maxX = cPos.x; - if (cPos.z < minZ) - minZ = cPos.z; - if (cPos.z > maxZ) - maxZ = cPos.z; + + if (cPos.x < minX) minX = cPos.x; + if (cPos.x > maxX) maxX = cPos.x; + if (cPos.z < minZ) minZ = cPos.z; + if (cPos.z > maxZ) maxZ = cPos.z; } - if (pos.getY() < minY) - minY = pos.getY(); - if (pos.getY() > maxY) - maxY = pos.getY(); + if (pos.getY() < minY) minY = pos.getY(); + if (pos.getY() > maxY) maxY = pos.getY(); part.addBlock(pos, state); - + lastPos = cPos; lastPart = part; } - + public boolean placeChunk(WorldGenLevel world, ChunkPos chunkPos) { Part part = parts.get(chunkPos); if (part != null) { - Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z); + ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z); part.placeChunk(chunk); return true; } return false; } - + public CompoundTag toBNT() { CompoundTag tag = new CompoundTag(); tag.putInt("minX", minX); @@ -104,49 +96,47 @@ public class StructureWorld { }); return tag; } - - public BlockBox getBounds() { - if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE - || maxZ == Integer.MIN_VALUE) { - return BlockBox.empty(); + + public BoundingBox getBounds() { + if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE || maxZ == Integer.MIN_VALUE) { + return BoundingBox.getUnknownBox(); } - return new BlockBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15); + return new BoundingBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15); } - + private static final class Part { Map blocks = Maps.newHashMap(); - - public Part() { - } - + + public Part() {} + public Part(CompoundTag tag) { ListTag map = tag.getList("blocks", 10); ListTag map2 = tag.getList("states", 10); BlockState[] states = new BlockState[map2.size()]; for (int i = 0; i < states.length; i++) { - states[i] = NbtHelper.toBlockState((CompoundTag) map2.get(i)); + states[i] = NbtUtils.readBlockState((CompoundTag) map2.get(i)); } - + map.forEach((element) -> { CompoundTag block = (CompoundTag) element; - BlockPos pos = NbtHelper.toBlockPos(block.getCompound("pos")); + BlockPos pos = NbtUtils.readBlockPos(block.getCompound("pos")); int stateID = block.getInt("state"); - BlockState state = stateID < states.length ? states[stateID] : Block.getStateFromRawId(stateID); + BlockState state = stateID < states.length ? states[stateID] : Block.stateById(stateID); blocks.put(pos, state); }); } - + void addBlock(BlockPos pos, BlockState state) { BlockPos inner = new BlockPos(pos.getX() & 15, pos.getY(), pos.getZ() & 15); blocks.put(inner, state); } - - void placeChunk(Chunk chunk) { + + void placeChunk(ChunkAccess chunk) { blocks.forEach((pos, state) -> { - chunk.setBlockAndUpdate(pos, state, false); + chunk.setBlockState(pos, state, false); }); } - + CompoundTag toNBT(int x, int z) { CompoundTag tag = new CompoundTag(); tag.putInt("x", x); @@ -155,24 +145,24 @@ public class StructureWorld { tag.put("blocks", map); ListTag stateMap = new ListTag(); tag.put("states", stateMap); - + int[] id = new int[1]; Map states = Maps.newHashMap(); - + blocks.forEach((pos, state) -> { int stateID = states.getOrDefault(states, -1); if (stateID < 0) { - stateID = id[0]++; + stateID = id[0] ++; states.put(state, stateID); - stateMap.add(NbtHelper.fromBlockState(state)); + stateMap.add(NbtUtils.writeBlockState(state)); } - + CompoundTag block = new CompoundTag(); - block.put("pos", NbtHelper.fromBlockPos(pos)); + block.put("pos", NbtUtils.writeBlockPos(pos)); block.putInt("state", stateID); map.add(block); }); - + return tag; } } diff --git a/src/main/java/ru/betterend/world/structures/features/EternalPortalStructure.java b/src/main/java/ru/betterend/world/structures/features/EternalPortalStructure.java index a40bd45c..5cb3dcc9 100644 --- a/src/main/java/ru/betterend/world/structures/features/EternalPortalStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/EternalPortalStructure.java @@ -1,21 +1,21 @@ package ru.betterend.world.structures.features; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.source.BiomeSource; -import net.minecraft.world.gen.ChunkRandom; +import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import ru.betterend.BetterEnd; import ru.betterend.util.MHelper; import ru.betterend.util.StructureHelper; @@ -23,46 +23,40 @@ import ru.betterend.world.structures.piece.NBTPiece; public class EternalPortalStructure extends FeatureBaseStructure { private static final ResourceLocation STRUCTURE_ID = BetterEnd.makeID("portal/eternal_portal"); - private static final Structure STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID); - + private static final StructureTemplate STRUCTURE = StructureHelper.readStructure(STRUCTURE_ID); + @Override - protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, - ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, - NoneFeatureConfiguration featureConfig) { + protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig) { long x = chunkPos.x; long z = chunkPos.z; if (x * x + z * z < 10000) { return false; } - if (chunkGenerator.getHeight((chunkX << 4) | 8, (chunkZ << 4) | 8, Heightmap.Type.WORLD_SURFACE_WG) < 10) { + if (chunkGenerator.getBaseHeight((chunkX << 4) | 8, (chunkZ << 4) | 8, Heightmap.Types.WORLD_SURFACE_WG) < 10) { return false; } - return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos, - featureConfig); + return super.shouldStartAt(chunkGenerator, biomeSource, worldSeed, chunkRandom, chunkX, chunkZ, biome, chunkPos, featureConfig); } - + @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 4) { - this.children.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5), - true, random)); + this.pieces.add(new NBTPiece(STRUCTURE_ID, STRUCTURE, new BlockPos(x, y - 4, z), random.nextInt(5), true, random)); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/features/FeatureBaseStructure.java b/src/main/java/ru/betterend/world/structures/features/FeatureBaseStructure.java index a670c02e..cf36a3ac 100644 --- a/src/main/java/ru/betterend/world/structures/features/FeatureBaseStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/FeatureBaseStructure.java @@ -1,35 +1,32 @@ package ru.betterend.world.structures.features; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Rotation; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.Heightmap; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.source.BiomeSource; -import net.minecraft.world.gen.ChunkRandom; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; public abstract class FeatureBaseStructure extends StructureFeature { protected static final BlockState AIR = Blocks.AIR.defaultBlockState(); - + public FeatureBaseStructure() { super(NoneFeatureConfiguration.CODEC); } - - protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, - ChunkRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, - NoneFeatureConfiguration featureConfig) { + + protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long worldSeed, WorldgenRandom chunkRandom, int chunkX, int chunkZ, Biome biome, ChunkPos chunkPos, NoneFeatureConfiguration featureConfig) { return getGenerationHeight(chunkX, chunkZ, chunkGenerator) >= 20; } private static int getGenerationHeight(int chunkX, int chunkZ, ChunkGenerator chunkGenerator) { Random random = new Random((long) (chunkX + chunkZ * 10387313)); - Rotation blockRotation = Rotation.random(random); + Rotation blockRotation = Rotation.getRandom(random); int i = 5; int j = 5; if (blockRotation == Rotation.CLOCKWISE_90) { @@ -43,10 +40,10 @@ public abstract class FeatureBaseStructure extends StructureFeature points = getFibonacciPoints(count); SDF sdf = null; - SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size) - .setBlock(EndBlocks.DENSE_SNOW); + SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F).setRadius2(0).setHeight(size).setBlock(EndBlocks.DENSE_SNOW); spike = new SDFTranslate().setTranslate(0, size - 0.5F, 0).setSource(spike); - for (Vector3f point : points) { + for (Vector3f point: points) { SDF rotated = spike; point = MHelper.normalize(point); - float angle = MHelper.angle(Vector3f.POSITIVE_Y, point); + float angle = MHelper.angle(Vector3f.YP, point); if (angle > 0.01F && angle < 3.14F) { - Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.POSITIVE_Y, point)); + Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.YP, point)); rotated = new SDFRotation().setRotation(axis, angle).setSource(spike); - } else if (angle > 1) { - rotated = new SDFRotation().setRotation(Vector3f.POSITIVE_Y, (float) Math.PI).setSource(spike); + } + else if (angle > 1) { + rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(spike); } sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated); } - + final float ancientRadius = size * 0.7F; final float denseRadius = size * 0.9F; final float iceRadius = size < 7 ? size * 5 : size * 1.3F; final float randScale = size * 0.3F; - + final BlockPos center = pos; final BlockState ice = EndBlocks.EMERALD_ICE.defaultBlockState(); final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.defaultBlockState(); final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.defaultBlockState(); final SDF sdfCopy = sdf; - + return sdf.addPostProcess((info) -> { BlockPos bpos = info.getPos(); float px = bpos.getX() - center.getX(); float py = bpos.getY() - center.getY(); float pz = bpos.getZ() - center.getZ(); - float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F - + random.nextFloat() * randScale; + float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(px, py, pz) * 0.4F + random.nextFloat() * randScale; if (distance < ancientRadius) { return ancient; - } else if (distance < denseRadius) { + } + else if (distance < denseRadius) { return dense; - } else if (distance < iceRadius) { + } + else if (distance < iceRadius) { return ice; } return info.getState(); }); } - + private List getFibonacciPoints(int count) { float max = count - 1; List result = new ArrayList(count); @@ -94,29 +94,25 @@ public class GiantIceStarStructure extends SDFStructureFeature { } return result; } - + @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return StarStructureStart::new; } - + public static class StarStructureStart extends StructureStart { - public StarStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public StarStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); BlockPos start = new BlockPos(x, MHelper.randRange(32, 128, random), z); - VoxelPiece piece = new VoxelPiece((world) -> { - ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); - }, random.nextInt()); - this.children.add(piece); - this.setBoundingBoxFromChildren(); + VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt()); + this.pieces.add(piece); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/features/GiantMossyGlowshroomStructure.java b/src/main/java/ru/betterend/world/structures/features/GiantMossyGlowshroomStructure.java index c1082948..3def5bb3 100644 --- a/src/main/java/ru/betterend/world/structures/features/GiantMossyGlowshroomStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/GiantMossyGlowshroomStructure.java @@ -1,9 +1,8 @@ package ru.betterend.world.structures.features; +import com.mojang.math.Vector3f; import java.util.List; import java.util.Random; - -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import ru.betterend.blocks.MossyGlowshroomCapBlock; @@ -34,49 +33,43 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature { SDFCappedCone cone1 = new SDFCappedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F); SDFCappedCone cone2 = new SDFCappedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F); SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2); - SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0) - .setSource(new SDFScale().setScale(2).setSource(cone2)); + SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0).setSource(new SDFScale().setScale(2).setSource(cone2)); SDF upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3); SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone); SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave); - + SDF innerCone = new SDFTranslate().setTranslate(0, 1.25F, 0).setSource(upCone); innerCone = new SDFScale3D().setScale(1.2F, 1F, 1.2F).setSource(innerCone); cones = new SDFUnion().setSourceA(cones).setSourceB(innerCone); - + SDF glowCone = new SDFCappedCone().setHeight(3F).setRadius1(2F).setRadius2(12.5F); SDFPrimitive priGlowCone = (SDFPrimitive) glowCone; glowCone = new SDFTranslate().setTranslate(0, 4.25F, 0).setSource(glowCone); glowCone = new SDFSubtraction().setSourceA(glowCone).setSourceB(posedCone3); - + cones = new SDFUnion().setSourceA(cones).setSourceB(glowCone); - + OpenSimplexNoise noise = new OpenSimplexNoise(1234); cones = new SDFCoordModify().setFunction((pos) -> { - float dist = MHelper.length(pos.getX(), pos.getZ()); - float y = pos.getY() - + (float) noise.eval(pos.getX() * 0.1 + center.getX(), pos.getZ() * 0.1 + center.getZ()) * dist - * 0.3F - - dist * 0.15F; - pos.set(pos.getX(), y, pos.getZ()); + float dist = MHelper.length(pos.x(), pos.z()); + float y = pos.y() + (float) noise.eval(pos.x() * 0.1 + center.getX(), pos.z() * 0.1 + center.getZ()) * dist * 0.3F - dist * 0.15F; + pos.set(pos.x(), y, pos.z()); }).setSource(cones); - - SDFTranslate HEAD_POS = (SDFTranslate) new SDFTranslate() - .setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones)); - + + SDFTranslate HEAD_POS = (SDFTranslate) new SDFTranslate().setSource(new SDFTranslate().setTranslate(0, 2.5F, 0).setSource(cones)); + SDF roots = new SDFSphere().setRadius(4F); SDFPrimitive primRoots = (SDFPrimitive) roots; roots = new SDFScale3D().setScale(1, 0.7F, 1).setSource(roots); SDFFlatWave rotRoots = (SDFFlatWave) new SDFFlatWave().setRaysCount(5).setIntensity(1.5F).setSource(roots); - - SDFBinary function = new SDFSmoothUnion().setRadius(4) - .setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(rotRoots)); - + + SDFBinary function = new SDFSmoothUnion().setRadius(4).setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(rotRoots)); + cone1.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP); cone2.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP); priGlowCone.setBlock(EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE); primRoots.setBlock(EndBlocks.MOSSY_GLOWSHROOM.bark); - + float height = MHelper.randRange(10F, 25F, random); int count = MHelper.floor(height / 4); List spline = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, count); @@ -86,43 +79,43 @@ public class GiantMossyGlowshroomStructure extends SDFStructureFeature { }); Vector3f pos = spline.get(spline.size() - 1); float scale = MHelper.randRange(2F, 3.5F, random); - - HEAD_POS.setTranslate(pos.getX(), pos.getY(), pos.getZ()); + + HEAD_POS.setTranslate(pos.x(), pos.y(), pos.z()); rotRoots.setAngle(random.nextFloat() * MHelper.PI2); function.setSourceA(sdf); - - return new SDFRound().setRadius(1.5F).setSource(new SDFScale().setScale(scale).setSource(function)) + + return new SDFRound().setRadius(1.5F).setSource(new SDFScale() + .setScale(scale) + .setSource(function)) .addPostProcess((info) -> { if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) { if (random.nextBoolean() && info.getStateUp().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) { - info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState() - .with(MossyGlowshroomCapBlock.TRANSITION, true)); + info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState().setValue(MossyGlowshroomCapBlock.TRANSITION, true)); return info.getState(); - } else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) - || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { + } + else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown())) { info.setState(EndBlocks.MOSSY_GLOWSHROOM.bark.defaultBlockState()); return info.getState(); } - } else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) { + } + else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) { if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) { - info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState() - .with(MossyGlowshroomCapBlock.TRANSITION, true)); + info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState().setValue(MossyGlowshroomCapBlock.TRANSITION, true)); return info.getState(); } - + info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()); return info.getState(); - } else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) { - for (Direction dir : BlocksHelper.HORIZONTAL) { + } + else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) { + for (Direction dir: BlocksHelper.HORIZONTAL) { if (info.getState(dir) == AIR) { - info.setBlockPos(info.getPos().offset(dir), - EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().with(FurBlock.FACING, dir)); + info.setBlockPos(info.getPos().relative(dir), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, dir)); } } - + if (info.getStateDown().getBlock() != EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) { - info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState() - .with(FurBlock.FACING, Direction.DOWN)); + info.setBlockPos(info.getPos().below(), EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.DOWN)); } } return info.getState(); diff --git a/src/main/java/ru/betterend/world/structures/features/MegaLakeSmallStructure.java b/src/main/java/ru/betterend/world/structures/features/MegaLakeSmallStructure.java index 5ec17e48..2ed7f3c7 100644 --- a/src/main/java/ru/betterend/world/structures/features/MegaLakeSmallStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/MegaLakeSmallStructure.java @@ -1,43 +1,41 @@ package ru.betterend.world.structures.features; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.util.MHelper; import ru.betterend.world.structures.piece.LakePiece; public class MegaLakeSmallStructure extends FeatureBaseStructure { @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 5) { float radius = MHelper.randRange(20, 40, random); float depth = MHelper.randRange(5, 10, random); LakePiece piece = new LakePiece(new BlockPos(x, y, z), radius, depth, random, biome); - this.children.add(piece); + this.pieces.add(piece); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/features/MegaLakeStructure.java b/src/main/java/ru/betterend/world/structures/features/MegaLakeStructure.java index c5ff0335..8a433b2f 100644 --- a/src/main/java/ru/betterend/world/structures/features/MegaLakeStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/MegaLakeStructure.java @@ -1,43 +1,41 @@ package ru.betterend.world.structures.features; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.util.MHelper; import ru.betterend.world.structures.piece.LakePiece; public class MegaLakeStructure extends FeatureBaseStructure { @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 5) { float radius = MHelper.randRange(32, 64, random); float depth = MHelper.randRange(7, 15, random); LakePiece piece = new LakePiece(new BlockPos(x, y, z), radius, depth, random, biome); - this.children.add(piece); + this.pieces.add(piece); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/features/MountainStructure.java b/src/main/java/ru/betterend/world/structures/features/MountainStructure.java index 686d64b6..8ae1acfa 100644 --- a/src/main/java/ru/betterend/world/structures/features/MountainStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/MountainStructure.java @@ -1,44 +1,41 @@ package ru.betterend.world.structures.features; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.util.MHelper; import ru.betterend.world.structures.piece.CrystalMountainPiece; public class MountainStructure extends FeatureBaseStructure { @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 5) { float radius = MHelper.randRange(50, 100, random); float height = radius * MHelper.randRange(0.8F, 1.2F, random); - CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random, - biome); - this.children.add(piece); + CrystalMountainPiece piece = new CrystalMountainPiece(new BlockPos(x, y, z), radius, height, random, biome); + this.pieces.add(piece); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/features/PaintedMountainStructure.java b/src/main/java/ru/betterend/world/structures/features/PaintedMountainStructure.java index 4bb136ba..b9e192dc 100644 --- a/src/main/java/ru/betterend/world/structures/features/PaintedMountainStructure.java +++ b/src/main/java/ru/betterend/world/structures/features/PaintedMountainStructure.java @@ -1,41 +1,39 @@ package ru.betterend.world.structures.features; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.registry.EndBlocks; import ru.betterend.util.MHelper; import ru.betterend.world.structures.piece.PaintedMountainPiece; public class PaintedMountainStructure extends FeatureBaseStructure { private static final BlockState[] VARIANTS; - + @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 50) { float radius = MHelper.randRange(50, 100, random); float height = radius * MHelper.randRange(0.4F, 0.6F, random); @@ -44,15 +42,17 @@ public class PaintedMountainStructure extends FeatureBaseStructure { for (int i = 0; i < count; i++) { slises[i] = VARIANTS[random.nextInt(VARIANTS.length)]; } - this.children - .add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises)); + this.pieces.add(new PaintedMountainPiece(new BlockPos(x, y, z), radius, height, random, biome, slises )); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } - + static { - VARIANTS = new BlockState[] { Blocks.END_STONE.defaultBlockState(), - EndBlocks.FLAVOLITE.stone.defaultBlockState(), EndBlocks.VIOLECITE.stone.defaultBlockState(), }; + VARIANTS = new BlockState[] { + Blocks.END_STONE.defaultBlockState(), + EndBlocks.FLAVOLITE.stone.defaultBlockState(), + EndBlocks.VIOLECITE.stone.defaultBlockState(), + }; } } diff --git a/src/main/java/ru/betterend/world/structures/features/SDFStructureFeature.java b/src/main/java/ru/betterend/world/structures/features/SDFStructureFeature.java index bfbb613b..299b8477 100644 --- a/src/main/java/ru/betterend/world/structures/features/SDFStructureFeature.java +++ b/src/main/java/ru/betterend/world/structures/features/SDFStructureFeature.java @@ -1,50 +1,45 @@ package ru.betterend.world.structures.features; import java.util.Random; - -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructureStart; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.StructureStart; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.util.MHelper; import ru.betterend.util.sdf.SDF; import ru.betterend.world.structures.piece.VoxelPiece; public abstract class SDFStructureFeature extends FeatureBaseStructure { - + protected abstract SDF getSDF(BlockPos pos, Random random); - + @Override - public StructureFeature.StructureStartFactory getStructureStartFactory() { + public StructureFeature.StructureStartFactory getStartFactory() { return SDFStructureStart::new; } - + public static class SDFStructureStart extends StructureStart { - public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, - BlockBox box, int references, long seed) { + public SDFStructureStart(StructureFeature feature, int chunkX, int chunkZ, BoundingBox box, int references, long seed) { super(feature, chunkX, chunkZ, box, references, seed); } @Override - public void init(DynamicRegistryManager registryManager, ChunkGenerator chunkGenerator, - StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { + public void generatePieces(RegistryAccess registryManager, ChunkGenerator chunkGenerator, StructureManager manager, int chunkX, int chunkZ, Biome biome, NoneFeatureConfiguration config) { int x = (chunkX << 4) | MHelper.randRange(4, 12, random); int z = (chunkZ << 4) | MHelper.randRange(4, 12, random); - int y = chunkGenerator.getHeight(x, z, Type.WORLD_SURFACE_WG); + int y = chunkGenerator.getBaseHeight(x, z, Types.WORLD_SURFACE_WG); if (y > 5) { BlockPos start = new BlockPos(x, y, z); - VoxelPiece piece = new VoxelPiece((world) -> { - ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); - }, random.nextInt()); - this.children.add(piece); + VoxelPiece piece = new VoxelPiece((world) -> { ((SDFStructureFeature) this.getFeature()).getSDF(start, this.random).fillRecursive(world, start); }, random.nextInt()); + this.pieces.add(piece); } - this.setBoundingBoxFromChildren(); + this.calculateBoundingBox(); } } } diff --git a/src/main/java/ru/betterend/world/structures/piece/BasePiece.java b/src/main/java/ru/betterend/world/structures/piece/BasePiece.java index aa8fe1a4..b5ce64f8 100644 --- a/src/main/java/ru/betterend/world/structures/piece/BasePiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/BasePiece.java @@ -1,8 +1,8 @@ package ru.betterend.world.structures.piece; import net.minecraft.nbt.CompoundTag; -import net.minecraft.structure.StructurePiece; -import net.minecraft.structure.StructurePieceType; +import net.minecraft.world.level.levelgen.feature.StructurePieceType; +import net.minecraft.world.level.levelgen.structure.StructurePiece; public abstract class BasePiece extends StructurePiece { protected BasePiece(StructurePieceType type, int i) { diff --git a/src/main/java/ru/betterend/world/structures/piece/CavePiece.java b/src/main/java/ru/betterend/world/structures/piece/CavePiece.java index a8042879..fef5d2f0 100644 --- a/src/main/java/ru/betterend/world/structures/piece/CavePiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/CavePiece.java @@ -1,18 +1,17 @@ package ru.betterend.world.structures.piece; import java.util.Random; - -import net.minecraft.world.level.block.Blocks; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.StructureManager; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.util.math.ChunkPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.gen.StructureAccessor; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndStructures; import ru.betterend.registry.EndTags; @@ -23,7 +22,7 @@ public class CavePiece extends BasePiece { private OpenSimplexNoise noise; private BlockPos center; private float radius; - + public CavePiece(BlockPos center, float radius, int id) { super(EndStructures.CAVE_PIECE, id); this.center = center; @@ -36,17 +35,16 @@ public class CavePiece extends BasePiece { super(EndStructures.CAVE_PIECE, tag); makeBoundingBox(); } - + @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { - int x1 = MHelper.max(this.boundingBox.minX, blockBox.minX); - int z1 = MHelper.max(this.boundingBox.minZ, blockBox.minZ); - int x2 = MHelper.min(this.boundingBox.maxX, blockBox.maxX); - int z2 = MHelper.min(this.boundingBox.maxZ, blockBox.maxZ); - int y1 = this.boundingBox.minY; - int y2 = this.boundingBox.maxY; - + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + int x1 = MHelper.max(this.boundingBox.x0, blockBox.x0); + int z1 = MHelper.max(this.boundingBox.z0, blockBox.z0); + int x2 = MHelper.min(this.boundingBox.x1, blockBox.x1); + int z2 = MHelper.min(this.boundingBox.z1, blockBox.z1); + int y1 = this.boundingBox.y0; + int y2 = this.boundingBox.y1; + double hr = radius * 0.75; double nr = radius * 0.25; MutableBlockPos pos = new MutableBlockPos(); @@ -67,10 +65,11 @@ public class CavePiece extends BasePiece { double r2 = r - 4.5; double dist = xsq + ysq + zsq; if (dist < r2 * r2) { - if (world.getBlockState(pos).isIn(EndTags.END_GROUND)) { - BlocksHelper.setWithoutUpdate(world, pos, AIR); + if (world.getBlockState(pos).is(EndTags.END_GROUND)) { + BlocksHelper.setWithoutUpdate(world, pos, CAVE_AIR); } - } else if (dist < r * r) { + } + else if (dist < r * r) { if (world.getBlockState(pos).getMaterial().isReplaceable()) { BlocksHelper.setWithoutUpdate(world, pos, Blocks.END_STONE); } @@ -78,23 +77,23 @@ public class CavePiece extends BasePiece { } } } - + return true; } @Override - protected void toNbt(CompoundTag tag) { - tag.put("center", NbtHelper.fromBlockPos(center)); + protected void addAdditionalSaveData(CompoundTag tag) { + tag.put("center", NbtUtils.writeBlockPos(center)); tag.putFloat("radius", radius); } @Override protected void fromNbt(CompoundTag tag) { - center = NbtHelper.toBlockPos(tag.getCompound("center")); + center = NbtUtils.readBlockPos(tag.getCompound("center")); radius = tag.getFloat("radius"); noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ())); } - + private void makeBoundingBox() { int minX = MHelper.floor(center.getX() - radius); int minY = MHelper.floor(center.getY() - radius); @@ -102,6 +101,6 @@ public class CavePiece extends BasePiece { int maxX = MHelper.floor(center.getX() + radius + 1); int maxY = MHelper.floor(center.getY() + radius + 1); int maxZ = MHelper.floor(center.getZ() + radius + 1); - this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ); + this.boundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ); } } diff --git a/src/main/java/ru/betterend/world/structures/piece/CrystalMountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/CrystalMountainPiece.java index 82d08f40..e85ca44d 100644 --- a/src/main/java/ru/betterend/world/structures/piece/CrystalMountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/CrystalMountainPiece.java @@ -1,23 +1,22 @@ package ru.betterend.world.structures.piece; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.structure.StructureManager; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.util.math.ChunkPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Mth; -import net.minecraft.world.Heightmap; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.StructureAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndStructures; @@ -26,7 +25,7 @@ import ru.betterend.util.MHelper; public class CrystalMountainPiece extends MountainPiece { private BlockState top; - + public CrystalMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome) { super(EndStructures.MOUNTAIN_PIECE, center, radius, height, random, biome); top = biome.getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); @@ -43,14 +42,13 @@ public class CrystalMountainPiece extends MountainPiece { } @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { - int sx = chunkPos.getStartX(); - int sz = chunkPos.getStartZ(); + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + int sx = chunkPos.getMinBlockX(); + int sz = chunkPos.getMinBlockZ(); MutableBlockPos pos = new MutableBlockPos(); - Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z); - Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE); - Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG); + ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z); + Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE); + Heightmap map2 = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE_WG); for (int x = 0; x < 16; x++) { int px = x + sx; int px2 = px - center.getX(); @@ -64,17 +62,16 @@ public class CrystalMountainPiece extends MountainPiece { if (dist < r2) { pos.setZ(z); dist = 1 - (float) Math.pow(dist / r2, 0.3); - int minY = map.get(x, z); + int minY = map.getFirstAvailable(x, z); if (minY < 10) { continue; } pos.setY(minY); - while (!chunk.getBlockState(pos).isIn(EndTags.GEN_TERRAIN) && pos.getY() > 56 - && !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) { + while (!chunk.getBlockState(pos).is(EndTags.GEN_TERRAIN) && pos.getY() > 56 && !chunk.getBlockState(pos.below()).is(Blocks.CAVE_AIR)) { pos.setY(pos.getY() - 1); } minY = pos.getY(); - minY = Math.max(minY, map2.get(x, z)); + minY = Math.max(minY, map2.getFirstAvailable(x, z)); if (minY > center.getY() - 8) { float maxY = dist * height * getHeightClamp(world, 12, px, pz); if (maxY > 0) { @@ -83,30 +80,28 @@ public class CrystalMountainPiece extends MountainPiece { maxY += center.getY(); int maxYI = (int) (maxY); int cover = maxYI - 1; - boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - - (center.getY() + 14) * 0.1) > 0; + boolean needCover = (noise1.eval(px * 0.1, pz * 0.1) + MHelper.randRange(-0.4, 0.4, random) - (center.getY() + 14) * 0.1) > 0; for (int y = minY - 1; y < maxYI; y++) { pos.setY(y); - chunk.setBlockAndUpdate(pos, - needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false); + chunk.setBlockState(pos, needCover && y == cover ? top : Blocks.END_STONE.defaultBlockState(), false); } } } } } } - - map = chunk.getHeightmap(Type.WORLD_SURFACE); - + + map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE); + // Big crystals - int count = (map.get(8, 8) - (center.getY() + 24)) / 7; + int count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 7; count = Mth.clamp(count, 0, 8); for (int i = 0; i < count; i++) { int radius = MHelper.randRange(2, 3, random); float fill = MHelper.randRange(0F, 1F, random); int x = MHelper.randRange(radius, 15 - radius, random); int z = MHelper.randRange(radius, 15 - radius, random); - int y = map.get(x, z); + int y = map.getFirstAvailable(x, z); if (y > 80) { pos.set(x, y, z); if (chunk.getBlockState(pos.below()).is(Blocks.END_STONE)) { @@ -115,16 +110,16 @@ public class CrystalMountainPiece extends MountainPiece { } } } - + // Small crystals - count = (map.get(8, 8) - (center.getY() + 24)) / 2; + count = (map.getFirstAvailable(8, 8) - (center.getY() + 24)) / 2; count = Mth.clamp(count, 4, 8); for (int i = 0; i < count; i++) { int radius = MHelper.randRange(1, 2, random); float fill = random.nextBoolean() ? 0 : 1; int x = MHelper.randRange(radius, 15 - radius, random); int z = MHelper.randRange(radius, 15 - radius, random); - int y = map.get(x, z); + int y = map.getFirstAvailable(x, z); if (y > 80) { pos.set(x, y, z); if (chunk.getBlockState(pos.below()).getBlock() == Blocks.END_STONE) { @@ -133,15 +128,15 @@ public class CrystalMountainPiece extends MountainPiece { } } } - + return true; } - - private void crystal(Chunk chunk, BlockPos pos, int radius, int height, float fill, Random random) { + + private void crystal(ChunkAccess chunk, BlockPos pos, int radius, int height, float fill, Random random) { MutableBlockPos mut = new MutableBlockPos(); int max = MHelper.floor(fill * radius + radius + 0.5F); height += pos.getY(); - Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE); + Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE); int coefX = MHelper.randRange(-1, 1, random); int coefZ = MHelper.randRange(-1, 1, random); for (int x = -radius; x <= radius; x++) { @@ -153,14 +148,14 @@ public class CrystalMountainPiece extends MountainPiece { if (mut.getZ() >= 0 && mut.getZ() < 16) { int az = Math.abs(z); if (ax + az < max) { - int minY = map.get(mut.getX(), mut.getZ()) - MHelper.randRange(3, 7, random); + int minY = map.getFirstAvailable(mut.getX(), mut.getZ()) - MHelper.randRange(3, 7, random); if (pos.getY() - minY > 8) { minY = pos.getY() - 8; } int h = coefX * x + coefZ * z + height; for (int y = minY; y < h; y++) { mut.setY(y); - chunk.setBlockAndUpdate(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false); + chunk.setBlockState(mut, EndBlocks.AURORA_CRYSTAL.defaultBlockState(), false); } } } diff --git a/src/main/java/ru/betterend/world/structures/piece/LakePiece.java b/src/main/java/ru/betterend/world/structures/piece/LakePiece.java index 12939c6f..7200068a 100644 --- a/src/main/java/ru/betterend/world/structures/piece/LakePiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/LakePiece.java @@ -4,26 +4,25 @@ import java.util.Map; import java.util.Random; import com.google.common.collect.Maps; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.fluid.FluidState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.StructureManager; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.util.math.ChunkPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.StructureAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; +import net.minecraft.world.level.material.FluidState; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBlocks; @@ -42,9 +41,9 @@ public class LakePiece extends BasePiece { private float aspect; private float depth; private int seed; - + private ResourceLocation biomeID; - + public LakePiece(BlockPos center, float radius, float depth, Random random, Biome biome) { super(EndStructures.LAKE_PIECE, random.nextInt()); this.center = center; @@ -63,8 +62,8 @@ public class LakePiece extends BasePiece { } @Override - protected void toNbt(CompoundTag tag) { - tag.put("center", NbtHelper.fromBlockPos(center)); + protected void addAdditionalSaveData(CompoundTag tag) { + tag.put("center", NbtUtils.writeBlockPos(center)); tag.putFloat("radius", radius); tag.putFloat("depth", depth); tag.putInt("seed", seed); @@ -73,7 +72,7 @@ public class LakePiece extends BasePiece { @Override protected void fromNbt(CompoundTag tag) { - center = NbtHelper.toBlockPos(tag.getCompound("center")); + center = NbtUtils.readBlockPos(tag.getCompound("center")); radius = tag.getFloat("radius"); depth = tag.getFloat("depth"); seed = tag.getInt("seed"); @@ -83,14 +82,13 @@ public class LakePiece extends BasePiece { } @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { - int minY = this.boundingBox.minY; - int maxY = this.boundingBox.maxY; + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + int minY = this.boundingBox.y0; + int maxY = this.boundingBox.y1; int sx = chunkPos.x << 4; int sz = chunkPos.z << 4; MutableBlockPos mut = new MutableBlockPos(); - Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z); + ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z); for (int x = 0; x < 16; x++) { mut.setX(x); int wx = x | sx; @@ -102,13 +100,12 @@ public class LakePiece extends BasePiece { double nz = wz * 0.1; int z2 = wz - center.getZ(); float clamp = getHeightClamp(world, 8, wx, wz); - if (clamp < 0.01) - continue; - + if (clamp < 0.01) continue; + double n = noise.eval(nx, nz) * 1.5 + 1.5; double x3 = MHelper.pow2(x2 + noise.eval(nx, nz, 100) * 10); double z3 = MHelper.pow2(z2 + noise.eval(nx, nz, -100) * 10); - + for (int y = minY; y <= maxY; y++) { mut.setY((int) (y + n)); double y2 = MHelper.pow2((y - center.getY()) * aspect); @@ -119,24 +116,23 @@ public class LakePiece extends BasePiece { double dist = x3 + y2 + z3; if (dist < r2) { BlockState state = chunk.getBlockState(mut); - if (state.isIn(EndTags.GEN_TERRAIN) || state.isAir()) { - state = mut.getY() < center.getY() ? WATER : AIR; - chunk.setBlockAndUpdate(mut, state, false); + if (state.is(EndTags.GEN_TERRAIN) || state.isAir()) { + state = mut.getY() < center.getY() ? WATER : CAVE_AIR; + chunk.setBlockState(mut, state, false); } - } else if (dist <= r3 && mut.getY() < center.getY()) { + } + else if (dist <= r3 && mut.getY() < center.getY()) { BlockState state = chunk.getBlockState(mut); - BlockPos worldPos = mut.add(sx, 0, sz); - if (!state.isFullCube(world, worldPos) && !state.isSolidBlock(world, worldPos)) { - state = chunk.getBlockState(mut.up()); + BlockPos worldPos = mut.offset(sx, 0, sz); + if (!state.isCollisionShapeFullBlock(world, worldPos) && !state.isRedstoneConductor(world, worldPos)) { + state = chunk.getBlockState(mut.above()); if (state.isAir()) { - state = random.nextBoolean() ? ENDSTONE - : world.getBiome(worldPos).getGenerationSettings().getSurfaceBuilderConfig() - .getTopMaterial(); - } else { - state = state.getFluidState().isEmpty() ? ENDSTONE - : EndBlocks.ENDSTONE_DUST.defaultBlockState(); + state = random.nextBoolean() ? ENDSTONE : world.getBiome(worldPos).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); } - chunk.setBlockAndUpdate(mut, state, false); + else { + state = state.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState(); + } + chunk.setBlockState(mut, state, false); } } } @@ -145,10 +141,10 @@ public class LakePiece extends BasePiece { fixWater(world, chunk, mut, random, sx, sz); return true; } - - private void fixWater(WorldGenLevel world, Chunk chunk, MutableBlockPos mut, Random random, int sx, int sz) { - int minY = this.boundingBox.minY; - int maxY = this.boundingBox.maxY; + + private void fixWater(WorldGenLevel world, ChunkAccess chunk, MutableBlockPos mut, Random random, int sx, int sz) { + int minY = this.boundingBox.y0; + int maxY = this.boundingBox.y1; for (int x = 0; x < 16; x++) { mut.setX(x); for (int z = 0; z < 16; z++) { @@ -160,78 +156,76 @@ public class LakePiece extends BasePiece { mut.setY(y - 1); if (chunk.getBlockState(mut).isAir()) { mut.setY(y + 1); - + BlockState bState = chunk.getBlockState(mut); if (bState.isAir()) { - bState = random.nextBoolean() ? ENDSTONE - : world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings() - .getSurfaceBuilderConfig().getTopMaterial(); - } else { - bState = bState.getFluidState().isEmpty() ? ENDSTONE - : EndBlocks.ENDSTONE_DUST.defaultBlockState(); + bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.offset(sx, 0, sz)).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); } - + else { + bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState(); + } + mut.setY(y); - + makeEndstonePillar(chunk, mut, bState); - } else if (x > 1 && x < 15 && z > 1 && z < 15) { + } + else if (x > 1 && x < 15 && z > 1 && z < 15) { mut.setY(y); - for (Direction dir : BlocksHelper.HORIZONTAL) { - BlockPos wPos = mut.add(dir.getOffsetX(), 0, dir.getOffsetZ()); + for (Direction dir: BlocksHelper.HORIZONTAL) { + BlockPos wPos = mut.offset(dir.getStepX(), 0, dir.getStepZ()); if (chunk.getBlockState(wPos).isAir()) { mut.setY(y + 1); BlockState bState = chunk.getBlockState(mut); if (bState.isAir()) { - bState = random.nextBoolean() ? ENDSTONE - : world.getBiome(mut.add(sx, 0, sz)).getGenerationSettings() - .getSurfaceBuilderConfig().getTopMaterial(); - } else { - bState = bState.getFluidState().isEmpty() ? ENDSTONE - : EndBlocks.ENDSTONE_DUST.defaultBlockState(); + bState = random.nextBoolean() ? ENDSTONE : world.getBiome(mut.offset(sx, 0, sz)).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); + } + else { + bState = bState.getFluidState().isEmpty() ? ENDSTONE : EndBlocks.ENDSTONE_DUST.defaultBlockState(); } mut.setY(y); makeEndstonePillar(chunk, mut, bState); break; } } - } else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) { - chunk.getFluidTickScheduler().schedule(mut.move(Direction.DOWN), state.getFluid(), 0); + } + else if (chunk.getBlockState(mut.move(Direction.UP)).isAir()) { + chunk.getLiquidTicks().scheduleTick(mut.move(Direction.DOWN), state.getType(), 0); } } } } } } - - private void makeEndstonePillar(Chunk chunk, MutableBlockPos mut, BlockState terrain) { - chunk.setBlockAndUpdate(mut, terrain, false); + + private void makeEndstonePillar(ChunkAccess chunk, MutableBlockPos mut, BlockState terrain) { + chunk.setBlockState(mut, terrain, false); mut.setY(mut.getY() - 1); while (!chunk.getFluidState(mut).isEmpty()) { - chunk.setBlockAndUpdate(mut, ENDSTONE, false); + chunk.setBlockState(mut, ENDSTONE, false); mut.setY(mut.getY() - 1); } } - + private int getHeight(WorldGenLevel world, BlockPos pos) { int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047); int h = heightmap.getOrDefault(p, Byte.MIN_VALUE); if (h > Byte.MIN_VALUE) { return h; } - + if (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) { heightmap.put(p, (byte) 0); return 0; } - + h = world.getHeight(Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ()); h = Mth.abs(h - center.getY()); h = h < 8 ? 1 : 0; - + heightmap.put(p, (byte) h); return h; } - + private float getHeightClamp(WorldGenLevel world, int radius, int posX, int posZ) { MutableBlockPos mut = new MutableBlockPos(); int r2 = radius * radius; @@ -253,7 +247,7 @@ public class LakePiece extends BasePiece { height /= max; return Mth.clamp(height, 0, 1); } - + private void makeBoundingBox() { int minX = MHelper.floor(center.getX() - radius - 8); int minY = MHelper.floor(center.getY() - depth - 8); @@ -261,6 +255,6 @@ public class LakePiece extends BasePiece { int maxX = MHelper.floor(center.getX() + radius + 8); int maxY = MHelper.floor(center.getY() + depth); int maxZ = MHelper.floor(center.getZ() + radius + 8); - this.boundingBox = new BlockBox(minX, minY, minZ, maxX, maxY, maxZ); + this.boundingBox = new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java index a066e38b..95f10b32 100644 --- a/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/MountainPiece.java @@ -4,19 +4,18 @@ import java.util.Map; import java.util.Random; import com.google.common.collect.Maps; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructurePieceType; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; -import net.minecraft.world.Heightmap.Type; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.feature.StructurePieceType; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.registry.EndBiomes; import ru.betterend.util.MHelper; @@ -32,9 +31,8 @@ public abstract class MountainPiece extends BasePiece { protected ResourceLocation biomeID; protected int seed1; protected int seed2; - - public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, - Biome biome) { + + public MountainPiece(StructurePieceType type, BlockPos center, float radius, float height, Random random, Biome biome) { super(type, random.nextInt()); this.center = center; this.radius = radius; @@ -54,8 +52,8 @@ public abstract class MountainPiece extends BasePiece { } @Override - protected void toNbt(CompoundTag tag) { - tag.put("center", NbtHelper.fromBlockPos(center)); + protected void addAdditionalSaveData(CompoundTag tag) { + tag.put("center", NbtUtils.writeBlockPos(center)); tag.putFloat("radius", radius); tag.putFloat("height", height); tag.putString("biome", biomeID.toString()); @@ -65,7 +63,7 @@ public abstract class MountainPiece extends BasePiece { @Override protected void fromNbt(CompoundTag tag) { - center = NbtHelper.toBlockPos(tag.getCompound("center")); + center = NbtUtils.readBlockPos(tag.getCompound("center")); radius = tag.getFloat("radius"); height = tag.getFloat("height"); biomeID = new ResourceLocation(tag.getString("biome")); @@ -75,14 +73,14 @@ public abstract class MountainPiece extends BasePiece { noise1 = new OpenSimplexNoise(seed1); noise2 = new OpenSimplexNoise(seed2); } - + private int getHeight(WorldGenLevel world, BlockPos pos) { int p = ((pos.getX() & 2047) << 11) | (pos.getZ() & 2047); int h = heightmap.getOrDefault(p, Integer.MIN_VALUE); if (h > Integer.MIN_VALUE) { return h; } - + if (!EndBiomes.getBiomeID(world.getBiome(pos)).equals(biomeID)) { heightmap.put(p, -10); return -10; @@ -94,20 +92,19 @@ public abstract class MountainPiece extends BasePiece { heightmap.put(p, h); return h; } - - h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01) - * noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8); - + + h = MHelper.floor(noise2.eval(pos.getX() * 0.01, pos.getZ() * 0.01) * noise2.eval(pos.getX() * 0.002, pos.getZ() * 0.002) * 8 + 8); + if (h < 0) { heightmap.put(p, 0); return 0; } - + heightmap.put(p, h); - + return h; } - + protected float getHeightClamp(WorldGenLevel world, int radius, int posX, int posZ) { MutableBlockPos mut = new MutableBlockPos(); float height = 0; @@ -128,12 +125,12 @@ public abstract class MountainPiece extends BasePiece { height /= max; return Mth.clamp(height / radius, 0, 1); } - + private void makeBoundingBox() { int minX = MHelper.floor(center.getX() - radius); int minZ = MHelper.floor(center.getZ() - radius); int maxX = MHelper.floor(center.getX() + radius + 1); int maxZ = MHelper.floor(center.getZ() + radius + 1); - this.boundingBox = new BlockBox(minX, minZ, maxX, maxZ); + this.boundingBox = new BoundingBox(minX, minZ, maxX, maxZ); } } diff --git a/src/main/java/ru/betterend/world/structures/piece/NBTPiece.java b/src/main/java/ru/betterend/world/structures/piece/NBTPiece.java index 29e87287..63fa5bd7 100644 --- a/src/main/java/ru/betterend/world/structures/piece/NBTPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/NBTPiece.java @@ -1,21 +1,20 @@ package ru.betterend.world.structures.piece; import java.util.Random; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.Structure; -import net.minecraft.structure.StructureManager; -import net.minecraft.structure.StructurePlacementData; -import net.minecraft.util.BlockMirror; -import net.minecraft.world.level.block.Rotation; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.math.ChunkPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.gen.StructureAccessor; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import ru.betterend.registry.EndStructures; import ru.betterend.util.MHelper; import ru.betterend.util.StructureHelper; @@ -23,19 +22,18 @@ import ru.betterend.util.StructureHelper; public class NBTPiece extends BasePiece { private ResourceLocation structureID; private Rotation rotation; - private BlockMirror mirror; - private Structure structure; + private Mirror mirror; + private StructureTemplate structure; private BlockPos pos; private int erosion; private boolean cover; - - public NBTPiece(ResourceLocation structureID, Structure structure, BlockPos pos, int erosion, boolean cover, - Random random) { + + public NBTPiece(ResourceLocation structureID, StructureTemplate structure, BlockPos pos, int erosion, boolean cover, Random random) { super(EndStructures.NBT_PIECE, random.nextInt()); this.structureID = structureID; this.structure = structure; - this.rotation = Rotation.random(random); - this.mirror = BlockMirror.values()[random.nextInt(3)]; + this.rotation = Rotation.getRandom(random); + this.mirror = Mirror.values()[random.nextInt(3)]; this.pos = StructureHelper.offsetPos(pos, structure, rotation, mirror); this.erosion = erosion; this.cover = cover; @@ -48,12 +46,12 @@ public class NBTPiece extends BasePiece { } @Override - protected void toNbt(CompoundTag tag) { + protected void addAdditionalSaveData(CompoundTag tag) { tag.putString("id", structureID.toString()); tag.putInt("rotation", rotation.ordinal()); tag.putInt("mirror", mirror.ordinal()); tag.putInt("erosion", erosion); - tag.put("pos", NbtHelper.fromBlockPos(pos)); + tag.put("pos", NbtUtils.writeBlockPos(pos)); tag.putBoolean("cover", cover); } @@ -61,27 +59,25 @@ public class NBTPiece extends BasePiece { protected void fromNbt(CompoundTag tag) { structureID = new ResourceLocation(tag.getString("id")); rotation = Rotation.values()[tag.getInt("rotation")]; - mirror = BlockMirror.values()[tag.getInt("mirror")]; + mirror = Mirror.values()[tag.getInt("mirror")]; erosion = tag.getInt("erosion"); - pos = NbtHelper.toBlockPos(tag.getCompound("pos")); + pos = NbtUtils.readBlockPos(tag.getCompound("pos")); cover = tag.getBoolean("cover"); structure = StructureHelper.readStructure(structureID); } @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { - BlockBox bounds = new BlockBox(blockBox); - bounds.maxY = this.boundingBox.maxY; - bounds.minY = this.boundingBox.minY; - StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror) - .setBoundingBox(bounds); - structure.place(world, pos, placementData, random); + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + BoundingBox bounds = new BoundingBox(blockBox); + bounds.y1 = this.boundingBox.y1; + bounds.y0 = this.boundingBox.y0; + StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds); + structure.placeInWorldChunk(world, pos, placementData, random); if (erosion > 0) { - bounds.maxX = MHelper.min(bounds.maxX, boundingBox.maxX); - bounds.minX = MHelper.max(bounds.minX, boundingBox.minX); - bounds.maxZ = MHelper.min(bounds.maxZ, boundingBox.maxZ); - bounds.minZ = MHelper.max(bounds.minZ, boundingBox.minZ); + bounds.x1 = MHelper.min(bounds.x1, boundingBox.x1); + bounds.x0 = MHelper.max(bounds.x0, boundingBox.x0); + bounds.z1 = MHelper.min(bounds.z1, boundingBox.z1); + bounds.z0 = MHelper.max(bounds.z0, boundingBox.z0); StructureHelper.erode(world, bounds, erosion, random); } if (cover) { @@ -89,7 +85,7 @@ public class NBTPiece extends BasePiece { } return true; } - + private void makeBoundingBox() { this.boundingBox = StructureHelper.getStructureBounds(pos, structure, rotation, mirror); } diff --git a/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java b/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java index b6c3c9c8..915c9126 100644 --- a/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/PaintedMountainPiece.java @@ -1,31 +1,28 @@ package ru.betterend.world.structures.piece; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.structure.StructureManager; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.Heightmap; -import net.minecraft.world.Heightmap.Type; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.StructureAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.registry.EndStructures; import ru.betterend.util.MHelper; public class PaintedMountainPiece extends MountainPiece { private BlockState[] slises; - - public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome, - BlockState[] slises) { + public PaintedMountainPiece(BlockPos center, float radius, float height, Random random, Biome biome, BlockState[] slises) { super(EndStructures.PAINTED_MOUNTAIN_PIECE, center, radius, height, random, biome); this.slises = slises; } @@ -35,11 +32,11 @@ public class PaintedMountainPiece extends MountainPiece { } @Override - protected void toNbt(CompoundTag tag) { - super.toNbt(tag); + protected void addAdditionalSaveData(CompoundTag tag) { + super.addAdditionalSaveData(tag); ListTag slise = new ListTag(); - for (BlockState state : slises) { - slise.add(NbtHelper.fromBlockState(state)); + for (BlockState state: slises) { + slise.add(NbtUtils.writeBlockState(state)); } tag.put("slises", slise); } @@ -50,19 +47,18 @@ public class PaintedMountainPiece extends MountainPiece { ListTag slise = tag.getList("slises", 10); slises = new BlockState[slise.size()]; for (int i = 0; i < slises.length; i++) { - slises[i] = NbtHelper.toBlockState(slise.getCompound(i)); + slises[i] = NbtUtils.readBlockState(slise.getCompound(i)); } } @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { - int sx = chunkPos.getStartX(); - int sz = chunkPos.getStartZ(); + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + int sx = chunkPos.getMinBlockX(); + int sz = chunkPos.getMinBlockZ(); MutableBlockPos pos = new MutableBlockPos(); - Chunk chunk = world.getChunk(chunkPos.x, chunkPos.z); - Heightmap map = chunk.getHeightmap(Type.WORLD_SURFACE); - Heightmap map2 = chunk.getHeightmap(Type.WORLD_SURFACE_WG); + ChunkAccess chunk = world.getChunk(chunkPos.x, chunkPos.z); + Heightmap map = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE); + Heightmap map2 = chunk.getOrCreateHeightmapUnprimed(Types.WORLD_SURFACE_WG); for (int x = 0; x < 16; x++) { int px = x + sx; int px2 = px - center.getX(); @@ -76,32 +72,31 @@ public class PaintedMountainPiece extends MountainPiece { if (dist < r2) { pos.setZ(z); dist = 1 - dist / r2; - int minY = map.get(x, z); + int minY = map.getFirstAvailable(x, z); pos.setY(minY - 1); while (chunk.getBlockState(pos).isAir() && pos.getY() > 50) { - pos.setY(minY--); + pos.setY(minY --); } minY = pos.getY(); - minY = Math.max(minY, map2.get(x, z)); + minY = Math.max(minY, map2.getFirstAvailable(x, z)); if (minY > center.getY() - 8) { float maxY = dist * height * getHeightClamp(world, 10, px, pz); if (maxY > 0) { maxY *= (float) noise1.eval(px * 0.05, pz * 0.05) * 0.3F + 0.7F; maxY *= (float) noise1.eval(px * 0.1, pz * 0.1) * 0.1F + 0.9F; maxY += center.getY(); - float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5 - + noise1.eval(px * 0.2, pz * 0.2) * 2 + 7); + float offset = (float) (noise1.eval(px * 0.07, pz * 0.07) * 5 + noise1.eval(px * 0.2, pz * 0.2) * 2 + 7); for (int y = minY - 1; y < maxY; y++) { pos.setY(y); int index = MHelper.floor((y + offset) * 0.65F) % slises.length; - chunk.setBlockAndUpdate(pos, slises[index], false); + chunk.setBlockState(pos, slises[index], false); } } } } } } - + return true; } } diff --git a/src/main/java/ru/betterend/world/structures/piece/VoxelPiece.java b/src/main/java/ru/betterend/world/structures/piece/VoxelPiece.java index a2be51f9..07276d85 100644 --- a/src/main/java/ru/betterend/world/structures/piece/VoxelPiece.java +++ b/src/main/java/ru/betterend/world/structures/piece/VoxelPiece.java @@ -2,21 +2,20 @@ package ru.betterend.world.structures.piece; import java.util.Random; import java.util.function.Consumer; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.structure.StructureManager; -import net.minecraft.util.math.BlockBox; import net.minecraft.core.BlockPos; -import net.minecraft.util.math.ChunkPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.StructureFeatureManager; import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; import ru.betterend.registry.EndStructures; import ru.betterend.world.structures.StructureWorld; public class VoxelPiece extends BasePiece { private StructureWorld world; - + public VoxelPiece(Consumer function, int id) { super(EndStructures.VOXEL_PIECE, id); world = new StructureWorld(); @@ -30,7 +29,7 @@ public class VoxelPiece extends BasePiece { } @Override - protected void toNbt(CompoundTag tag) { + protected void addAdditionalSaveData(CompoundTag tag) { tag.put("world", world.toBNT()); } @@ -40,8 +39,7 @@ public class VoxelPiece extends BasePiece { } @Override - public boolean place(WorldGenLevel world, StructureAccessor arg, ChunkGenerator chunkGenerator, Random random, - BlockBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { + public boolean postProcess(WorldGenLevel world, StructureFeatureManager arg, ChunkGenerator chunkGenerator, Random random, BoundingBox blockBox, ChunkPos chunkPos, BlockPos blockPos) { this.world.placeChunk(world, chunkPos); return true; } diff --git a/src/main/java/ru/betterend/world/surface/DoubleBlockSurfaceBuilder.java b/src/main/java/ru/betterend/world/surface/DoubleBlockSurfaceBuilder.java index 053d7798..b69dc71a 100644 --- a/src/main/java/ru/betterend/world/surface/DoubleBlockSurfaceBuilder.java +++ b/src/main/java/ru/betterend/world/surface/DoubleBlockSurfaceBuilder.java @@ -1,55 +1,51 @@ package ru.betterend.world.surface; import java.util.Random; - -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; -public class DoubleBlockSurfaceBuilder extends SurfaceBuilder { +public class DoubleBlockSurfaceBuilder extends SurfaceBuilder { private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141); - private TernarySurfaceConfig config1; - private TernarySurfaceConfig config2; - + private SurfaceBuilderBaseConfiguration config1; + private SurfaceBuilderBaseConfiguration config2; + private DoubleBlockSurfaceBuilder() { - super(TernarySurfaceConfig.CODEC); + super(SurfaceBuilderBaseConfiguration.CODEC); } - + public DoubleBlockSurfaceBuilder setBlock1(Block block) { BlockState stone = Blocks.END_STONE.defaultBlockState(); - config1 = new TernarySurfaceConfig(block.defaultBlockState(), stone, stone); + config1 = new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), stone, stone); return this; } - + public DoubleBlockSurfaceBuilder setBlock2(Block block) { BlockState stone = Blocks.END_STONE.defaultBlockState(); - config2 = new TernarySurfaceConfig(block.defaultBlockState(), stone, stone); + config2 = new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), stone, stone); return this; } @Override - public void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, - BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, - TernarySurfaceConfig surfaceBlocks) { + public void apply(Random random, ChunkAccess chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, SurfaceBuilderBaseConfiguration surfaceBlocks) { noise = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, random); - SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, - seed, noise > 0 ? config1 : config2); + SurfaceBuilder.DEFAULT.apply(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, noise > 0 ? config1 : config2); } - + public static DoubleBlockSurfaceBuilder register(String name) { return Registry.register(Registry.SURFACE_BUILDER, name, new DoubleBlockSurfaceBuilder()); } - - public ConfiguredSurfaceBuilder configured() { + + public ConfiguredSurfaceBuilder configured() { BlockState stone = Blocks.END_STONE.defaultBlockState(); - return this.withConfig(new TernarySurfaceConfig(config1.getTopMaterial(), stone, stone)); + return this.configured(new SurfaceBuilderBaseConfiguration(config1.getTopMaterial(), stone, stone)); } } \ No newline at end of file diff --git a/src/main/java/ru/betterend/world/surface/SulphuricSurfaceBuilder.java b/src/main/java/ru/betterend/world/surface/SulphuricSurfaceBuilder.java index bbe78a14..e9317b48 100644 --- a/src/main/java/ru/betterend/world/surface/SulphuricSurfaceBuilder.java +++ b/src/main/java/ru/betterend/world/surface/SulphuricSurfaceBuilder.java @@ -1,44 +1,39 @@ package ru.betterend.world.surface; import java.util.Random; - -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.util.MHelper; -public class SulphuricSurfaceBuilder extends SurfaceBuilder { +public class SulphuricSurfaceBuilder extends SurfaceBuilder { private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(5123); - + public SulphuricSurfaceBuilder() { - super(TernarySurfaceConfig.CODEC); + super(SurfaceBuilderBaseConfiguration.CODEC); } @Override - public void generate(Random random, Chunk chunk, Biome biome, int x, int z, int height, double noise, - BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, - TernarySurfaceConfig surfaceBlocks) { - double value = NOISE.eval(x * 0.03, z * 0.03) + NOISE.eval(x * 0.1, z * 0.1) * 0.3 - + MHelper.randRange(-0.1, 0.1, MHelper.RANDOM); + public void apply(Random random, ChunkAccess chunk, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, SurfaceBuilderBaseConfiguration surfaceBlocks) { + double value = NOISE.eval(x * 0.03, z * 0.03) + NOISE.eval(x * 0.1, z * 0.1) * 0.3 + MHelper.randRange(-0.1, 0.1, MHelper.RANDOM); if (value < -0.6) { - SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, - seaLevel, seed, SurfaceBuilders.DEFAULT_END_CONFIG); - } else if (value < -0.3) { - SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, - seaLevel, seed, SurfaceBuilders.FLAVOLITE_CONFIG); - } else if (value < 0.5) { - SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, - seaLevel, seed, SurfaceBuilders.SULFURIC_ROCK_CONFIG); - } else { - SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, - seaLevel, seed, SurfaceBuilders.BRIMSTONE_CONFIG); + SurfaceBuilder.DEFAULT.apply(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, SurfaceBuilders.DEFAULT_END_CONFIG); + } + else if (value < -0.3) { + SurfaceBuilder.DEFAULT.apply(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, SurfaceBuilders.FLAVOLITE_CONFIG); + } + else if (value < 0.5) { + SurfaceBuilder.DEFAULT.apply(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, SurfaceBuilders.SULFURIC_ROCK_CONFIG); + } + else { + SurfaceBuilder.DEFAULT.apply(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, SurfaceBuilders.BRIMSTONE_CONFIG); } } - + public static SulphuricSurfaceBuilder register(String name) { return Registry.register(Registry.SURFACE_BUILDER, name, new SulphuricSurfaceBuilder()); } diff --git a/src/main/java/ru/betterend/world/surface/SurfaceBuilders.java b/src/main/java/ru/betterend/world/surface/SurfaceBuilders.java index 2246f34a..b00b12ca 100644 --- a/src/main/java/ru/betterend/world/surface/SurfaceBuilders.java +++ b/src/main/java/ru/betterend/world/surface/SurfaceBuilders.java @@ -1,32 +1,29 @@ package ru.betterend.world.surface; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; import net.minecraft.core.Registry; -import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; -import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; import ru.betterend.registry.EndBlocks; public class SurfaceBuilders { - public static final TernarySurfaceConfig DEFAULT_END_CONFIG = makeSimpleConfig(Blocks.END_STONE); - public static final TernarySurfaceConfig FLAVOLITE_CONFIG = makeSimpleConfig(EndBlocks.FLAVOLITE.stone); - public static final TernarySurfaceConfig BRIMSTONE_CONFIG = makeSimpleConfig(EndBlocks.BRIMSTONE); - public static final TernarySurfaceConfig SULFURIC_ROCK_CONFIG = makeSimpleConfig(EndBlocks.SULPHURIC_ROCK.stone); - - public static final SurfaceBuilder SULPHURIC_SURFACE = register("sulphuric_surface", - new SulphuricSurfaceBuilder()); - - private static SurfaceBuilder register(String name, - SurfaceBuilder builder) { + public static final SurfaceBuilderBaseConfiguration DEFAULT_END_CONFIG = makeSimpleConfig(Blocks.END_STONE); + public static final SurfaceBuilderBaseConfiguration FLAVOLITE_CONFIG = makeSimpleConfig(EndBlocks.FLAVOLITE.stone); + public static final SurfaceBuilderBaseConfiguration BRIMSTONE_CONFIG = makeSimpleConfig(EndBlocks.BRIMSTONE); + public static final SurfaceBuilderBaseConfiguration SULFURIC_ROCK_CONFIG = makeSimpleConfig(EndBlocks.SULPHURIC_ROCK.stone); + + public static final SurfaceBuilder SULPHURIC_SURFACE = register("sulphuric_surface", new SulphuricSurfaceBuilder()); + + private static SurfaceBuilder register(String name, SurfaceBuilder builder) { return Registry.register(Registry.SURFACE_BUILDER, name, builder); } - - private static TernarySurfaceConfig makeSimpleConfig(Block block) { + + private static SurfaceBuilderBaseConfiguration makeSimpleConfig(Block block) { BlockState state = block.defaultBlockState(); - return new TernarySurfaceConfig(state, state, state); - } - - public static void register() { + return new SurfaceBuilderBaseConfiguration(state, state, state); } + + public static void register() {} }