Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '0.6-SNAPSHOT' id 'fabric-loom' version '0.7-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

@ -39,7 +39,6 @@ import ru.betterend.world.surface.SurfaceBuilders;
public class BetterEnd implements ModInitializer { public class BetterEnd implements ModInitializer {
public static final String MOD_ID = "betterend"; public static final String MOD_ID = "betterend";
public static final Logger LOGGER = Logger.get(); public static final Logger LOGGER = Logger.get();
@Override @Override
public void onInitialize() { public void onInitialize() {
EndPortals.loadPortals(); EndPortals.loadPortals();
@ -67,41 +66,40 @@ public class BetterEnd implements ModInitializer {
GeneratorOptions.init(); GeneratorOptions.init();
DataFixerUtil.init(); DataFixerUtil.init();
LootTableUtil.init(); LootTableUtil.init();
if (hasGuideBook()) { if (hasGuideBook()) {
GuideBookItem.register(); GuideBookItem.register();
} }
FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class) FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class).forEach(BetterEndPlugin::register);
.forEach(BetterEndPlugin::register);
Configs.saveConfigs(); Configs.saveConfigs();
if (hasGuideBook()) { 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"); ResourceLocation advId = new ResourceLocation("minecraft:end/enter_end_gateway");
if (advId.equals(advancement.getId())) { if (advId.equals(advancement.getId())) {
player.giveItemStack(new ItemStack(GuideBookItem.GUIDE_BOOK)); player.addItem(new ItemStack(GuideBookItem.GUIDE_BOOK));
} }
}); });
} }
} }
public static boolean hasGuideBook() { public static boolean hasGuideBook() {
return FabricLoader.getInstance().isModLoaded("patchouli"); return FabricLoader.getInstance().isModLoaded("patchouli");
} }
public static ResourceLocation makeID(String path) { public static ResourceLocation makeID(String path) {
return new ResourceLocation(MOD_ID, path); return new ResourceLocation(MOD_ID, path);
} }
public static String getStringId(String id) { public static String getStringId(String id) {
return String.format("%s:%s", MOD_ID, id); return String.format("%s:%s", MOD_ID, id);
} }
public static boolean isDevEnvironment() { public static boolean isDevEnvironment() {
return FabricLoader.getInstance().isDevelopmentEnvironment(); return FabricLoader.getInstance().isDevelopmentEnvironment();
} }
public static boolean isClient() { public static boolean isClient() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
} }

View file

@ -1,10 +1,10 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.blocks.basis.EndAnvilBlock;
import ru.betterend.item.material.EndToolMaterial; import ru.betterend.item.material.EndToolMaterial;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
@ -12,11 +12,11 @@ import ru.betterend.registry.EndBlocks;
public class AeterniumAnvil extends EndAnvilBlock { public class AeterniumAnvil extends EndAnvilBlock {
private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION_LONG; private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION_LONG;
public AeterniumAnvil() { public AeterniumAnvil() {
super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel()); super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel());
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(DESTRUCTION); builder.add(DESTRUCTION);
@ -24,7 +24,7 @@ public class AeterniumAnvil extends EndAnvilBlock {
} }
@Override @Override
public IntegerProperty getDESTRUCTION() { public IntegerProperty getDestructionProperty() {
return DESTRUCTION; return DESTRUCTION;
} }

View file

@ -5,17 +5,20 @@ import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; 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.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.SoundType;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class AeterniumBlock extends BlockBase { public class AeterniumBlock extends BlockBase {
public AeterniumBlock() { public AeterniumBlock() {
super(FabricBlockSettings.of(Material.METAL, MaterialColor.COLOR_GRAY).hardness(65F).resistance(1200F) super(FabricBlockSettings.of(Material.METAL, MaterialColor.COLOR_GRAY)
.requiresTool().sounds(SoundType.NETHERITE_BLOCK)); .hardness(65F)
.resistance(1200F)
.requiresCorrectToolForDrops()
.sound(SoundType.NETHERITE_BLOCK));
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)

View file

@ -2,12 +2,12 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class AmaranitaCapBlock extends BlockBase { public class AmaranitaCapBlock extends BlockBase {
public AmaranitaCapBlock() { public AmaranitaCapBlock() {
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WOOD)); super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sound(SoundType.WOOD));
} }
} }

View file

@ -2,15 +2,15 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
public class AmaranitaHymenophoreBlock extends BlockBase implements IRenderTypeable { public class AmaranitaHymenophoreBlock extends BlockBase implements IRenderTypeable {
public AmaranitaHymenophoreBlock() { 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 @Override

View file

@ -3,11 +3,11 @@ package ru.betterend.blocks;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
@ -16,13 +16,13 @@ import ru.betterend.util.MHelper;
public class AncientEmeraldIceBlock extends BlockBase { public class AncientEmeraldIceBlock extends BlockBase {
public AncientEmeraldIceBlock() { public AncientEmeraldIceBlock() {
super(FabricBlockSettings.copyOf(Blocks.BLUE_ICE).ticksRandomly()); super(FabricBlockSettings.copyOf(Blocks.BLUE_ICE).randomTicks());
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
Direction dir = BlocksHelper.randomDirection(random); Direction dir = BlocksHelper.randomDirection(random);
if (random.nextBoolean()) { if (random.nextBoolean()) {
int x = MHelper.randRange(-2, 2, random); int x = MHelper.randRange(-2, 2, random);
int y = 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); makeParticles(world, p, random);
} }
} }
pos = pos.relative(dir); pos = pos.relative(dir);
state = world.getBlockState(pos); state = world.getBlockState(pos);
if (state.is(Blocks.WATER)) { if (state.is(Blocks.WATER)) {
world.setBlockAndUpdate(pos, EndBlocks.EMERALD_ICE.defaultBlockState()); world.setBlockAndUpdate(pos, EndBlocks.EMERALD_ICE.defaultBlockState());
makeParticles(world, pos, random); 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()); world.setBlockAndUpdate(pos, EndBlocks.DENSE_EMERALD_ICE.defaultBlockState());
makeParticles(world, pos, random); makeParticles(world, pos, random);
} }
} }
private void makeParticles(ServerLevel world, BlockPos pos, Random 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, world.sendParticles(EndParticles.SNOWFLAKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 20, 0.5, 0.5, 0.5, 0);
0.5, 0);
} }
} }

View file

@ -5,39 +5,47 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.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.core.Vec3i;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.AbstractGlassBlock; 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.block.state.BlockState;
import net.minecraft.world.level.material.Material; 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.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; 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.client.render.ERenderLayer;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
import ru.betterend.registry.EndTags;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTypeable, IColorProvider { public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTypeable, IColorProvider {
public static final Vec3i[] COLORS; public static final Vec3i[] COLORS;
private static final int MIN_DROP = 1; private static final int MIN_DROP = 1;
private static final int MAX_DROP = 4; private static final int MAX_DROP = 4;
public AuroraCrystalBlock() { public AuroraCrystalBlock() {
super(FabricBlockSettings.of(Material.GLASS).breakByTool(FabricToolTags.PICKAXES) super(FabricBlockSettings.of(Material.GLASS)
.suffocates((state, world, pos) -> false).hardness(1F).resistance(1F).sounds(SoundType.GLASS) .breakByTool(FabricToolTags.PICKAXES)
.luminance(15).nonOpaque()); .breakByTool(EndTags.HAMMERS)
.hardness(1F)
.resistance(1F)
.luminance(15)
.noOcclusion()
.isSuffocating((state, world, pos) -> false)
.sound(SoundType.GLASS));
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ(); long i = (long) pos.getX() + (long) pos.getY() + (long) pos.getZ();
double delta = i * 0.1; double delta = i * 0.1;
@ -45,28 +53,30 @@ public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTyp
int index2 = (index + 1) & 3; int index2 = (index + 1) & 3;
delta -= index; delta -= index;
index &= 3; index &= 3;
Vec3i color1 = COLORS[index]; Vec3i color1 = COLORS[index];
Vec3i color2 = COLORS[index2]; Vec3i color2 = COLORS[index2];
int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX()));
int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY()));
int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ()));
return MHelper.color(r, g, b); return MHelper.color(r, g, b);
}; };
} }
@Override @Override
public ItemColor getItemProvider() { 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 @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -91,9 +101,13 @@ public class AuroraCrystalBlock extends AbstractGlassBlock implements IRenderTyp
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
static { static {
COLORS = new Vec3i[] { new Vec3i(247, 77, 161), new Vec3i(120, 184, 255), new Vec3i(120, 255, 168), COLORS = new Vec3i[] {
new Vec3i(243, 58, 255) }; new Vec3i(247, 77, 161),
new Vec3i(120, 184, 255),
new Vec3i(120, 255, 168),
new Vec3i(243, 58, 255)
};
} }
} }

View file

@ -1,146 +1,163 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.StringRepresentable;
import net.minecraft.state.property.EnumProperty; 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.world.level.block.state.properties.IntegerProperty;
import net.minecraft.util.StringIdentifiable;
import ru.betterend.registry.EndPortals; import ru.betterend.registry.EndPortals;
public class BlockProperties { public class BlockProperties {
public static final EnumProperty<HydraluxShape> HYDRALUX_SHAPE = EnumProperty.of("shape", HydraluxShape.class); public static final EnumProperty<HydraluxShape> HYDRALUX_SHAPE = EnumProperty.create("shape", HydraluxShape.class);
public final static EnumProperty<PedestalState> PEDESTAL_STATE = EnumProperty.of("state", PedestalState.class); public final static EnumProperty<PedestalState> PEDESTAL_STATE = EnumProperty.create("state", PedestalState.class);
public static final EnumProperty<TripleShape> TRIPLE_SHAPE = EnumProperty.of("shape", TripleShape.class); public static final EnumProperty<TripleShape> TRIPLE_SHAPE = EnumProperty.create("shape", TripleShape.class);
public static final EnumProperty<PentaShape> PENTA_SHAPE = EnumProperty.of("shape", PentaShape.class); public static final EnumProperty<PentaShape> PENTA_SHAPE = EnumProperty.create("shape", PentaShape.class);
public static final BooleanProperty TRANSITION = BooleanProperty.of("transition"); public static final BooleanProperty TRANSITION = BooleanProperty.create("transition");
public static final BooleanProperty HAS_LIGHT = BooleanProperty.of("has_light"); public static final BooleanProperty HAS_LIGHT = BooleanProperty.create("has_light");
public static final BooleanProperty HAS_ITEM = BooleanProperty.of("has_item"); public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item");
public static final BooleanProperty IS_FLOOR = BooleanProperty.of("is_floor"); public static final BooleanProperty IS_FLOOR = BooleanProperty.create("is_floor");
public static final BooleanProperty NATURAL = BooleanProperty.of("natural"); public static final BooleanProperty NATURAL = BooleanProperty.create("natural");
public static final BooleanProperty ACTIVE = BooleanProperty.of("active"); public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
public static final BooleanProperty SMALL = BooleanProperty.of("small"); public static final BooleanProperty SMALL = BooleanProperty.create("small");
public static final IntegerProperty DESTRUCTION_LONG = IntegerProperty.of("destruction", 0, 8); public static final IntegerProperty DESTRUCTION_LONG = IntegerProperty.create("destruction", 0, 8);
public static final IntegerProperty DESTRUCTION = IntegerProperty.of("destruction", 0, 2); public static final IntegerProperty DESTRUCTION = IntegerProperty.create("destruction", 0, 2);
public static final IntegerProperty ROTATION = IntegerProperty.of("rotation", 0, 3); public static final IntegerProperty ROTATION = IntegerProperty.create("rotation", 0, 3);
public static final IntegerProperty FULLNESS = IntegerProperty.of("fullness", 0, 3); public static final IntegerProperty FULLNESS = IntegerProperty.create("fullness", 0, 3);
public static final IntegerProperty COLOR = IntegerProperty.of("color", 0, 7); public static final IntegerProperty COLOR = IntegerProperty.create("color", 0, 7);
public static final IntegerProperty PORTAL = IntegerProperty.of("portal", 0, EndPortals.getCount()); public static final IntegerProperty PORTAL = IntegerProperty.create("portal", 0, EndPortals.getCount());
public static final IntegerProperty SIZE = IntegerProperty.of("size", 0, 7); public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7);
public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 3); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
public static enum TripleShape implements StringIdentifiable { public static enum TripleShape implements StringRepresentable {
TOP("top"), MIDDLE("middle"), BOTTOM("bottom"); TOP("top"),
MIDDLE("middle"),
BOTTOM("bottom");
private final String name; private final String name;
TripleShape(String name) { TripleShape(String name) {
this.name = name; this.name = name;
} }
@Override @Override
public String asString() { public String getSerializedName() {
return name; return name;
} }
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
} }
public static enum PedestalState implements StringIdentifiable { public static enum PedestalState implements StringRepresentable {
PEDESTAL_TOP("pedestal_top"), COLUMN_TOP("column_top"), BOTTOM("bottom"), PILLAR("pillar"), COLUMN("column"), PEDESTAL_TOP("pedestal_top"),
COLUMN_TOP("column_top"),
BOTTOM("bottom"),
PILLAR("pillar"),
COLUMN("column"),
DEFAULT("default"); DEFAULT("default");
private final String name; private final String name;
PedestalState(String name) { PedestalState(String name) {
this.name = name; this.name = name;
} }
@Override @Override
public String asString() { public String getSerializedName() {
return this.name; return this.name;
} }
@Override @Override
public String toString() { public String toString() {
return this.name; return this.name;
} }
} }
public static enum HydraluxShape implements StringIdentifiable { public static enum HydraluxShape implements StringRepresentable {
FLOWER_BIG_BOTTOM("flower_big_bottom", true), FLOWER_BIG_TOP("flower_big_top", true), FLOWER_BIG_BOTTOM("flower_big_bottom", true),
FLOWER_SMALL_BOTTOM("flower_small_bottom", true), FLOWER_SMALL_TOP("flower_small_top", true), FLOWER_BIG_TOP("flower_big_top", true),
VINE("vine", false), ROOTS("roots", false); 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 String name;
private final boolean glow; private final boolean glow;
HydraluxShape(String name, boolean glow) { HydraluxShape(String name, boolean glow) {
this.name = name; this.name = name;
this.glow = glow; this.glow = glow;
} }
@Override @Override
public String asString() { public String getSerializedName() {
return name; return name;
} }
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
public boolean hasGlow() { public boolean hasGlow() {
return glow; return glow;
} }
} }
public static enum PentaShape implements StringIdentifiable { public static enum PentaShape implements StringRepresentable {
BOTTOM("bottom"), PRE_BOTTOM("pre_bottom"), MIDDLE("middle"), PRE_TOP("pre_top"), TOP("top"); BOTTOM("bottom"),
PRE_BOTTOM("pre_bottom"),
MIDDLE("middle"),
PRE_TOP("pre_top"),
TOP("top");
private final String name; private final String name;
PentaShape(String name) { PentaShape(String name) {
this.name = name; this.name = name;
} }
@Override @Override
public String asString() { public String getSerializedName() {
return name; return name;
} }
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
} }
public static enum LumecornShape implements StringIdentifiable { public static enum LumecornShape implements StringRepresentable {
LIGHT_TOP("light_top", 15), LIGHT_TOP_MIDDLE("light_top_middle", 15), LIGHT_MIDDLE("light_middle", 15), LIGHT_TOP("light_top", 15),
LIGHT_BOTTOM("light_bottom", 15), MIDDLE("middle", 0), BOTTOM_BIG("bottom_big", 0), 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); BOTTOM_SMALL("bottom_small", 0);
private final String name; private final String name;
private final int light; private final int light;
LumecornShape(String name, int light) { LumecornShape(String name, int light) {
this.name = name; this.name = name;
this.light = light; this.light = light;
} }
@Override @Override
public String asString() { public String getSerializedName() {
return name; return name;
} }
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
public int getLight() { public int getLight() {
return light; return light;
} }

View file

@ -1,10 +1,13 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.SoundType;
public class BlockSounds { public class BlockSounds {
public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, SoundEvents.BLOCK_STONE_BREAK, public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F,
SoundEvents.BLOCK_WART_BLOCK_STEP, SoundEvents.BLOCK_STONE_PLACE, SoundEvents.BLOCK_STONE_HIT, SoundEvents.STONE_BREAK,
SoundEvents.BLOCK_STONE_FALL); SoundEvents.WART_BLOCK_STEP,
SoundEvents.STONE_PLACE,
SoundEvents.STONE_HIT,
SoundEvents.STONE_FALL);
} }

View file

@ -3,19 +3,19 @@ package ru.betterend.blocks;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.UpDownPlantBlock; import ru.betterend.blocks.basis.UpDownPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class BlueVineBlock extends UpDownPlantBlock { public class BlueVineBlock extends UpDownPlantBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM; return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM;

View file

@ -2,44 +2,43 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class BlueVineLanternBlock extends BlockBase { public class BlueVineLanternBlock extends BlockBase {
public static final BooleanProperty NATURAL = BlockProperties.NATURAL; public static final BooleanProperty NATURAL = BlockProperties.NATURAL;
public BlueVineLanternBlock() { public BlueVineLanternBlock() {
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WART_BLOCK) super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WART_BLOCK));
.luminance(15)); this.registerDefaultState(this.stateDefinition.any().setValue(NATURAL, false));
this.setDefaultState(this.stateManager.defaultBlockState().with(NATURAL, false));
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return state.getValue(NATURAL) ? world.getBlockState(pos.below()).getBlock() == EndBlocks.BLUE_VINE : true; return !state.getValue(NATURAL) || world.getBlockState(pos.below()).getBlock() == EndBlocks.BLUE_VINE;
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} else { }
else {
return state; return state;
} }
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(NATURAL); stateManager.add(NATURAL);

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.blocks.basis.FurBlock; import ru.betterend.blocks.basis.FurBlock;
@ -22,40 +21,34 @@ public class BlueVineSeedBlock extends EndPlantWithAgeBlock {
if (h < height + 1) { if (h < height + 1) {
return; return;
} }
BlocksHelper.setWithoutUpdate(world, pos, BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
for (int i = 1; i < height; i++) { for (int i = 1; i < height; i++) {
BlocksHelper.setWithoutUpdate(world, pos.up(i), BlocksHelper.setWithoutUpdate(world, pos.above(i), EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE));
EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE));
} }
BlocksHelper.setWithoutUpdate(world, pos.up(height), BlocksHelper.setWithoutUpdate(world, pos.above(height), EndBlocks.BLUE_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP));
EndBlocks.BLUE_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)); placeLantern(world, pos.above(height + 1));
placeLantern(world, pos.up(height + 1));
} }
private void placeLantern(WorldGenLevel world, BlockPos pos) { private void placeLantern(WorldGenLevel world, BlockPos pos) {
BlocksHelper.setWithoutUpdate(world, pos, BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BLUE_VINE_LANTERN.defaultBlockState().setValue(BlueVineLanternBlock.NATURAL, true));
EndBlocks.BLUE_VINE_LANTERN.defaultBlockState().with(BlueVineLanternBlock.NATURAL, true)); for (Direction dir: BlocksHelper.HORIZONTAL) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos p = pos.relative(dir); BlockPos p = pos.relative(dir);
if (world.isAir(p)) { if (world.isEmptyBlock(p)) {
BlocksHelper.setWithoutUpdate(world, p, BlocksHelper.setWithoutUpdate(world, p, EndBlocks.BLUE_VINE_FUR.defaultBlockState().setValue(FurBlock.FACING, dir));
EndBlocks.BLUE_VINE_FUR.defaultBlockState().with(FurBlock.FACING, dir));
} }
} }
if (world.isAir(pos.up())) { if (world.isEmptyBlock(pos.above())) {
BlocksHelper.setWithoutUpdate(world, pos.up(), BlocksHelper.setWithoutUpdate(world, pos.above(), EndBlocks.BLUE_VINE_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.UP));
EndBlocks.BLUE_VINE_FUR.defaultBlockState().with(FurBlock.FACING, Direction.UP));
} }
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM); return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM);
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
} }

View file

@ -2,54 +2,52 @@ package ru.betterend.blocks;
import java.util.List; import java.util.List;
import java.util.Random; 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.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.BlockGetter;
import net.minecraft.world.level.Level; 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.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class BoluxMushroomBlock extends EndPlantBlock { 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() { public BoluxMushroomBlock() {
super(10); super(10);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.RUTISCUS); return state.is(EndBlocks.RUTISCUS);
} }
@Override @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; return SHAPE;
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));

View file

@ -5,52 +5,51 @@ import java.util.Random;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.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.BlockPos;
import net.minecraft.core.Direction; 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.Level;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class BrimstoneBlock extends BlockBase { public class BrimstoneBlock extends BlockBase {
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE;
public BrimstoneBlock() { public BrimstoneBlock() {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(MaterialColor.COLOR_BROWN).ticksRandomly()); super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(MaterialColor.COLOR_BROWN).randomTicks());
setDefaultState(stateManager.defaultBlockState().with(ACTIVATED, false)); registerDefaultState(stateDefinition.any().setValue(ACTIVATED, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(ACTIVATED); stateManager.add(ACTIVATED);
} }
@Override @Override
public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
ItemStack itemStack) {
if (world.isClientSide()) { if (world.isClientSide()) {
updateChunks((ClientLevel) world, pos); 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()) { if (world.isClientSide()) {
updateChunks((ClientLevel) world, pos); updateChunks((ClientLevel) world, pos);
} }
} }
private void updateChunks(ClientLevel world, BlockPos pos) { private void updateChunks(ClientLevel world, BlockPos pos) {
int y = pos.getY() >> 4; int y = pos.getY() >> 4;
int x1 = (pos.getX() - 2) >> 4; int x1 = (pos.getX() - 2) >> 4;
@ -59,41 +58,45 @@ public class BrimstoneBlock extends BlockBase {
int z2 = (pos.getZ() + 2) >> 4; int z2 = (pos.getZ() + 2) >> 4;
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) { for (int z = z1; z <= z2; z++) {
world.scheduleBlockRenders(x, y, z); world.setSectionDirtyWithNeighbors(x, y, z);
} }
} }
} }
@Override @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; boolean deactivate = true;
for (Direction dir : BlocksHelper.DIRECTIONS) { for (Direction dir: BlocksHelper.DIRECTIONS) {
if (world.getFluidState(pos.relative(dir)).getFluid().equals(Fluids.WATER)) { if (world.getFluidState(pos.relative(dir)).getType().equals(Fluids.WATER)) {
deactivate = false; deactivate = false;
break; break;
} }
} }
if (state.getValue(ACTIVATED)) { if (state.getValue(ACTIVATED)) {
if (deactivate) { if (deactivate) {
world.setBlockAndUpdate(pos, getDefaultState().with(ACTIVATED, false)); world.setBlockAndUpdate(pos, defaultBlockState().setValue(ACTIVATED, false));
} else if (state.getValue(ACTIVATED) && random.nextInt(16) == 0) { }
else if (state.getValue(ACTIVATED) && random.nextInt(16) == 0) {
Direction dir = BlocksHelper.randomDirection(random); Direction dir = BlocksHelper.randomDirection(random);
BlockPos side = pos.relative(dir); BlockPos side = pos.relative(dir);
BlockState sideState = world.getBlockState(side); BlockState sideState = world.getBlockState(side);
if (sideState.getBlock() instanceof SulphurCrystalBlock) { if (sideState.getBlock() instanceof SulphurCrystalBlock) {
if (sideState.get(SulphurCrystalBlock.AGE) < 2 && sideState.get(SulphurCrystalBlock.WATERLOGGED)) { if (sideState.getValue(SulphurCrystalBlock.AGE) < 2 && sideState.getValue(SulphurCrystalBlock.WATERLOGGED)) {
int age = sideState.get(SulphurCrystalBlock.AGE) + 1; int age = sideState.getValue(SulphurCrystalBlock.AGE) + 1;
world.setBlockAndUpdate(side, sideState.with(SulphurCrystalBlock.AGE, age)); 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() BlockState crystal = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState()
.with(SulphurCrystalBlock.FACING, dir).with(SulphurCrystalBlock.WATERLOGGED, true) .setValue(SulphurCrystalBlock.FACING, dir)
.with(SulphurCrystalBlock.AGE, 0); .setValue(SulphurCrystalBlock.WATERLOGGED, true)
.setValue(SulphurCrystalBlock.AGE, 0);
world.setBlockAndUpdate(side, crystal); 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));
} }
} }
} }

View file

@ -6,30 +6,33 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.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.BlockGetter;
import net.minecraft.world.level.Level; 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; import ru.betterend.blocks.basis.UnderwaterPlantBlock;
public class BubbleCoralBlock extends 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() { public BubbleCoralBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) super(FabricBlockSettings.of(Material.WATER_PLANT)
.sounds(SoundType.CORAL).breakByHand(true).noCollision()); .breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.CORAL_BLOCK)
.noCollission());
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@ -39,19 +42,19 @@ public class BubbleCoralBlock extends UnderwaterPlantBlock {
double z = pos.getZ() + random.nextDouble(); double z = pos.getZ() + random.nextDouble();
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D); world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0.0D, 0.0D, 0.0D);
} }
@Override @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; return SHAPE;
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
} }

View file

@ -1,15 +1,13 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.List; 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.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.VineBlock; import ru.betterend.blocks.basis.VineBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -20,27 +18,28 @@ public class BulbVineBlock extends VineBlock {
public BulbVineBlock() { public BulbVineBlock() {
super(15, true); super(15, true);
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(SHAPE) == TripleShape.BOTTOM) { if (state.getValue(SHAPE) == TripleShape.BOTTOM) {
return Lists.newArrayList(new ItemStack(EndItems.GLOWING_BULB)); 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)); return Lists.newArrayList(new ItemStack(EndBlocks.BULB_VINE_SEED));
} else { }
else {
return Lists.newArrayList(); return Lists.newArrayList();
} }
} }
@Override @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; return false;
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
boolean canPlace = super.canPlaceAt(state, world, pos); boolean canPlace = super.canSurvive(state, world, pos);
return (state.is(this) && state.getValue(SHAPE) == TripleShape.BOTTOM) ? canPlace return (state.is(this) && state.getValue(SHAPE) == TripleShape.BOTTOM) ? canPlace : canPlace && world.getBlockState(pos.below()).is(this);
: canPlace && world.getBlockState(pos.below()).is(this);
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.ShapeContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.phys.shapes.VoxelShape;
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 ru.betterend.blocks.basis.EndLanternBlock; import ru.betterend.blocks.basis.EndLanternBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -25,21 +25,26 @@ import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class BulbVineLanternBlock extends EndLanternBlock implements IRenderTypeable, BlockPatterned { 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_CEIL = Block.box(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_FLOOR = Block.box(4, 0, 4, 12, 12, 12);
public BulbVineLanternBlock() { public BulbVineLanternBlock() {
this(FabricBlockSettings.of(Material.METAL).sounds(SoundType.LANTERN).hardness(1).resistance(1) this(FabricBlockSettings.of(Material.METAL)
.breakByTool(FabricToolTags.PICKAXES).materialColor(MaterialColor.LIGHT_GRAY).requiresTool() .hardness(1)
.luminance(15)); .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); super(settings);
} }
@Override @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; return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL;
} }
@ -47,13 +52,13 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
@ -62,21 +67,22 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
map.put("%metal%", getMetalTexture(blockId)); map.put("%metal%", getMetalTexture(blockId));
if (block.contains("item") || block.contains("ceil")) { if (block.contains("item") || block.contains("ceil")) {
return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, map); return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, map);
} else { }
else {
return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, map); return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, map);
} }
} }
protected String getMetalTexture(ResourceLocation blockId) { protected String getMetalTexture(ResourceLocation blockId) {
String name = blockId.getPath(); String name = blockId.getPath();
name = name.substring(0, name.indexOf('_')); name = name.substring(0, name.indexOf('_'));
return name + "_bulb_vine_lantern_metal"; return name + "_bulb_vine_lantern_metal";
} }
protected String getGlowTexture() { protected String getGlowTexture() {
return "bulb_vine_lantern_bulb"; return "bulb_vine_lantern_bulb";
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_BULB_LANTERN; return Patterns.STATE_BULB_LANTERN;

View file

@ -13,7 +13,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
return getColor(); return getColor();
}; };
@ -25,7 +25,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements
return getColor(); return getColor();
}; };
} }
private int getColor() { private int getColor() {
int color = BlocksHelper.getBlockColor(this); int color = BlocksHelper.getBlockColor(this);
int b = (color & 255); int b = (color & 255);
@ -34,7 +34,7 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements
float[] hsv = MHelper.fromRGBtoHSB(r, g, b); float[] hsv = MHelper.fromRGBtoHSB(r, g, b);
return MHelper.fromHSBtoRGB(hsv[0], hsv[1], hsv[1] > 0.2 ? 1 : hsv[2]); return MHelper.fromHSBtoRGB(hsv[0], hsv[1], hsv[1] > 0.2 ? 1 : hsv[2]);
} }
@Override @Override
protected String getGlowTexture() { protected String getGlowTexture() {
return "bulb_vine_lantern_overlay"; return "bulb_vine_lantern_overlay";

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -15,23 +14,20 @@ import ru.betterend.util.BlocksHelper;
public class BulbVineSeedBlock extends EndPlantWithAgeBlock { public class BulbVineSeedBlock extends EndPlantWithAgeBlock {
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState up = world.getBlockState(pos.up()); BlockState up = world.getBlockState(pos.above());
return up.isIn(EndTags.GEN_TERRAIN) || up.isIn(BlockTags.LOGS) || up.isIn(BlockTags.LEAVES); return up.is(EndTags.GEN_TERRAIN) || up.is(BlockTags.LOGS) || up.is(BlockTags.LEAVES);
} }
@Override @Override
public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { public void growAdult(WorldGenLevel world, Random random, BlockPos pos) {
int h = BlocksHelper.downRay(world, pos, random.nextInt(24)) - 1; int h = BlocksHelper.downRay(world, pos, random.nextInt(24)) - 1;
if (h > 2) { if (h > 2) {
BlocksHelper.setWithoutUpdate(world, pos, BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP));
EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP));
for (int i = 1; i < h; i++) { for (int i = 1; i < h; i++) {
BlocksHelper.setWithoutUpdate(world, pos.down(i), BlocksHelper.setWithoutUpdate(world, pos.below(i), EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE));
EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE));
} }
BlocksHelper.setWithoutUpdate(world, pos.down(h), BlocksHelper.setWithoutUpdate(world, pos.below(h), EndBlocks.BULB_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
EndBlocks.BULB_VINE.defaultBlockState().with(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
} }
} }
} }

View file

@ -4,18 +4,18 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.core.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.level.BlockGetter; 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.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -25,42 +25,41 @@ public class CavePumpkinBlock extends BlockBaseNotFull implements IRenderTypeabl
public static final BooleanProperty SMALL = BlockProperties.SMALL; public static final BooleanProperty SMALL = BlockProperties.SMALL;
private static final VoxelShape SHAPE_SMALL; private static final VoxelShape SHAPE_SMALL;
private static final VoxelShape SHAPE_BIG; private static final VoxelShape SHAPE_BIG;
public CavePumpkinBlock() { public CavePumpkinBlock() {
super(FabricBlockSettings.copyOf(Blocks.PUMPKIN).luminance((state) -> state.getValue(SMALL) ? 10 : 15)); super(FabricBlockSettings.copyOf(Blocks.PUMPKIN).lightLevel((state) -> state.getValue(SMALL) ? 10 : 15));
setDefaultState(getDefaultState().with(SMALL, false)); registerDefaultState(defaultBlockState().setValue(SMALL, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SMALL); stateManager.add(SMALL);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @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; return state.getValue(SMALL) ? SHAPE_SMALL : SHAPE_BIG;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return state.getValue(SMALL) ? Collections.singletonList(new ItemStack(EndBlocks.CAVE_PUMPKIN_SEED)) return state.getValue(SMALL) ? Collections.singletonList(new ItemStack(EndBlocks.CAVE_PUMPKIN_SEED)) : Collections.singletonList(new ItemStack(this));
: Collections.singletonList(new ItemStack(this));
} }
static { static {
VoxelShape lantern = Block.createCuboidShape(1, 0, 1, 15, 13, 15); VoxelShape lantern = Block.box(1, 0, 1, 15, 13, 15);
VoxelShape cap = Block.createCuboidShape(0, 12, 0, 16, 15, 16); VoxelShape cap = Block.box(0, 12, 0, 16, 15, 16);
VoxelShape top = Block.createCuboidShape(5, 15, 5, 11, 16, 11); VoxelShape top = Block.box(5, 15, 5, 11, 16, 11);
SHAPE_BIG = VoxelShapes.union(lantern, cap, top); SHAPE_BIG = Shapes.or(lantern, cap, top);
lantern = Block.createCuboidShape(1, 7, 1, 15, 13, 15); lantern = Block.box(1, 7, 1, 15, 13, 15);
cap = Block.createCuboidShape(4, 12, 4, 12, 15, 12); cap = Block.box(4, 12, 4, 12, 15, 12);
top = Block.createCuboidShape(6, 15, 6, 10, 16, 10); top = Block.box(6, 15, 6, 10, 16, 10);
SHAPE_SMALL = VoxelShapes.union(lantern, cap, top); SHAPE_SMALL = Shapes.or(lantern, cap, top);
} }
} }

View file

@ -1,73 +1,69 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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.BlockPos;
import net.minecraft.core.Direction; 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.BlockGetter;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class CavePumpkinVineBlock extends EndPlantWithAgeBlock { 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 @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.up()); BlockState down = world.getBlockState(pos.above());
return isTerrain(down); return isTerrain(down);
} }
@Override @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); int age = state.getValue(AGE);
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
if (down.getMaterial().isReplaceable() if (down.getMaterial().isReplaceable() || (down.is(EndBlocks.CAVE_PUMPKIN) && down.getValue(BlockProperties.SMALL))) {
|| (down.is(EndBlocks.CAVE_PUMPKIN) && down.get(BlockProperties.SMALL))) {
if (age < 3) { if (age < 3) {
world.setBlockAndUpdate(pos, state.with(AGE, age + 1)); world.setBlockAndUpdate(pos, state.setValue(AGE, age + 1));
} }
if (age == 2) { if (age == 2) {
world.setBlockAndUpdate(pos.below(), world.setBlockAndUpdate(pos.below(), EndBlocks.CAVE_PUMPKIN.defaultBlockState().setValue(BlockProperties.SMALL, true));
EndBlocks.CAVE_PUMPKIN.defaultBlockState().with(BlockProperties.SMALL, true)); }
} else if (age == 3) { else if (age == 3) {
world.setBlockAndUpdate(pos.below(), EndBlocks.CAVE_PUMPKIN.defaultBlockState()); world.setBlockAndUpdate(pos.below(), EndBlocks.CAVE_PUMPKIN.defaultBlockState());
} }
} }
} }
@Override @Override
public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { public void growAdult(WorldGenLevel world, Random random, BlockPos pos) {}
}
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) {
state = super.updateShape(state, facing, neighborState, world, pos, neighborPos); state = super.updateShape(state, facing, neighborState, world, pos, neighborPos);
if (state.is(this) && state.getValue(BlockProperties.AGE) > 1) { if (state.is(this) && state.getValue(BlockProperties.AGE) > 1) {
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
if (!down.is(EndBlocks.CAVE_PUMPKIN)) { if (!down.is(EndBlocks.CAVE_PUMPKIN)) {
state = state.with(BlockProperties.AGE, 1); state = state.setValue(BlockProperties.AGE, 1);
} }
} }
return state; return state;
} }
@Override @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; return SHAPE;
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
} }

View file

@ -6,16 +6,16 @@ import java.util.EnumMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.level.BlockGetter; 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.blocks.basis.AttachedBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -24,52 +24,55 @@ import ru.betterend.patterns.Patterns;
public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockPatterned { public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockPatterned {
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public ChandelierBlock(Block source) { public ChandelierBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noCollision().nonOpaque().requiresTool().luminance(15)); super(FabricBlockSettings.copyOf(source).luminance(15).noCollission().noOcclusion().requiresCorrectToolForDrops());
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @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)); return BOUNDING_SHAPES.get(state.getValue(FACING));
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
if (block.contains("item")) { if (block.contains("item")) {
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath()); 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()); 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()); return Patterns.createJson(Patterns.BLOCK_CHANDELIER_WALL, blockId.getPath());
} else { }
else {
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, blockId.getPath()); return Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, blockId.getPath());
} }
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_CHANDELIER; return Patterns.STATE_CHANDELIER;
} }
static { static {
BOUNDING_SHAPES.put(Direction.UP, Block.createCuboidShape(5, 0, 5, 11, 13, 11)); BOUNDING_SHAPES.put(Direction.UP, Block.box(5, 0, 5, 11, 13, 11));
BOUNDING_SHAPES.put(Direction.DOWN, Block.createCuboidShape(5, 3, 5, 11, 16, 11)); BOUNDING_SHAPES.put(Direction.DOWN, Block.box(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.NORTH, Shapes.box(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.SOUTH, Shapes.box(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.WEST, Shapes.box(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.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0));
} }
} }

View file

@ -1,16 +1,15 @@
package ru.betterend.blocks; 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.BlockPos;
import net.minecraft.core.Direction; 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; import ru.betterend.blocks.basis.UnderwaterPlantBlock;
public class CharniaBlock extends UnderwaterPlantBlock { public class CharniaBlock extends UnderwaterPlantBlock {
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return sideCoversSmallSquare(world, pos.below(), Direction.UP) return canSupportCenter(world, pos.below(), Direction.UP) && world.getFluidState(pos).getType() == Fluids.WATER;
&& world.getFluidState(pos).getFluid() == Fluids.WATER;
} }
} }

View file

@ -8,7 +8,7 @@ public class ChorusGrassBlock extends EndPlantBlock {
public ChorusGrassBlock() { public ChorusGrassBlock() {
super(true); super(true);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.getBlock() == EndBlocks.CHORUS_NYLIUM; return state.getBlock() == EndBlocks.CHORUS_NYLIUM;

View file

@ -1,12 +1,12 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class DenseSnowBlock extends BlockBase { public class DenseSnowBlock extends BlockBase {
public DenseSnowBlock() { 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));
} }
} }

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,9 +17,9 @@ public class DragonTreeSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.DRAGON_TREE.getFeature(); return EndFeatures.DRAGON_TREE.getFeature();
} }
@Override @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); return world.getBlockState(pos.below()).is(EndBlocks.SHADOW_GRASS);
} }
} }

View file

@ -8,28 +8,28 @@ import java.util.Random;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Registry; 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.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.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable, BlockPatterned { public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderTypeable, BlockPatterned {
public EmeraldIceBlock() { public EmeraldIceBlock() {
super(FabricBlockSettings.copyOf(Blocks.ICE)); super(FabricBlockSettings.copyOf(Blocks.ICE));
} }
@ -40,17 +40,16 @@ public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable
} }
@Override @Override
public void afterBreak(Level world, Player player, BlockPos pos, BlockState state, public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack stack) {
@Nullable BlockEntity blockEntity, ItemStack stack) { super.playerDestroy(world, player, pos, state, blockEntity, stack);
super.afterBreak(world, player, pos, state, blockEntity, stack);
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) == 0) { if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) == 0) {
if (world.getDimension().isUltrawarm()) { if (world.dimensionType().ultraWarm()) {
world.removeBlock(pos, false); world.removeBlock(pos, false);
return; return;
} }
Material material = world.getBlockState(pos.below()).getMaterial(); Material material = world.getBlockState(pos.below()).getMaterial();
if (material.blocksMovement() || material.isLiquid()) { if (material.blocksMotion() || material.isLiquid()) {
world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState()); world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
} }
} }
@ -59,38 +58,39 @@ public class EmeraldIceBlock extends TransparentBlock implements IRenderTypeable
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { 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); this.melt(state, world, pos);
} }
} }
protected void melt(BlockState state, Level world, BlockPos pos) { protected void melt(BlockState state, Level world, BlockPos pos) {
if (world.getDimension().isUltrawarm()) { if (world.dimensionType().ultraWarm()) {
world.removeBlock(pos, false); world.removeBlock(pos, false);
} else { }
else {
world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState()); world.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
world.updateNeighbor(pos, Blocks.WATER, pos); world.neighborChanged(pos, Blocks.WATER, pos);
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath(); String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block); return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE; return Patterns.STATE_SIMPLE;

View file

@ -10,26 +10,26 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.UnderwaterPlantBlock; import ru.betterend.blocks.basis.UnderwaterPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -38,80 +38,81 @@ import ru.betterend.util.MHelper;
public class EndLilyBlock extends UnderwaterPlantBlock { public class EndLilyBlock extends UnderwaterPlantBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(4, 0, 4, 12, 16, 12); private static final VoxelShape SHAPE_BOTTOM = Block.box(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_TOP = Block.box(2, 0, 2, 14, 6, 14);
public EndLilyBlock() { public EndLilyBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) super(FabricBlockSettings.of(Material.WATER_PLANT)
.sounds(SoundType.WET_GRASS).breakByHand(true).luminance((state) -> { .breakByTool(FabricToolTags.SHEARS)
return state.getValue(SHAPE) == TripleShape.TOP ? 13 : 0; .breakByHand(true)
}).noCollision()); .sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(SHAPE) == TripleShape.TOP ? 13 : 0)
.noCollission());
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) { return state.getValue(SHAPE) == TripleShape.TOP ? Blocks.AIR.defaultBlockState() : Blocks.WATER.defaultBlockState();
return state.getValue(SHAPE) == TripleShape.TOP ? Blocks.AIR.defaultBlockState() }
: Blocks.WATER.defaultBlockState(); else {
} else {
return state; return state;
} }
} }
@Override @Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos); Vec3 vec3d = state.getOffset(view, pos);
VoxelShape shape = state.getValue(SHAPE) == TripleShape.TOP ? SHAPE_TOP : SHAPE_BOTTOM; 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 @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @Override
public FluidState getFluidState(BlockState state) { public FluidState getFluidState(BlockState state) {
return state.getValue(SHAPE) == TripleShape.TOP ? Fluids.EMPTY.defaultBlockState() return state.getValue(SHAPE) == TripleShape.TOP ? Fluids.EMPTY.defaultFluidState() : Fluids.WATER.getSource(false);
: Fluids.WATER.getStill(false);
} }
@Override @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) { if (state.getValue(SHAPE) == TripleShape.TOP) {
return world.getBlockState(pos.below()).getBlock() == this; 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())); 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()); BlockState down = world.getBlockState(pos.below());
return up.getBlock() == this && down.getBlock() == this; return up.getBlock() == this && down.getBlock() == this;
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(SHAPE) == TripleShape.TOP) { if (state.getValue(SHAPE) == TripleShape.TOP) {
return Lists.newArrayList(new ItemStack(EndItems.END_LILY_LEAF, 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)));
new ItemStack(EndBlocks.END_LILY_SEED, MHelper.randRange(1, 2, MHelper.RANDOM)));
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); return new ItemStack(EndBlocks.END_LILY_SEED);
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
} }

View file

@ -1,10 +1,9 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; import java.util.Random;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.material.Fluids;
import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -14,24 +13,21 @@ public class EndLilySeedBlock extends UnderwaterPlantWithAgeBlock {
@Override @Override
public void grow(WorldGenLevel world, Random random, BlockPos pos) { public void grow(WorldGenLevel world, Random random, BlockPos pos) {
if (canGrow(world, pos)) { if (canGrow(world, pos)) {
BlocksHelper.setWithoutUpdate(world, pos, BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.BOTTOM));
EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.BOTTOM)); BlockPos up = pos.above();
BlockPos up = pos.up(); while (world.getFluidState(up).isSource()) {
while (world.getFluidState(up).isStill()) { BlocksHelper.setWithoutUpdate(world, up, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.MIDDLE));
BlocksHelper.setWithoutUpdate(world, up, up = up.above();
EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.MIDDLE));
up = up.up();
} }
BlocksHelper.setWithoutUpdate(world, up, BlocksHelper.setWithoutUpdate(world, up, EndBlocks.END_LILY.defaultBlockState().setValue(EndLilyBlock.SHAPE, TripleShape.TOP));
EndBlocks.END_LILY.defaultBlockState().with(EndLilyBlock.SHAPE, TripleShape.TOP));
} }
} }
private boolean canGrow(WorldGenLevel world, BlockPos pos) { private boolean canGrow(WorldGenLevel world, BlockPos pos) {
BlockPos up = pos.up(); BlockPos up = pos.above();
while (world.getBlockState(up).getFluidState().getFluid().equals(Fluids.WATER.getStill())) { while (world.getBlockState(up).getFluidState().getType().equals(Fluids.WATER.getSource())) {
up = up.up(); up = up.above();
} }
return world.isAir(up); return world.isEmptyBlock(up);
} }
} }

View file

@ -7,57 +7,57 @@ import com.google.common.collect.Lists;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; 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.storage.loot.LootContext;
import net.minecraft.core.BlockPos; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.BlockGetter;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class EndLotusFlowerBlock extends EndPlantBlock { public class EndLotusFlowerBlock extends EndPlantBlock {
private static final VoxelShape SHAPE_OUTLINE = Block.createCuboidShape(2, 0, 2, 14, 14, 14); private static final VoxelShape SHAPE_OUTLINE = Block.box(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_COLLISION = Block.box(0, 0, 0, 16, 2, 16);
public EndLotusFlowerBlock() { public EndLotusFlowerBlock() {
super(FabricBlockSettings.of(Material.PLANT).nonOpaque().luminance(15)); super(FabricBlockSettings.of(Material.PLANT).luminance(15).noOcclusion());
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_LOTUS_STEM); return state.is(EndBlocks.END_LOTUS_STEM);
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
@Override @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; return SHAPE_OUTLINE;
} }
@Override @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; return SHAPE_COLLISION;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
int count = MHelper.randRange(1, 2, MHelper.RANDOM); int count = MHelper.randRange(1, 2, MHelper.RANDOM);
return Lists.newArrayList(new ItemStack(EndBlocks.END_LOTUS_SEED, count)); return Lists.newArrayList(new ItemStack(EndBlocks.END_LOTUS_SEED, count));
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); return new ItemStack(EndBlocks.END_LOTUS_SEED);
} }
} }

View file

@ -3,23 +3,23 @@ package ru.betterend.blocks;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; 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.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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
@ -28,48 +28,48 @@ import ru.betterend.registry.EndBlocks;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class EndLotusLeafBlock extends BlockBaseNotFull implements IRenderTypeable { public class EndLotusLeafBlock extends BlockBaseNotFull implements IRenderTypeable {
public static final EnumProperty<Direction> HORIZONTAL_FACING = Properties.HORIZONTAL_FACING; public static final EnumProperty<Direction> HORIZONTAL_FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> 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() { public EndLotusLeafBlock() {
super(FabricBlockSettings.of(Material.PLANT).nonOpaque().sounds(SoundType.WET_GRASS)); super(FabricBlockSettings.of(Material.PLANT).noOcclusion().sound(SoundType.WET_GRASS));
} }
@Override @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 down = world.getBlockState(pos.below());
return !down.getFluidState().isEmpty() && down.getFluidState().getFluid() instanceof WaterFluid; return !down.getFluidState().isEmpty() && down.getFluidState().getType() instanceof WaterFluid;
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(SHAPE, HORIZONTAL_FACING); builder.add(SHAPE, HORIZONTAL_FACING);
} }
@Override @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; return VSHAPE;
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, HORIZONTAL_FACING); return BlocksHelper.rotateHorizontal(state, rotation, HORIZONTAL_FACING);
} }
@Override @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, HORIZONTAL_FACING); return BlocksHelper.mirrorHorizontal(state, mirror, HORIZONTAL_FACING);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); return new ItemStack(EndBlocks.END_LOTUS_SEED);
} }
} }

View file

@ -1,13 +1,12 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,103 +16,100 @@ public class EndLotusSeedBlock extends UnderwaterPlantWithAgeBlock {
@Override @Override
public void grow(WorldGenLevel world, Random random, BlockPos pos) { public void grow(WorldGenLevel world, Random random, BlockPos pos) {
if (canGrow(world, pos)) { if (canGrow(world, pos)) {
BlockState startLeaf = EndBlocks.END_LOTUS_STEM.defaultBlockState().with(EndLotusStemBlock.LEAF, true); BlockState startLeaf = EndBlocks.END_LOTUS_STEM.defaultBlockState().setValue(EndLotusStemBlock.LEAF, true);
BlockState roots = EndBlocks.END_LOTUS_STEM.defaultBlockState() BlockState roots = EndBlocks.END_LOTUS_STEM.defaultBlockState().setValue(EndLotusStemBlock.SHAPE, TripleShape.BOTTOM).setValue(EndLotusStemBlock.WATERLOGGED, true);
.with(EndLotusStemBlock.SHAPE, TripleShape.BOTTOM).with(EndLotusStemBlock.WATERLOGGED, true);
BlockState stem = EndBlocks.END_LOTUS_STEM.defaultBlockState(); BlockState stem = EndBlocks.END_LOTUS_STEM.defaultBlockState();
BlockState flower = EndBlocks.END_LOTUS_FLOWER.defaultBlockState(); BlockState flower = EndBlocks.END_LOTUS_FLOWER.defaultBlockState();
BlocksHelper.setWithoutUpdate(world, pos, roots); BlocksHelper.setWithoutUpdate(world, pos, roots);
MutableBlockPos bpos = new MutableBlockPos().set(pos); MutableBlockPos bpos = new MutableBlockPos().set(pos);
bpos.setY(bpos.getY() + 1); bpos.setY(bpos.getY() + 1);
while (world.getFluidState(bpos).isStill()) { while (world.getFluidState(bpos).isSource()) {
BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.WATERLOGGED, true)); BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.WATERLOGGED, true));
bpos.setY(bpos.getY() + 1); bpos.setY(bpos.getY() + 1);
} }
int height = random.nextBoolean() ? 0 : random.nextBoolean() ? 1 : random.nextBoolean() ? 1 : -1; int height = random.nextBoolean() ? 0 : random.nextBoolean() ? 1 : random.nextBoolean() ? 1 : -1;
TripleShape shape = (height == 0) ? TripleShape.TOP : TripleShape.MIDDLE; TripleShape shape = (height == 0) ? TripleShape.TOP : TripleShape.MIDDLE;
Direction dir = BlocksHelper.randomHorizontal(random); Direction dir = BlocksHelper.randomHorizontal(random);
BlockPos leafCenter = bpos.immutable().offset(dir); BlockPos leafCenter = bpos.immutable().relative(dir);
if (hasLeaf(world, leafCenter)) { if (hasLeaf(world, leafCenter)) {
generateLeaf(world, leafCenter); generateLeaf(world, leafCenter);
BlocksHelper.setWithoutUpdate(world, bpos, BlocksHelper.setWithoutUpdate(world, bpos, startLeaf.setValue(EndLotusStemBlock.SHAPE, shape).setValue(EndLotusStemBlock.FACING, dir));
startLeaf.with(EndLotusStemBlock.SHAPE, shape).with(EndLotusStemBlock.FACING, dir));
} else {
BlocksHelper.setWithoutUpdate(world, bpos, stem.with(EndLotusStemBlock.SHAPE, shape));
} }
else {
BlocksHelper.setWithoutUpdate(world, bpos, stem.setValue(EndLotusStemBlock.SHAPE, shape));
}
bpos.setY(bpos.getY() + 1); bpos.setY(bpos.getY() + 1);
for (int i = 1; i <= height; i++) { for (int i = 1; i <= height; i++) {
if (!world.isAir(bpos)) { if (!world.isEmptyBlock(bpos)) {
bpos.setY(bpos.getY() - 1); bpos.setY(bpos.getY() - 1);
BlocksHelper.setWithoutUpdate(world, bpos, flower); BlocksHelper.setWithoutUpdate(world, bpos, flower);
bpos.setY(bpos.getY() - 1); bpos.setY(bpos.getY() - 1);
stem = world.getBlockState(bpos); 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; return;
} }
BlocksHelper.setWithoutUpdate(world, bpos, stem); BlocksHelper.setWithoutUpdate(world, bpos, stem);
bpos.setY(bpos.getY() + 1); bpos.setY(bpos.getY() + 1);
} }
if (!world.isAir(bpos) || height < 0) { if (!world.isEmptyBlock(bpos) || height < 0) {
bpos.setY(bpos.getY() - 1); bpos.setY(bpos.getY() - 1);
} }
BlocksHelper.setWithoutUpdate(world, bpos, flower); BlocksHelper.setWithoutUpdate(world, bpos, flower);
bpos.setY(bpos.getY() - 1); bpos.setY(bpos.getY() - 1);
stem = world.getBlockState(bpos); stem = world.getBlockState(bpos);
if (!stem.is(EndBlocks.END_LOTUS_STEM)) { if (!stem.is(EndBlocks.END_LOTUS_STEM)) {
stem = EndBlocks.END_LOTUS_STEM.defaultBlockState(); stem = EndBlocks.END_LOTUS_STEM.defaultBlockState();
if (!world.getBlockState(bpos.north()).getFluidState().isEmpty()) { 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)) { if (world.getBlockState(bpos.relative(dir)).is(EndBlocks.END_LOTUS_LEAF)) {
stem = stem.with(EndLotusStemBlock.LEAF, true).with(EndLotusStemBlock.FACING, dir); 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) { private boolean canGrow(WorldGenLevel world, BlockPos pos) {
MutableBlockPos bpos = new MutableBlockPos(); MutableBlockPos bpos = new MutableBlockPos();
bpos.set(pos); 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); 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) { private void generateLeaf(WorldGenLevel world, BlockPos pos) {
MutableBlockPos p = new MutableBlockPos(); MutableBlockPos p = new MutableBlockPos();
BlockState leaf = EndBlocks.END_LOTUS_LEAF.defaultBlockState(); BlockState leaf = EndBlocks.END_LOTUS_LEAF.defaultBlockState();
BlocksHelper.setWithoutUpdate(world, pos, leaf.with(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM)); BlocksHelper.setWithoutUpdate(world, pos, leaf.setValue(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM));
for (Direction move : BlocksHelper.HORIZONTAL) { for (Direction move: BlocksHelper.HORIZONTAL) {
BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf BlocksHelper.setWithoutUpdate(world, p.set(pos).move(move), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, move).setValue(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE));
.with(EndLotusLeafBlock.HORIZONTAL_FACING, move).with(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE));
} }
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i ++) {
Direction d1 = BlocksHelper.HORIZONTAL[i]; Direction d1 = BlocksHelper.HORIZONTAL[i];
Direction d2 = BlocksHelper.HORIZONTAL[(i + 1) & 3]; Direction d2 = BlocksHelper.HORIZONTAL[(i + 1) & 3];
BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), BlocksHelper.setWithoutUpdate(world, p.set(pos).move(d1).move(d2), leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, d1).setValue(EndLotusLeafBlock.SHAPE, TripleShape.TOP));
leaf.with(EndLotusLeafBlock.HORIZONTAL_FACING, d1).with(EndLotusLeafBlock.SHAPE, TripleShape.TOP));
} }
} }
private boolean hasLeaf(WorldGenLevel world, BlockPos pos) { private boolean hasLeaf(WorldGenLevel world, BlockPos pos) {
MutableBlockPos p = new MutableBlockPos(); MutableBlockPos p = new MutableBlockPos();
p.setY(pos.getY()); p.setY(pos.getY());
int count = 0; int count = 0;
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x ++) {
p.setX(pos.getX() + 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); p.setZ(pos.getZ() + z);
if (world.isAir(p) && !world.getFluidState(p.below()).isEmpty()) if (world.isEmptyBlock(p) && !world.getFluidState(p.below()).isEmpty())
count++; count ++;
} }
} }
return count == 9; return count == 9;

View file

@ -5,96 +5,92 @@ import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis; 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.BlockGetter;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class EndLotusStemBlock extends BlockBase implements Waterloggable, IRenderTypeable { public class EndLotusStemBlock extends BlockBase implements SimpleWaterloggedBlock, IRenderTypeable {
public static final EnumProperty<Direction> FACING = Properties.FACING; public static final EnumProperty<Direction> FACING = BlockStateProperties.FACING;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty LEAF = BooleanProperty.of("leaf"); public static final BooleanProperty LEAF = BooleanProperty.create("leaf");
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final Map<Axis, VoxelShape> SHAPES = Maps.newEnumMap(Axis.class); private static final Map<Axis, VoxelShape> SHAPES = Maps.newEnumMap(Axis.class);
public EndLotusStemBlock() { public EndLotusStemBlock() {
super(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)); super(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS));
this.setDefaultState(getDefaultState().with(WATERLOGGED, false).with(SHAPE, TripleShape.MIDDLE) this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false).setValue(SHAPE, TripleShape.MIDDLE).setValue(LEAF, false).setValue(FACING, Direction.UP));
.with(LEAF, false).with(FACING, Direction.UP));
} }
@Override @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()); return state.getValue(LEAF) ? SHAPES.get(Axis.Y) : SHAPES.get(state.getValue(FACING).getAxis());
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED, SHAPE, LEAF); builder.add(FACING, WATERLOGGED, SHAPE, LEAF);
} }
@Override @Override
public FluidState getFluidState(BlockState state) { 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 @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
LevelAccessor worldAccess = ctx.getLevel(); LevelAccessor worldAccess = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos(); BlockPos blockPos = ctx.getClickedPos();
return this.defaultBlockState() return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER).setValue(FACING, ctx.getClickedFace());
.with(WATERLOGGED, worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER)
.with(FACING, ctx.getSide());
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING); return BlocksHelper.rotateHorizontal(state, rotation, FACING);
} }
@Override @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING); return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
BlockPos pos, BlockPos posFrom) {
if ((Boolean) state.getValue(WATERLOGGED)) { 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; return state;
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
static { static {
SHAPES.put(Axis.X, Block.createCuboidShape(0, 6, 6, 16, 10, 10)); SHAPES.put(Axis.X, Block.box(0, 6, 6, 16, 10, 10));
SHAPES.put(Axis.Y, Block.createCuboidShape(6, 0, 6, 10, 16, 10)); SHAPES.put(Axis.Y, Block.box(6, 0, 6, 10, 16, 10));
SHAPES.put(Axis.Z, Block.createCuboidShape(6, 6, 0, 10, 10, 16)); SHAPES.put(Axis.Z, Block.box(6, 6, 0, 10, 10, 16));
} }
} }

View file

@ -7,36 +7,34 @@ import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Registry; 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.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.blocks.basis.BlockBaseNotFull;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class EndPathBlock extends BlockBaseNotFull { 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) { public EndPathBlock(Block source) {
super(FabricBlockSettings.copyOf(source).allowsSpawning((state, world, pos, type) -> { super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
return false;
}));
if (source instanceof EndTerrainBlock) { if (source instanceof EndTerrainBlock) {
EndTerrainBlock terrain = (EndTerrainBlock) source; EndTerrainBlock terrain = (EndTerrainBlock) source;
terrain.setPathBlock(this); terrain.setPathBlock(this);
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -45,17 +43,17 @@ public class EndPathBlock extends BlockBaseNotFull {
} }
return Collections.singletonList(new ItemStack(Blocks.END_STONE)); return Collections.singletonList(new ItemStack(Blocks.END_STONE));
} }
@Override @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; return SHAPE;
} }
@Override @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; return SHAPE;
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
String name = Registry.BLOCK.getKey(this).getPath(); String name = Registry.BLOCK.getKey(this).getPath();
@ -64,7 +62,7 @@ public class EndPathBlock extends BlockBaseNotFull {
map.put("%side%", name.replace("_path", "") + "_side"); map.put("%side%", name.replace("_path", "") + "_side");
return Patterns.createJson(Patterns.BLOCK_PATH, map); return Patterns.createJson(Patterns.BLOCK_PATH, map);
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_ROTATED_TOP; return Patterns.STATE_ROTATED_TOP;

View file

@ -2,10 +2,9 @@ package ru.betterend.blocks;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.world.level.block.Block;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
@ -15,7 +14,7 @@ public class EndPedestal extends PedestalBlock {
public EndPedestal(Block parent) { public EndPedestal(Block parent) {
super(parent); super(parent);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
@ -23,7 +22,7 @@ public class EndPedestal extends PedestalBlock {
Map<String, String> textures = new HashMap<String, String>() { Map<String, String> textures = new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%mod%", BetterEnd.MOD_ID); put("%mod%", BetterEnd.MOD_ID );
put("%top%", name + "_polished"); put("%top%", name + "_polished");
put("%base%", name + "_polished"); put("%base%", name + "_polished");
put("%pillar%", name + "_pillar_side"); put("%pillar%", name + "_pillar_side");

View file

@ -6,29 +6,29 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.core.Registry; 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.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block; 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.Blocks;
import net.minecraft.world.level.block.NetherPortalBlock; import net.minecraft.world.level.block.NetherPortalBlock;
import net.minecraft.client.color.block.BlockColor; import net.minecraft.world.level.block.Rotation;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; 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 net.minecraft.world.level.dimension.DimensionType;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
@ -42,8 +42,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
public static final IntegerProperty PORTAL = BlockProperties.PORTAL; public static final IntegerProperty PORTAL = BlockProperties.PORTAL;
public EndPortalBlock() { public EndPortalBlock() {
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getExplosionResistance()) super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getExplosionResistance()).luminance(15));
.luminance(15));
} }
@Override @Override
@ -51,13 +50,12 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
super.createBlockStateDefinition(builder); super.createBlockStateDefinition(builder);
builder.add(PORTAL); builder.add(PORTAL);
} }
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
if (random.nextInt(100) == 0) { if (random.nextInt(100) == 0) {
world.playLocalSound(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, SoundEvents.PORTAL_AMBIENT, 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);
SoundSource.BLOCKS, 0.5F, random.nextFloat() * 0.4F + 0.8F, false);
} }
double x = pos.getX() + random.nextDouble(); double x = pos.getX() + random.nextDouble();
@ -74,24 +72,24 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {}
BlockPos pos, BlockPos posFrom) {
@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
return state; return state;
} }
@Override @Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (world.isClientSide() || !validate(entity)) if (world.isClientSide || !validate(entity)) return;
return;
entity.setPortalCooldown(); entity.setPortalCooldown();
ServerLevel currentWorld = (ServerLevel) world; ServerLevel currentWorld = (ServerLevel) world;
MinecraftServer server = currentWorld.getServer(); 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); boolean isInEnd = currentWorld.dimension().equals(Level.END);
ServerLevel destination = isInEnd ? targetWorld : server.getLevel(Level.END); ServerLevel destination = isInEnd ? targetWorld : server.getLevel(Level.END);
BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity); BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity);
if (exitPos == null) if (exitPos == null) return;
return;
if (entity instanceof ServerPlayer) { if (entity instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) entity; ServerPlayer player = (ServerPlayer) entity;
teleportPlayer(player, destination, exitPos); teleportPlayer(player, destination, exitPos);
@ -106,43 +104,39 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
} }
private boolean validate(Entity entity) { private boolean validate(Entity entity) {
return !entity.isPassenger() && !entity.isVehicle() && entity.canChangeDimensions() return !entity.isPassenger() && !entity.isVehicle() &&
&& !entity.isOnPortalCooldown(); entity.canChangeDimensions() && !entity.isOnPortalCooldown();
} }
private void teleportPlayer(ServerPlayer player, ServerLevel destination, BlockPos exitPos) { private void teleportPlayer(ServerPlayer player, ServerLevel destination, BlockPos exitPos) {
if (player.isCreative()) { if (player.isCreative()) {
player.teleportTo(destination, exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5, player.yRot, player.teleportTo(destination, exitPos.getX() + 0.5, exitPos.getY(), exitPos.getZ() + 0.5, player.yRot, player.xRot);
player.xRot);
} else { } else {
TeleportingEntity teleEntity = (TeleportingEntity) player; TeleportingEntity teleEntity = (TeleportingEntity) player;
teleEntity.beSetExitPos(exitPos); teleEntity.beSetExitPos(exitPos);
player.changeDimension(destination); player.changeDimension(destination);
} }
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;
} }
private BlockPos findExitPos(ServerLevel currentWorld, ServerLevel targetWorld, BlockPos currentPos, private BlockPos findExitPos(ServerLevel currentWorld, ServerLevel targetWorld, BlockPos currentPos, Entity entity) {
Entity entity) { if (targetWorld == null) return null;
if (targetWorld == null)
return null;
Registry<DimensionType> registry = targetWorld.registryAccess().dimensionTypes(); Registry<DimensionType> registry = targetWorld.registryAccess().dimensionTypes();
ResourceLocation targetWorldId = targetWorld.dimension().location(); ResourceLocation targetWorldId = targetWorld.dimension().location();
ResourceLocation currentWorldId = currentWorld.dimension().location(); ResourceLocation currentWorldId = currentWorld.dimension().location();
double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).coordinateScale(); double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).coordinateScale();
double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).coordinateScale(); double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).coordinateScale();
double multiplier = targetMultiplier > currentMultiplier ? 1.0 / targetMultiplier : currentMultiplier; double multiplier = targetMultiplier > currentMultiplier ? 1.0 / targetMultiplier : currentMultiplier;
BlockPos.MutableBlockPos basePos = currentPos.mutable().set(currentPos.getX() * multiplier, currentPos.getY(), BlockPos.MutableBlockPos basePos = currentPos.mutable().set(currentPos.getX() * multiplier, currentPos.getY(), currentPos.getZ() * multiplier);
currentPos.getZ() * multiplier);
BlockPos.MutableBlockPos checkPos = basePos.mutable(); BlockPos.MutableBlockPos checkPos = basePos.mutable();
BlockState currentState = currentWorld.getBlockState(currentPos); BlockState currentState = currentWorld.getBlockState(currentPos);
int radius = (EternalRitual.SEARCH_RADIUS >> 4) + 1; int radius = (EternalRitual.SEARCH_RADIUS >> 4) + 1;
checkPos = EternalRitual.findBlockPos(targetWorld, checkPos, radius, this, checkPos = EternalRitual.findBlockPos(targetWorld, checkPos, radius, this, state -> state.is(this) &&
state -> state.is(this) && state.getValue(PORTAL).equals(currentState.getValue(PORTAL))); state.getValue(PORTAL).equals(currentState.getValue(PORTAL)));
if (checkPos != null) { if (checkPos != null) {
BlockState checkState = targetWorld.getBlockState(checkPos); BlockState checkState = targetWorld.getBlockState(checkPos);
Axis axis = checkState.getValue(AXIS); Axis axis = checkState.getValue(AXIS);
@ -156,19 +150,17 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
entity.rotate(Rotation.CLOCKWISE_90); entity.rotate(Rotation.CLOCKWISE_90);
entityDir = entityDir.getClockWise(); entityDir = entityDir.getClockWise();
} }
return checkPos.move(entityDir); return checkPos.relative(entityDir);
} }
return null; return null;
} }
private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis) { private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis) {
return findCenter(world, pos, axis, 1); return findCenter(world, pos, axis, 1);
} }
private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis, private BlockPos.MutableBlockPos findCenter(Level world, BlockPos.MutableBlockPos pos, Direction.Axis axis, int step) {
int step) { if (step > 8) return pos;
if (step > 8)
return pos;
BlockState right, left; BlockState right, left;
Direction rightDir, leftDir; Direction rightDir, leftDir;
rightDir = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE); rightDir = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
@ -189,7 +181,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> EndPortals.getColor(state.getValue(PORTAL)); return (state, world, pos, tintIndex) -> EndPortals.getColor(state.getValue(PORTAL));
} }

View file

@ -2,12 +2,12 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Blocks; 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.block.SoundType;
import net.minecraft.world.level.material.MaterialColor;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class EndStoneBlock extends BlockBase { public class EndStoneBlock extends BlockBase {
public EndStoneBlock(MaterialColor color) { 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));
} }
} }

View file

@ -8,85 +8,89 @@ import com.google.common.collect.Lists;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; 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.BlockGetter;
import net.minecraft.world.level.Level; 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.basis.BaseBlockWithEntity;
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity; import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
public class EndStoneSmelter extends BaseBlockWithEntity { public class EndStoneSmelter extends BaseBlockWithEntity {
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty LIT = Properties.LIT; public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final String ID = "end_stone_smelter"; public static final String ID = "end_stone_smelter";
public EndStoneSmelter() { public EndStoneSmelter() {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.COLOR_GRAY).hardness(4F).resistance(100F) super(FabricBlockSettings.of(Material.STONE, MaterialColor.COLOR_GRAY)
.requiresTool().sounds(SoundType.STONE)); .hardness(4F)
this.setDefaultState(this.stateManager.defaultBlockState().with(FACING, Direction.NORTH).with(LIT, false)); .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, public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
BlockHitResult hit) {
if (world.isClientSide) { if (world.isClientSide) {
return ActionResult.SUCCESS; return InteractionResult.SUCCESS;
} else { } else {
this.openScreen(world, pos, player); this.openScreen(world, pos, player);
return ActionResult.CONSUME; return InteractionResult.CONSUME;
} }
} }
private void openScreen(Level world, BlockPos pos, Player player) { private void openScreen(Level world, BlockPos pos, Player player) {
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof EndStoneSmelterBlockEntity) { if (blockEntity instanceof EndStoneSmelterBlockEntity) {
player.openHandledScreen((EndStoneSmelterBlockEntity) blockEntity); player.openMenu((EndStoneSmelterBlockEntity) blockEntity);
} }
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return this.defaultBlockState().with(FACING, ctx.getPlayerFacing().getOpposite()); return this.defaultBlockState().setValue(FACING, ctx.getHorizontalDirection().getOpposite());
} }
@Override @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity newBlockEntity(BlockGetter world) {
return new EndStoneSmelterBlockEntity(); return new EndStoneSmelterBlockEntity();
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = Lists.newArrayList(new ItemStack(this)); List<ItemStack> drop = Lists.newArrayList(new ItemStack(this));
BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof EndStoneSmelterBlockEntity) { if (blockEntity instanceof EndStoneSmelterBlockEntity) {
EndStoneSmelterBlockEntity smelterBlockEntity = (EndStoneSmelterBlockEntity) blockEntity; EndStoneSmelterBlockEntity smelterBlockEntity = (EndStoneSmelterBlockEntity) blockEntity;
for (int i = 0; i < smelterBlockEntity.size(); i++) { for (int i = 0; i < smelterBlockEntity.getContainerSize(); i++) {
ItemStack item = smelterBlockEntity.getStack(i); ItemStack item = smelterBlockEntity.getItem(i);
if (!item.isEmpty()) { if (!item.isEmpty()) {
drop.add(item); drop.add(item);
} }
@ -96,36 +100,36 @@ public class EndStoneSmelter extends BaseBlockWithEntity {
} }
@Override @Override
public boolean hasComparatorOutput(BlockState state) { public boolean hasAnalogOutputSignal(BlockState state) {
return true; return true;
} }
@Override @Override
public int getComparatorOutput(BlockState state, Level world, BlockPos pos) { public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
// TODO //TODO
return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos)); return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos));
} }
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public RenderShape getRenderShape(BlockState state) {
return BlockRenderType.MODEL; return RenderShape.MODEL;
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { 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 @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation((Direction) state.getValue(FACING))); return state.rotate(mirror.getRotation((Direction)state.getValue(FACING)));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, LIT); builder.add(FACING, LIT);
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
if (state.getValue(LIT)) { if (state.getValue(LIT)) {
@ -133,16 +137,15 @@ public class EndStoneSmelter extends BaseBlockWithEntity {
double y = pos.getY(); double y = pos.getY();
double z = pos.getZ() + 0.5D; double z = pos.getZ() + 0.5D;
if (random.nextDouble() < 0.1D) { if (random.nextDouble() < 0.1D) {
world.playLocalSound(x, y, z, SoundEvents.BLOCK_BLASTFURNACE_FIRE_CRACKLE, SoundSource.BLOCKS, 1.0F, world.playLocalSound(x, y, z, SoundEvents.BLASTFURNACE_FIRE_CRACKLE, SoundSource.BLOCKS, 1.0F, 1.0F, false);
1.0F, false);
} }
Direction direction = (Direction) state.getValue(FACING); Direction direction = (Direction)state.getValue(FACING);
Direction.Axis axis = direction.getAxis(); Direction.Axis axis = direction.getAxis();
double defOffset = random.nextDouble() * 0.6D - 0.3D; 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 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); world.addParticle(ParticleTypes.SMOKE, x + offX, y + offY, z + offZ, 0.0D, 0.0D, 0.0D);
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; 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.level.Level;
import net.minecraft.world.WorldView; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.chunk.light.ChunkLightProvider; 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.blocks.basis.BlockBase;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
public class EndTerrainBlock extends BlockBase { public class EndTerrainBlock extends BlockBase {
private Block pathBlock; private Block pathBlock;
public EndTerrainBlock(MaterialColor color) { public EndTerrainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sounds(BlockSounds.TERRAIN_SOUND) super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
.ticksRandomly());
} }
public void setPathBlock(Block roadBlock) { public void setPathBlock(Block roadBlock) {
this.pathBlock = roadBlock; this.pathBlock = roadBlock;
} }
@Override @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) {
BlockHitResult hit) { if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
if (pathBlock != null && player.getMainHandStack().getItem().isIn(FabricToolTags.SHOVELS)) { world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
world.playLocalSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) { if (!world.isClientSide) {
world.setBlockAndUpdate(pos, pathBlock.defaultBlockState()); world.setBlockAndUpdate(pos, pathBlock.defaultBlockState());
if (player != null && !player.isCreative()) { if (!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;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -73,7 +71,7 @@ public class EndTerrainBlock extends BlockBase {
} }
return Collections.singletonList(new ItemStack(Blocks.END_STONE)); return Collections.singletonList(new ItemStack(Blocks.END_STONE));
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { 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) { @Override
BlockPos blockPos = pos.up(); public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) {
BlockPos blockPos = pos.above();
BlockState blockState = worldView.getBlockState(blockPos); 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; return true;
} else if (blockState.getFluidState().getLevel() == 8) { }
else if (blockState.getFluidState().getAmount() == 8) {
return false; return false;
} else { }
int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, else {
blockState.getOpacity(worldView, blockPos)); int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
return i < 5; return i < 5;
} }
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
String name = Registry.BLOCK.getKey(this).getPath(); String name = Registry.BLOCK.getKey(this).getPath();
@ -104,7 +104,7 @@ public class EndTerrainBlock extends BlockBase {
map.put("%bottom%", "minecraft:block/end_stone"); map.put("%bottom%", "minecraft:block/end_stone");
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map); return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map);
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_ROTATED_TOP; return Patterns.STATE_ROTATED_TOP;

View file

@ -3,23 +3,26 @@ package ru.betterend.blocks;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; 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; import ru.betterend.blocks.basis.BlockBase;
public class EnderBlock extends BlockBase { public class EnderBlock extends BlockBase {
public EnderBlock() { public EnderBlock() {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.field_25708).hardness(5F).resistance(6F) super(FabricBlockSettings.of(Material.STONE, MaterialColor.WARPED_WART_BLOCK)
.requiresTool().sounds(SoundType.STONE)); .hardness(5F)
.resistance(6F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE));
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public int getColor(BlockState state, BlockView world, BlockPos pos) { public int getColor(BlockState state, BlockGetter world, BlockPos pos) {
return 0xFF005548; return 0xFF005548;
} }
} }

View file

@ -7,31 +7,32 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.Blocks;
import net.minecraft.world.level.block.FallingBlock; 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.world.level.storage.loot.LootContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class EndstoneDustBlock extends FallingBlock { public class EndstoneDustBlock extends FallingBlock {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
private static final int COLOR = MHelper.color(226, 239, 168); private static final int COLOR = MHelper.color(226, 239, 168);
public EndstoneDustBlock() { public EndstoneDustBlock() {
super(FabricBlockSettings.copyOf(Blocks.SAND).breakByTool(FabricToolTags.SHOVELS) super(FabricBlockSettings.copyOf(Blocks.SAND)
.breakByTool(FabricToolTags.SHOVELS)
.materialColor(Blocks.END_STONE.defaultMaterialColor())); .materialColor(Blocks.END_STONE.defaultMaterialColor()));
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public int getColor(BlockState state, BlockView world, BlockPos pos) { public int getDustColor(BlockState state, BlockGetter world, BlockPos pos) {
return COLOR; return COLOR;
} }
} }

View file

@ -1,27 +1,25 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.List; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; 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.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; 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.basis.PedestalBlock;
import ru.betterend.blocks.entities.EternalPedestalEntity; import ru.betterend.blocks.entities.EternalPedestalEntity;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -30,12 +28,12 @@ import ru.betterend.rituals.EternalRitual;
public class EternalPedestal extends PedestalBlock { public class EternalPedestal extends PedestalBlock {
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE;
public EternalPedestal() { public EternalPedestal() {
super(EndBlocks.FLAVOLITE_RUNED_ETERNAL); super(EndBlocks.FLAVOLITE_RUNED_ETERNAL);
this.setDefaultState(getDefaultState().with(ACTIVATED, false)); this.registerDefaultState(defaultBlockState().setValue(ACTIVATED, false));
} }
@Override @Override
public void checkRitual(Level world, BlockPos pos) { public void checkRitual(Level world, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
@ -56,12 +54,12 @@ public class EternalPedestal extends PedestalBlock {
ritual.disablePortal(portalId); 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 { } else {
ItemStack itemStack = pedestal.getStack(0); ItemStack itemStack = pedestal.getItem(0);
ResourceLocation id = Registry.ITEM.getId(itemStack.getItem()); ResourceLocation id = Registry.ITEM.getKey(itemStack.getItem());
if (EndPortals.isAvailableItem(id)) { 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()) { if (pedestal.hasRitual()) {
pedestal.getRitual().checkStructure(); pedestal.getRitual().checkStructure();
} else { } else {
@ -72,54 +70,51 @@ public class EternalPedestal extends PedestalBlock {
} }
} }
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
BlockPos pos, BlockPos posFrom) {
BlockState updated = super.updateShape(state, direction, newState, world, pos, posFrom); BlockState updated = super.updateShape(state, direction, newState, world, pos, posFrom);
if (!updated.is(this)) if (!updated.is(this)) return updated;
return updated;
if (!this.isPlaceable(updated)) { if (!this.isPlaceable(updated)) {
return updated.with(ACTIVATED, false); return updated.setValue(ACTIVATED, false);
} }
return updated; return updated;
} }
@Override @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; return 0.0F;
} }
@Override @Override
public float getBlastResistance() { public float getExplosionResistance() {
return Blocks.BEDROCK.getExplosionResistance(); return Blocks.BEDROCK.getExplosionResistance();
} }
@Override @Override
public boolean shouldDropItemsOnExplosion(Explosion explosion) { public boolean dropFromExplosion(Explosion explosion) {
return false; return false;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.is(this)) { if (state.is(this)) {
BlockProperties.PedestalState currentState = state.getValue(BlockProperties.PEDESTAL_STATE); BlockProperties.PedestalState currentState = state.getValue(BlockProperties.PEDESTAL_STATE);
if (currentState.equals(BlockProperties.PedestalState.BOTTOM) if (currentState.equals(BlockProperties.PedestalState.BOTTOM) || currentState.equals(BlockProperties.PedestalState.PILLAR)) {
|| currentState.equals(BlockProperties.PedestalState.PILLAR)) {
return Lists.newArrayList(); return Lists.newArrayList();
} }
} }
List<ItemStack> drop = Lists.newArrayList(); List<ItemStack> drop = Lists.newArrayList();
BlockEntity blockEntity = builder.getNullable(LootContextParams.BLOCK_ENTITY); BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof EternalPedestalEntity) { if (blockEntity instanceof EternalPedestalEntity) {
EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity; EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity;
if (!pedestal.isEmpty()) { if (!pedestal.isEmpty()) {
drop.add(pedestal.getStack(0)); drop.add(pedestal.getItem(0));
} }
} }
return drop; return drop;
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
super.createBlockStateDefinition(stateManager); super.createBlockStateDefinition(stateManager);
@ -127,7 +122,7 @@ public class EternalPedestal extends PedestalBlock {
} }
@Override @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity newBlockEntity(BlockGetter world) {
return new EternalPedestalEntity(); return new EternalPedestalEntity();
} }
} }

View file

@ -1,35 +1,33 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.List; import java.util.List;
import net.minecraft.core.BlockPos;
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.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; 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.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 { public class EternalRunedFlavolite extends RunedFlavolite {
@Override @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; return 0.0F;
} }
@Override @Override
public float getBlastResistance() { public float getExplosionResistance() {
return Blocks.BEDROCK.getExplosionResistance(); return Blocks.BEDROCK.getExplosionResistance();
} }
@Override @Override
public boolean shouldDropItemsOnExplosion(Explosion explosion) { public boolean dropFromExplosion(Explosion explosion) {
return false; return false;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(); return Lists.newArrayList();

View file

@ -2,13 +2,12 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class FilaluxLanternBlock extends BlockBase { public class FilaluxLanternBlock extends BlockBase {
public FilaluxLanternBlock() { public FilaluxLanternBlock() {
super(FabricBlockSettings.of(Material.WOOD).luminance(15).sounds(SoundType.WOOD) super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WOOD));
.breakByTool(FabricToolTags.AXES));
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.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.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.blocks.basis.EndPlantBlock;
import ru.betterend.interfaces.ISpetialItem; import ru.betterend.interfaces.ISpetialItem;
public class FlamaeaBlock extends EndPlantBlock implements 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() { public FlamaeaBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WET_GRASS) super(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)); .breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS));
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(Blocks.WATER); return state.is(Blocks.WATER);
} }
@Override @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; return SHAPE;
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));

View file

@ -2,13 +2,12 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class GlowingHymenophoreBlock extends BlockBase { public class GlowingHymenophoreBlock extends BlockBase {
public GlowingHymenophoreBlock() { public GlowingHymenophoreBlock() {
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WART_BLOCK) super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).luminance(15).sound(SoundType.WART_BLOCK));
.luminance(15));
} }
} }

View file

@ -2,9 +2,9 @@ package ru.betterend.blocks;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -12,19 +12,19 @@ public class GlowingMossBlock extends EndPlantBlock {
public GlowingMossBlock(int light) { public GlowingMossBlock(int light) {
super(light); super(light);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM; return state.getBlock() == EndBlocks.END_MOSS || state.getBlock() == EndBlocks.END_MYCELIUM;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) {
return true; return true;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) {
return 1F; return 1F;
} }
} }

View file

@ -2,45 +2,49 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class GlowingPillarLuminophorBlock extends BlockBase { public class GlowingPillarLuminophorBlock extends BlockBase {
public static final BooleanProperty NATURAL = BlockProperties.NATURAL; public static final BooleanProperty NATURAL = BlockProperties.NATURAL;
public GlowingPillarLuminophorBlock() { public GlowingPillarLuminophorBlock() {
super(FabricBlockSettings.of(Material.LEAVES).materialColor(MaterialColor.COLOR_ORANGE) super(FabricBlockSettings.of(Material.LEAVES)
.breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).strength(0.2F).luminance(15)); .materialColor(MaterialColor.COLOR_ORANGE)
this.setDefaultState(this.stateManager.defaultBlockState().with(NATURAL, false)); .breakByTool(FabricToolTags.SHEARS)
.strength(0.2F)
.luminance(15)
.sound(SoundType.GRASS));
this.registerDefaultState(this.stateDefinition.any().setValue(NATURAL, false));
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return state.getValue(NATURAL) ? world.getBlockState(pos.below()).is(EndBlocks.GLOWING_PILLAR_ROOTS) : true; return !state.getValue(NATURAL) || world.getBlockState(pos.below()).is(EndBlocks.GLOWING_PILLAR_ROOTS);
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} else { }
else {
return state; return state;
} }
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(NATURAL); stateManager.add(NATURAL);

View file

@ -2,33 +2,33 @@ package ru.betterend.blocks;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; 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.Block;
import net.minecraft.world.level.block.state.BlockState; 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.world.level.block.state.StateDefinition;
import net.minecraft.state.property.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.UpDownPlantBlock; import ru.betterend.blocks.basis.UpDownPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class GlowingPillarRootsBlock extends UpDownPlantBlock { public class GlowingPillarRootsBlock extends UpDownPlantBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.AMBER_MOSS); return state.is(EndBlocks.AMBER_MOSS);
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); return new ItemStack(EndBlocks.GLOWING_PILLAR_SEED);
} }
} }

View file

@ -4,15 +4,15 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -21,11 +21,15 @@ import ru.betterend.util.MHelper;
public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock { public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock {
public GlowingPillarSeedBlock() { public GlowingPillarSeedBlock() {
super(FabricBlockSettings.of(Material.PLANT).luminance((state) -> { super(FabricBlockSettings.of(Material.PLANT)
return state.getValue(AGE) * 3 + 3; .breakByTool(FabricToolTags.SHEARS)
}).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true).ticksRandomly().noCollision()); .breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel(state -> state.getValue(AGE) * 3 + 3)
.randomTicks()
.noCollission());
} }
@Override @Override
public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { public void growAdult(WorldGenLevel world, Random random, BlockPos pos) {
int height = MHelper.randRange(1, 2, random); int height = MHelper.randRange(1, 2, random);
@ -33,41 +37,39 @@ public class GlowingPillarSeedBlock extends EndPlantWithAgeBlock {
if (h < height) { if (h < height) {
return; return;
} }
MutableBlockPos mut = new MutableBlockPos().set(pos); MutableBlockPos mut = new MutableBlockPos().set(pos);
BlockState roots = EndBlocks.GLOWING_PILLAR_ROOTS.defaultBlockState(); BlockState roots = EndBlocks.GLOWING_PILLAR_ROOTS.defaultBlockState();
if (height < 2) { if (height < 2) {
BlocksHelper.setWithUpdate(world, mut, roots.with(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)); BlocksHelper.setWithUpdate(world, mut, roots.setValue(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));
mut.move(Direction.UP); mut.move(Direction.UP);
} }
BlocksHelper.setWithUpdate(world, mut, else {
EndBlocks.GLOWING_PILLAR_LUMINOPHOR.defaultBlockState().with(BlueVineLanternBlock.NATURAL, true)); BlocksHelper.setWithUpdate(world, mut, roots.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
for (Direction dir : BlocksHelper.DIRECTIONS) { mut.move(Direction.UP);
pos = mut.offset(dir); BlocksHelper.setWithUpdate(world, mut, roots.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP));
if (world.isAir(pos)) { mut.move(Direction.UP);
BlocksHelper.setWithUpdate(world, pos, }
EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().with(Properties.FACING, dir)); 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); mut.move(Direction.UP);
if (world.isAir(mut)) { if (world.isEmptyBlock(mut)) {
BlocksHelper.setWithUpdate(world, mut, BlocksHelper.setWithUpdate(world, mut, EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().setValue(BlockStateProperties.FACING, Direction.UP));
EndBlocks.GLOWING_PILLAR_LEAVES.defaultBlockState().with(Properties.FACING, Direction.UP));
} }
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.AMBER_MOSS); return state.is(EndBlocks.AMBER_MOSS);
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; 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.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.ItemPlacementContext; import net.minecraft.world.level.block.Block;
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.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.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; 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.blocks.basis.BlockBase;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
@ -32,20 +32,23 @@ import ru.betterend.util.MHelper;
public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider { public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider {
public static final IntegerProperty COLOR = BlockProperties.COLOR; public static final IntegerProperty COLOR = BlockProperties.COLOR;
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0);
public HelixTreeLeavesBlock() { public HelixTreeLeavesBlock() {
super(FabricBlockSettings.of(Material.LEAVES).materialColor(MaterialColor.COLOR_ORANGE) super(FabricBlockSettings.of(Material.LEAVES)
.breakByTool(FabricToolTags.SHEARS).sounds(SoundType.WART_BLOCK).sounds(SoundType.GRASS) .materialColor(MaterialColor.COLOR_ORANGE)
.breakByTool(FabricToolTags.SHEARS)
.sound(SoundType.WART_BLOCK)
.sound(SoundType.GRASS)
.strength(0.2F)); .strength(0.2F));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(COLOR); stateManager.add(COLOR);
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
return MHelper.color(237, getGreen(state.getValue(COLOR)), 20); 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); return MHelper.color(237, getGreen(4), 20);
}; };
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
double px = ctx.getBlockPos().getX() * 0.1; double px = ctx.getClickedPos().getX() * 0.1;
double py = ctx.getBlockPos().getY() * 0.1; double py = ctx.getClickedPos().getY() * 0.1;
double pz = ctx.getBlockPos().getZ() * 0.1; double pz = ctx.getClickedPos().getZ() * 0.1;
return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4));
} }
private int getGreen(int color) { private int getGreen(int color) {
float delta = color / 7F; float delta = color / 7F;
return (int) Mth.lerp(delta, 80, 158); return (int) Mth.lerp(delta, 80, 158);
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) { if (tool != null) {
if (tool.getItem().isIn(FabricToolTags.SHEARS) || tool.isCorrectToolForDrops(state) if (tool.getItem().is(FabricToolTags.SHEARS) || tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);
@ -85,7 +87,6 @@ public class HelixTreeLeavesBlock extends BlockBase implements IColorProvider {
} }
return Lists.newArrayList(); return Lists.newArrayList();
} }
return MHelper.RANDOM.nextInt(32) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING)) return MHelper.RANDOM.nextInt(32) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.HELIX_TREE_SAPLING)) : Lists.newArrayList();
: Lists.newArrayList();
} }
} }

View file

@ -10,18 +10,18 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.BlockProperties.HydraluxShape;
import ru.betterend.blocks.basis.UnderwaterPlantBlock; import ru.betterend.blocks.basis.UnderwaterPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -30,56 +30,60 @@ import ru.betterend.util.MHelper;
public class HydraluxBlock extends UnderwaterPlantBlock { public class HydraluxBlock extends UnderwaterPlantBlock {
public static final EnumProperty<HydraluxShape> SHAPE = BlockProperties.HYDRALUX_SHAPE; public static final EnumProperty<HydraluxShape> SHAPE = BlockProperties.HYDRALUX_SHAPE;
public HydraluxBlock() { public HydraluxBlock() {
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT).breakByTool(FabricToolTags.SHEARS) super(FabricBlockSettings.of(Material.WATER_PLANT)
.sounds(SoundType.WET_GRASS).breakByHand(true).luminance((state) -> { .breakByTool(FabricToolTags.SHEARS)
return state.getValue(SHAPE).hasGlow() ? 15 : 0; .breakByHand(true)
}).noCollision()); .sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(SHAPE).hasGlow() ? 15 : 0)
.noCollission());
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @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 down = world.getBlockState(pos.below());
HydraluxShape shape = state.getValue(SHAPE); HydraluxShape shape = state.getValue(SHAPE);
if (shape == HydraluxShape.FLOWER_BIG_TOP || shape == HydraluxShape.FLOWER_SMALL_TOP) { if (shape == HydraluxShape.FLOWER_BIG_TOP || shape == HydraluxShape.FLOWER_SMALL_TOP) {
return down.is(this); return down.is(this);
} else if (shape == HydraluxShape.ROOTS) { }
return down.is(EndBlocks.SULPHURIC_ROCK.stone) && world.getBlockState(pos.up()).is(this); else if (shape == HydraluxShape.ROOTS) {
} else { return down.is(EndBlocks.SULPHURIC_ROCK.stone) && world.getBlockState(pos.above()).is(this);
return down.is(this) && world.getBlockState(pos.up()).is(this); }
else {
return down.is(this) && world.getBlockState(pos.above()).is(this);
} }
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); return new ItemStack(EndBlocks.HYDRALUX_SAPLING);
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
HydraluxShape shape = state.getValue(SHAPE); HydraluxShape shape = state.getValue(SHAPE);
if (shape == HydraluxShape.FLOWER_BIG_BOTTOM || shape == HydraluxShape.FLOWER_SMALL_BOTTOM) { 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))); return Lists.newArrayList(new ItemStack(EndItems.HYDRALUX_PETAL, MHelper.randRange(1, 4, MHelper.RANDOM)));
} else if (shape == HydraluxShape.ROOTS) { }
return Lists else if (shape == HydraluxShape.ROOTS) {
.newArrayList(new ItemStack(EndBlocks.HYDRALUX_SAPLING, MHelper.randRange(1, 2, MHelper.RANDOM))); return Lists.newArrayList(new ItemStack(EndBlocks.HYDRALUX_SAPLING, MHelper.randRange(1, 2, MHelper.RANDOM)));
} }
return Collections.emptyList(); return Collections.emptyList();
} }

View file

@ -2,25 +2,29 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.Material;
import net.minecraft.world.level.material.MaterialColor; 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; import ru.betterend.blocks.basis.BlockBase;
public class HydraluxPetalBlock extends BlockBase { public class HydraluxPetalBlock extends BlockBase {
public HydraluxPetalBlock() { public HydraluxPetalBlock() {
this(FabricBlockSettings.of(Material.PLANT).materialColor(MaterialColor.SPRUCE).sounds(SoundType.WART_BLOCK) this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.AXES).hardness(1).resistance(1).breakByHand(true)); .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); super(settings);
} }
@Override @Override
public void onLandedUpon(Level world, BlockPos pos, Entity entity, float distance) { public void fallOn(Level world, BlockPos pos, Entity entity, float distance) {}
}
} }

View file

@ -14,9 +14,9 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo
public HydraluxPetalColoredBlock(FabricBlockSettings settings) { public HydraluxPetalColoredBlock(FabricBlockSettings settings) {
super(settings); super(settings);
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
return BlocksHelper.getBlockColor(this); return BlocksHelper.getBlockColor(this);
}; };
@ -28,19 +28,19 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo
return BlocksHelper.getBlockColor(this); return BlocksHelper.getBlockColor(this);
}; };
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
String path = "betterend:block/block_petal_colored"; String path = "betterend:block/block_petal_colored";
return Patterns.createJson(data, path, path); return Patterns.createJson(data, path, path);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
String path = "betterend:block/block_petal_colored"; String path = "betterend:block/block_petal_colored";
return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path); return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path);
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_DIRECT; return Patterns.STATE_DIRECT;

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.HydraluxShape;
import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock; import ru.betterend.blocks.basis.UnderwaterPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -18,32 +17,30 @@ public class HydraluxSaplingBlock extends UnderwaterPlantWithAgeBlock {
public void grow(WorldGenLevel world, Random random, BlockPos pos) { public void grow(WorldGenLevel world, Random random, BlockPos pos) {
int h = MHelper.randRange(4, 8, random); int h = MHelper.randRange(4, 8, random);
MutableBlockPos mut = new MutableBlockPos().set(pos); MutableBlockPos mut = new MutableBlockPos().set(pos);
for (int i = 1; i < h; i++) { for (int i = 1; i < h; i++) {
mut.setY(pos.getY() + i); mut.setY(pos.getY() + i);
if (!world.getBlockState(mut).is(Blocks.WATER)) { if (!world.getBlockState(mut).is(Blocks.WATER)) {
return; return;
} }
} }
mut.setY(pos.getY()); mut.setY(pos.getY());
BlockState state = EndBlocks.HYDRALUX.defaultBlockState(); 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++) { for (int i = 1; i < h - 2; i++) {
mut.setY(pos.getY() + 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); mut.setY(mut.getY() + 1);
boolean big = random.nextBoolean(); boolean big = random.nextBoolean();
BlocksHelper.setWithoutUpdate(world, mut, state.with(BlockProperties.HYDRALUX_SHAPE, BlocksHelper.setWithoutUpdate(world, mut, state.setValue(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_BOTTOM : HydraluxShape.FLOWER_SMALL_BOTTOM));
big ? HydraluxShape.FLOWER_BIG_BOTTOM : HydraluxShape.FLOWER_SMALL_BOTTOM));
mut.setY(mut.getY() + 1); mut.setY(mut.getY() + 1);
BlocksHelper.setWithoutUpdate(world, mut, state.with(BlockProperties.HYDRALUX_SHAPE, BlocksHelper.setWithoutUpdate(world, mut, state.setValue(BlockProperties.HYDRALUX_SHAPE, big ? HydraluxShape.FLOWER_BIG_TOP : HydraluxShape.FLOWER_SMALL_TOP));
big ? HydraluxShape.FLOWER_BIG_TOP : HydraluxShape.FLOWER_SMALL_TOP));
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.SULPHURIC_ROCK.stone); return state.is(EndBlocks.SULPHURIC_ROCK.stone);

View file

@ -8,125 +8,124 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; 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.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; 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.basis.BlockBaseNotFull;
import ru.betterend.blocks.entities.BlockEntityHydrothermalVent; import ru.betterend.blocks.entities.BlockEntityHydrothermalVent;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class HydrothermalVentBlock extends BlockBaseNotFull public class HydrothermalVentBlock extends BlockBaseNotFull implements EntityBlock, LiquidBlockContainer, SimpleWaterloggedBlock {
implements BlockEntityProvider, FluidFillable, Waterloggable { public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; 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() { public HydrothermalVentBlock() {
super(FabricBlockSettings.of(Material.STONE).breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.STONE) super(FabricBlockSettings.of(Material.STONE)
.noCollision().requiresTool()); .breakByTool(FabricToolTags.PICKAXES)
this.setDefaultState(getDefaultState().with(WATERLOGGED, true).with(ACTIVATED, false)); .sound(SoundType.STONE)
.noCollission()
.requiresCorrectToolForDrops());
this.registerDefaultState(defaultBlockState().setValue(WATERLOGGED, true).setValue(ACTIVATED, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(WATERLOGGED, ACTIVATED); builder.add(WATERLOGGED, ACTIVATED);
} }
@Override @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; return SHAPE;
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
state = world.getBlockState(pos.below()); state = world.getBlockState(pos.below());
return state.is(EndBlocks.SULPHURIC_ROCK.stone); return state.is(EndBlocks.SULPHURIC_ROCK.stone);
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.WATER.defaultBlockState(); 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; return state;
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
LevelAccessor worldAccess = ctx.getLevel(); LevelAccessor worldAccess = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos(); BlockPos blockPos = ctx.getClickedPos();
return this.defaultBlockState().with(WATERLOGGED, return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER);
worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER);
} }
@Override @Override
public FluidState getFluidState(BlockState state) { 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 @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity newBlockEntity(BlockGetter world) {
return new BlockEntityHydrothermalVent(); return new BlockEntityHydrothermalVent();
} }
@Override @Override
public void scheduledTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
BlockPos up = pos.up(); BlockPos up = pos.above();
if (world.getBlockState(up).is(Blocks.WATER)) { if (world.getBlockState(up).is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, up, EndBlocks.VENT_BUBBLE_COLUMN); 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 @Override
public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
ItemStack itemStack) { if (world instanceof ServerLevel && state.getValue(WATERLOGGED) && world.getBlockState(pos.above()).is(Blocks.WATER)) {
if (world instanceof ServerLevel && state.getValue(WATERLOGGED) tick(state,(ServerLevel) world, pos, world.random);
&& world.getBlockState(pos.up()).is(Blocks.WATER)) {
scheduledTick(state, (ServerLevel) world, pos, world.random);
} }
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
if (!state.getValue(ACTIVATED) && random.nextBoolean()) { if (!state.getValue(ACTIVATED) && random.nextBoolean()) {
@ -136,7 +135,8 @@ public class HydrothermalVentBlock extends BlockBaseNotFull
double z = pos.getZ() + random.nextDouble(); double z = pos.getZ() + random.nextDouble();
if (state.getValue(WATERLOGGED)) { if (state.getValue(WATERLOGGED)) {
world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0); world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0);
} else { }
else {
world.addParticle(ParticleTypes.SMOKE, x, y, z, 0, 0, 0); world.addParticle(ParticleTypes.SMOKE, x, y, z, 0, 0, 0);
} }
} }

View file

@ -1,15 +1,15 @@
package ru.betterend.blocks; 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.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.BlockGetter;
import net.minecraft.world.level.Level; 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.basis.PedestalBlock;
import ru.betterend.blocks.entities.InfusionPedestalEntity; import ru.betterend.blocks.entities.InfusionPedestalEntity;
import ru.betterend.rituals.InfusionRitual; import ru.betterend.rituals.InfusionRitual;
@ -22,7 +22,7 @@ public class InfusionPedestal extends PedestalBlock {
super(Blocks.OBSIDIAN); super(Blocks.OBSIDIAN);
this.height = 1.08F; this.height = 1.08F;
} }
@Override @Override
public void checkRitual(Level world, BlockPos pos) { public void checkRitual(Level world, BlockPos pos) {
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
@ -37,41 +37,41 @@ public class InfusionPedestal extends PedestalBlock {
} }
} }
} }
@Override @Override
public BlockEntity createBlockEntity(BlockView world) { public BlockEntity newBlockEntity(BlockGetter world) {
return new InfusionPedestalEntity(); return new InfusionPedestalEntity();
} }
@Override @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)) { if (state.is(this)) {
switch (state.getValue(STATE)) { switch(state.getValue(STATE)) {
case PEDESTAL_TOP: { case PEDESTAL_TOP: {
return SHAPE_PEDESTAL_TOP; return SHAPE_PEDESTAL_TOP;
} }
case DEFAULT: { case DEFAULT: {
return SHAPE_DEFAULT; return SHAPE_DEFAULT;
} }
default: { default: {
return super.getOutlineShape(state, world, pos, context); return super.getShape(state, world, pos, context);
} }
} }
} }
return super.getOutlineShape(state, world, pos, context); return super.getShape(state, world, pos, context);
} }
static { static {
VoxelShape basinUp = Block.createCuboidShape(2, 3, 2, 14, 4, 14); VoxelShape basinUp = Block.box(2, 3, 2, 14, 4, 14);
VoxelShape basinDown = Block.createCuboidShape(0, 0, 0, 16, 3, 16); VoxelShape basinDown = Block.box(0, 0, 0, 16, 3, 16);
VoxelShape pedestalTop = Block.createCuboidShape(1, 9, 1, 15, 11, 15); VoxelShape pedestalTop = Block.box(1, 9, 1, 15, 11, 15);
VoxelShape pedestalDefault = Block.createCuboidShape(1, 13, 1, 15, 15, 15); VoxelShape pedestalDefault = Block.box(1, 13, 1, 15, 15, 15);
VoxelShape pillar = Block.createCuboidShape(3, 0, 3, 13, 9, 13); VoxelShape pillar = Block.box(3, 0, 3, 13, 9, 13);
VoxelShape pillarDefault = Block.createCuboidShape(3, 4, 3, 13, 13, 13); VoxelShape pillarDefault = Block.box(3, 4, 3, 13, 13, 13);
VoxelShape eyeDefault = Block.createCuboidShape(4, 15, 4, 12, 16, 12); VoxelShape eyeDefault = Block.box(4, 15, 4, 12, 16, 12);
VoxelShape eyeTop = Block.createCuboidShape(4, 11, 4, 12, 12, 12); VoxelShape eyeTop = Block.box(4, 11, 4, 12, 12, 12);
VoxelShape basin = VoxelShapes.union(basinDown, basinUp); VoxelShape basin = Shapes.or(basinDown, basinUp);
SHAPE_DEFAULT = VoxelShapes.union(basin, pillarDefault, pedestalDefault, eyeDefault); SHAPE_DEFAULT = Shapes.or(basin, pillarDefault, pedestalDefault, eyeDefault);
SHAPE_PEDESTAL_TOP = VoxelShapes.union(pillar, pedestalTop, eyeTop); SHAPE_PEDESTAL_TOP = Shapes.or(pillar, pedestalTop, eyeTop);
} }
} }

View file

@ -6,21 +6,21 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.world.item.ItemPlacementContext; import net.minecraft.core.Registry;
import net.minecraft.world.item.ItemStack; import net.minecraft.core.Vec3i;
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.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.core.Vec3i; import net.minecraft.world.item.ItemStack;
import net.minecraft.core.Registry; 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.client.render.ERenderLayer;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -35,55 +35,55 @@ public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable,
private final Vec3i colorStart; private final Vec3i colorStart;
private final Vec3i colorEnd; private final Vec3i colorEnd;
private final int coloritem; private final int coloritem;
public JellyshroomCapBlock(int r1, int g1, int b1, int r2, int g2, int b2) { public JellyshroomCapBlock(int r1, int g1, int b1, int r2, int g2, int b2) {
super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK)); super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK));
colorStart = new Vec3i(r1, g1, b1); colorStart = new Vec3i(r1, g1, b1);
colorEnd = new Vec3i(r2, g2, b2); colorEnd = new Vec3i(r2, g2, b2);
coloritem = MHelper.color((r1 + r2) >> 1, (g1 + g2) >> 1, (b1 + b2) >> 1); coloritem = MHelper.color((r1 + r2) >> 1, (g1 + g2) >> 1, (b1 + b2) >> 1);
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
double px = ctx.getBlockPos().getX() * 0.1; double px = ctx.getClickedPos().getX() * 0.1;
double py = ctx.getBlockPos().getY() * 0.1; double py = ctx.getClickedPos().getY() * 0.1;
double pz = ctx.getBlockPos().getZ() * 0.1; double pz = ctx.getClickedPos().getZ() * 0.1;
return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(COLOR); stateManager.add(COLOR);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath(); String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block); return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap"); return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap");
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE; return Patterns.STATE_SIMPLE;
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
float delta = (float) state.getValue(COLOR) / 7F; float delta = (float) state.getValue(COLOR) / 7F;
int r = Mth.floor(Mth.lerp(delta, colorStart.getX() / 255F, colorEnd.getX() / 255F) * 255F); int r = Mth.floor(Mth.lerp(delta, colorStart.getX() / 255F, colorEnd.getX() / 255F) * 255F);

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,10 +17,9 @@ public class LacugroveSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.LACUGROVE.getFeature(); return EndFeatures.LACUGROVE.getFeature();
} }
@Override @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.END_MOSS) return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.ENDSTONE_DUST);
|| world.getBlockState(pos.below()).is(EndBlocks.ENDSTONE_DUST);
} }
} }

View file

@ -2,19 +2,18 @@ package ru.betterend.blocks;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.PentaShape;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -23,44 +22,45 @@ import ru.betterend.util.MHelper;
public class LanceleafBlock extends EndPlantBlock { public class LanceleafBlock extends EndPlantBlock {
public static final EnumProperty<PentaShape> SHAPE = BlockProperties.PENTA_SHAPE; public static final EnumProperty<PentaShape> SHAPE = BlockProperties.PENTA_SHAPE;
public static final IntegerProperty ROTATION = BlockProperties.ROTATION; public static final IntegerProperty ROTATION = BlockProperties.ROTATION;
public LanceleafBlock() { public LanceleafBlock() {
super(); super();
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE, ROTATION); stateManager.add(SHAPE, ROTATION);
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
PentaShape shape = state.getValue(SHAPE); PentaShape shape = state.getValue(SHAPE);
if (shape == PentaShape.TOP) { if (shape == PentaShape.TOP) {
return world.getBlockState(pos.below()).is(this); 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 if (shape == PentaShape.BOTTOM) {
} else { return world.getBlockState(pos.below()).is(EndBlocks.AMBER_MOSS) && world.getBlockState(pos.above()).is(this);
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 @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} else { }
else {
return state; return state;
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(SHAPE) == PentaShape.BOTTOM) { if (state.getValue(SHAPE) == PentaShape.BOTTOM) {
return Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED)); return Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED));
} }
return MHelper.RANDOM.nextBoolean() ? Collections.emptyList() return MHelper.RANDOM.nextBoolean() ? Collections.emptyList() : Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED));
: Collections.singletonList(new ItemStack(EndBlocks.LANCELEAF_SEED));
} }
} }

View file

@ -1,13 +1,12 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.WorldGenLevel; 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.BlockProperties.PentaShape;
import ru.betterend.blocks.basis.EndPlantWithAgeBlock; import ru.betterend.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -24,27 +23,23 @@ public class LanceleafSeedBlock extends EndPlantWithAgeBlock {
} }
int rotation = random.nextInt(4); int rotation = random.nextInt(4);
MutableBlockPos mut = new MutableBlockPos().set(pos); MutableBlockPos mut = new MutableBlockPos().set(pos);
BlockState plant = EndBlocks.LANCELEAF.defaultBlockState().with(BlockProperties.ROTATION, rotation); BlockState plant = EndBlocks.LANCELEAF.defaultBlockState().setValue(BlockProperties.ROTATION, rotation);
BlocksHelper.setWithoutUpdate(world, mut, plant.with(BlockProperties.PENTA_SHAPE, PentaShape.BOTTOM)); BlocksHelper.setWithoutUpdate(world, mut, plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.BOTTOM));
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.PRE_BOTTOM));
plant.with(BlockProperties.PENTA_SHAPE, PentaShape.PRE_BOTTOM));
for (int i = 2; i < height - 2; i++) { for (int i = 2; i < height - 2; i++) {
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.MIDDLE));
plant.with(BlockProperties.PENTA_SHAPE, PentaShape.MIDDLE));
} }
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.PRE_TOP));
plant.with(BlockProperties.PENTA_SHAPE, PentaShape.PRE_TOP)); BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), plant.setValue(BlockProperties.PENTA_SHAPE, PentaShape.TOP));
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP),
plant.with(BlockProperties.PENTA_SHAPE, PentaShape.TOP));
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.AMBER_MOSS); return state.is(EndBlocks.AMBER_MOSS);
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
} }

View file

@ -4,75 +4,77 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.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.BlockGetter;
import net.minecraft.world.level.Level; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class LargeAmaranitaBlock extends EndPlantBlock { public class LargeAmaranitaBlock extends EndPlantBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE_BOTTOM = Block.box(4, 0, 4, 12, 14, 12);
private static final VoxelShape SHAPE_TOP = VoxelShapes.union(Block.createCuboidShape(1, 3, 1, 15, 16, 15), private static final VoxelShape SHAPE_TOP = Shapes.or(Block.box(1, 3, 1, 15, 16, 15), SHAPE_BOTTOM);
SHAPE_BOTTOM);
public LargeAmaranitaBlock() { public LargeAmaranitaBlock() {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT)
.luminance((state) -> (state.getValue(SHAPE) == TripleShape.TOP) ? 15 : 0) .breakByTool(FabricToolTags.SHEARS)
.breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS).breakByHand(true)); .breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> (state.getValue(SHAPE) == TripleShape.TOP) ? 15 : 0));
} }
@Override @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; return state.getValue(SHAPE) == TripleShape.TOP ? SHAPE_TOP : SHAPE_BOTTOM;
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) || state.is(EndBlocks.MOSSY_DRAGON_BONE);
|| state.is(EndBlocks.MOSSY_DRAGON_BONE);
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) { if (shape == TripleShape.BOTTOM) {
return isTerrain(world.getBlockState(pos.below())) && world.getBlockState(pos.up()).is(this); return isTerrain(world.getBlockState(pos.below())) && world.getBlockState(pos.above()).is(this);
} else if (shape == TripleShape.TOP) { }
else if (shape == TripleShape.TOP) {
return world.getBlockState(pos.below()).is(this); 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 @Override
public OffsetType getOffsetType() { public OffsetType getOffsetType() {
return OffsetType.NONE; return OffsetType.NONE;
} }
@Override @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; return false;
} }
@Override @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; return false;
} }
} }

View file

@ -7,21 +7,21 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; 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.BlockGetter;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.LumecornShape;
import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
@ -32,17 +32,19 @@ import ru.betterend.registry.EndTags;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class LumecornBlock extends BlockBaseNotFull implements IRenderTypeable { public class LumecornBlock extends BlockBaseNotFull implements IRenderTypeable {
public static final EnumProperty<LumecornShape> SHAPE = EnumProperty.of("shape", LumecornShape.class); public static final EnumProperty<LumecornShape> SHAPE = EnumProperty.create("shape", LumecornShape.class);
private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(6, 0, 6, 10, 16, 10); private static final VoxelShape SHAPE_BOTTOM = Block.box(6, 0, 6, 10, 16, 10);
private static final VoxelShape SHAPE_TOP = Block.createCuboidShape(6, 0, 6, 10, 8, 10); private static final VoxelShape SHAPE_TOP = Block.box(6, 0, 6, 10, 8, 10);
public LumecornBlock() { public LumecornBlock() {
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).hardness(0.5F) super(FabricBlockSettings.of(Material.WOOD)
.luminance((state) -> { .breakByTool(FabricToolTags.AXES)
return state.getValue(SHAPE).getLight(); .hardness(0.5F)
})); .lightLevel((state) -> {
return state.getValue(SHAPE).getLight();
}));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
@ -52,48 +54,48 @@ public class LumecornBlock extends BlockBaseNotFull implements IRenderTypeable {
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @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; return state.getValue(SHAPE) == LumecornShape.LIGHT_TOP ? SHAPE_TOP : SHAPE_BOTTOM;
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
LumecornShape shape = state.getValue(SHAPE); LumecornShape shape = state.getValue(SHAPE);
if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL) { if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL) {
return world.getBlockState(pos.below()).isIn(EndTags.END_GROUND); return world.getBlockState(pos.below()).is(EndTags.END_GROUND);
} else if (shape == LumecornShape.LIGHT_TOP) { }
else if (shape == LumecornShape.LIGHT_TOP) {
return world.getBlockState(pos.below()).is(this); 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 @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} else { }
else {
return state; return state;
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
LumecornShape shape = state.getValue(SHAPE); LumecornShape shape = state.getValue(SHAPE);
if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) { if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) {
return Collections return Collections.singletonList(new ItemStack(EndBlocks.LUMECORN_SEED, MHelper.randRange(1, 2, MHelper.RANDOM)));
.singletonList(new ItemStack(EndBlocks.LUMECORN_SEED, MHelper.randRange(1, 2, MHelper.RANDOM)));
} }
return MHelper.RANDOM.nextBoolean() ? Collections.singletonList(new ItemStack(EndItems.LUMECORN_ROD)) return MHelper.RANDOM.nextBoolean() ? Collections.singletonList(new ItemStack(EndItems.LUMECORN_ROD)) : Collections.emptyList();
: Collections.emptyList();
} }
@Override @Override
@Environment(EnvType.CLIENT) @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); LumecornShape shape = state.getValue(SHAPE);
if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) { if (shape == LumecornShape.BOTTOM_BIG || shape == LumecornShape.BOTTOM_SMALL || shape == LumecornShape.MIDDLE) {
return new ItemStack(EndBlocks.LUMECORN_SEED); return new ItemStack(EndBlocks.LUMECORN_SEED);

View file

@ -1,11 +1,10 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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;
import net.minecraft.world.level.WorldGenLevel; 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.blocks.basis.EndPlantWithAgeBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndFeatures;
@ -15,14 +14,14 @@ public class LumecornSeedBlock extends EndPlantWithAgeBlock {
public void growAdult(WorldGenLevel world, Random random, BlockPos pos) { public void growAdult(WorldGenLevel world, Random random, BlockPos pos) {
EndFeatures.LUMECORN.getFeature().place(world, null, random, pos, null); EndFeatures.LUMECORN.getFeature().place(world, null, random, pos, null);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS); return state.is(EndBlocks.END_MOSS);
} }
@Override @Override
public AbstractBlock.OffsetType getOffsetType() { public BlockBehaviour.OffsetType getOffsetType() {
return AbstractBlock.OffsetType.NONE; return BlockBehaviour.OffsetType.NONE;
} }
} }

View file

@ -5,20 +5,20 @@ import java.util.Queue;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; 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.Level;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -26,19 +26,18 @@ import ru.betterend.registry.EndBlocks;
public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeable { public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeable {
public MengerSpongeBlock() { public MengerSpongeBlock() {
super(FabricBlockSettings.copyOf(Blocks.SPONGE).nonOpaque()); super(FabricBlockSettings.copyOf(Blocks.SPONGE).noOcclusion());
} }
@Override @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)) { if (absorbWater(world, pos)) {
world.setBlockAndUpdate(pos, EndBlocks.MENGER_SPONGE_WET.defaultBlockState()); world.setBlockAndUpdate(pos, EndBlocks.MENGER_SPONGE_WET.defaultBlockState());
} }
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) {
if (absorbWater(world, pos)) { if (absorbWater(world, pos)) {
return EndBlocks.MENGER_SPONGE_WET.defaultBlockState(); return EndBlocks.MENGER_SPONGE_WET.defaultBlockState();
} }
@ -46,46 +45,44 @@ public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeab
} }
private boolean absorbWater(LevelAccessor world, BlockPos pos) { private boolean absorbWater(LevelAccessor world, BlockPos pos) {
Queue<Pair<BlockPos, Integer>> queue = Lists.newLinkedList(); Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
queue.add(new Pair<BlockPos, Integer>(pos, 0)); queue.add(new Tuple<BlockPos, Integer>(pos, 0));
int i = 0; int i = 0;
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
Pair<BlockPos, Integer> pair = queue.poll(); Tuple<BlockPos, Integer> pair = queue.poll();
BlockPos blockPos = (BlockPos) pair.getLeft(); BlockPos blockPos = (BlockPos) pair.getA();
int j = (Integer) pair.getRight(); int j = (Integer) pair.getB();
Direction[] var8 = Direction.values(); Direction[] var8 = Direction.values();
int var9 = var8.length; int var9 = var8.length;
for (int var10 = 0; var10 < var9; ++var10) { for (int var10 = 0; var10 < var9; ++var10) {
Direction direction = var8[var10]; Direction direction = var8[var10];
BlockPos blockPos2 = blockPos.offset(direction); BlockPos blockPos2 = blockPos.relative(direction);
BlockState blockState = world.getBlockState(blockPos2); BlockState blockState = world.getBlockState(blockPos2);
FluidState fluidState = world.getFluidState(blockPos2); FluidState fluidState = world.getFluidState(blockPos2);
Material material = blockState.getMaterial(); Material material = blockState.getMaterial();
if (fluidState.isIn(FluidTags.WATER)) { if (fluidState.is(FluidTags.WATER)) {
if (blockState.getBlock() instanceof FluidDrainable && ((FluidDrainable) blockState.getBlock()) if (blockState.getBlock() instanceof BucketPickup && ((BucketPickup) blockState.getBlock()).takeLiquid(world, blockPos2, blockState) != Fluids.EMPTY) {
.tryDrainFluid(world, blockPos2, blockState) != Fluids.EMPTY) {
++i; ++i;
if (j < 6) { if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1)); queue.add(new Tuple<BlockPos, Integer>(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; ++i;
if (j < 6) { if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1)); queue.add(new Tuple<BlockPos, Integer>(blockPos2, j + 1));
} }
} else if (material == Material.UNDERWATER_PLANT }
|| material == Material.REPLACEABLE_UNDERWATER_PLANT) { else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) {
BlockEntity blockEntity = blockState.getBlock().hasBlockEntity() BlockEntity blockEntity = blockState.getBlock().isEntityBlock() ? world.getBlockEntity(blockPos2) : null;
? world.getBlockEntity(blockPos2) dropResources(blockState, world, blockPos2, blockEntity);
: null; world.setBlock(blockPos2, Blocks.AIR.defaultBlockState(), 3);
dropStacks(blockState, world, blockPos2, blockEntity);
world.setBlockAndUpdate(blockPos2, Blocks.AIR.defaultBlockState(), 3);
++i; ++i;
if (j < 6) { if (j < 6) {
queue.add(new Pair<BlockPos, Integer>(blockPos2, j + 1)); queue.add(new Tuple<BlockPos, Integer>(blockPos2, j + 1));
} }
} }
} }
@ -98,7 +95,7 @@ public class MengerSpongeBlock extends BlockBaseNotFull implements IRenderTypeab
return i > 0; return i > 0;
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;

View file

@ -5,20 +5,20 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; 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.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.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -27,27 +27,26 @@ import ru.betterend.util.BlocksHelper;
public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTypeable { public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTypeable {
public MengerSpongeWetBlock() { public MengerSpongeWetBlock() {
super(FabricBlockSettings.copyOf(Blocks.WET_SPONGE).nonOpaque()); super(FabricBlockSettings.copyOf(Blocks.WET_SPONGE).noOcclusion());
} }
@Override @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 (world.getDimension().isUltrawarm()) { if (world.dimensionType().ultraWarm()) {
world.setBlockAndUpdate(pos, EndBlocks.MENGER_SPONGE.defaultBlockState(), 3); world.setBlock(pos, EndBlocks.MENGER_SPONGE.defaultBlockState(), 3);
world.syncWorldEvent(2009, pos, 0); world.levelEvent(2009, pos, 0);
world.playLocalSound((Player) null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundSource.BLOCKS, 1.0F, world.playSound((Player) null, pos, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 1.0F, (1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F);
(1.0F + world.getRandom().nextFloat() * 0.2F) * 0.7F);
} }
} }
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { 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) { if (direction != Direction.UP) {
BlockPos blockPos = pos.relative(direction); BlockPos blockPos = pos.relative(direction);
BlockState blockState = world.getBlockState(blockPos); 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 x = (double) pos.getX();
double y = (double) pos.getY(); double y = (double) pos.getY();
double z = (double) pos.getZ(); double z = (double) pos.getZ();
@ -55,20 +54,24 @@ public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTyp
y -= 0.05; y -= 0.05;
x += random.nextDouble(); x += random.nextDouble();
z += random.nextDouble(); z += random.nextDouble();
} else { }
else {
y += random.nextDouble() * 0.8; y += random.nextDouble() * 0.8;
if (direction.getAxis() == Direction.Axis.X) { if (direction.getAxis() == Direction.Axis.X) {
z += random.nextDouble(); z += random.nextDouble();
if (direction == Direction.EAST) { if (direction == Direction.EAST) {
++x; ++x;
} else { }
else {
x += 0.05; x += 0.05;
} }
} else { }
else {
x += random.nextDouble(); x += random.nextDouble();
if (direction == Direction.SOUTH) { if (direction == Direction.SOUTH) {
++z; ++z;
} else { }
else {
z += 0.05; z += 0.05;
} }
} }
@ -80,25 +83,24 @@ public class MengerSpongeWetBlock extends BlockBaseNotFull implements IRenderTyp
} }
@Override @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); BlocksHelper.setWithUpdate(world, pos, Blocks.AIR);
if (!world.isClientSide()) { 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())) { 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, ItemEntity drop = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
new ItemStack(this)); world.addFreshEntity(drop);
world.spawnEntity(drop);
} }
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public FluidState getFluidState(BlockState state) { public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getStill(false); return Fluids.WATER.getSource(false);
} }
} }

View file

@ -5,27 +5,27 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.WorldView; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.chunk.light.ChunkLightProvider; 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.blocks.basis.EndPillarBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class MossyDragonBoneBlock extends EndPillarBlock { public class MossyDragonBoneBlock extends EndPillarBlock {
public MossyDragonBoneBlock() { public MossyDragonBoneBlock() {
super(FabricBlockSettings.copyOf(Blocks.BONE_BLOCK).hardness(0.5F).ticksRandomly()); super(FabricBlockSettings.copyOf(Blocks.BONE_BLOCK).hardness(0.5F).randomTicks());
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -34,25 +34,25 @@ public class MossyDragonBoneBlock extends EndPillarBlock {
} }
return Collections.singletonList(new ItemStack(EndBlocks.DRAGON_BONE_BLOCK)); return Collections.singletonList(new ItemStack(EndBlocks.DRAGON_BONE_BLOCK));
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { 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) { @Override
BlockPos blockPos = pos.up(); public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) {
BlockState blockState = worldView.getBlockState(blockPos); BlockPos blockPos = pos.above();
if (blockState.is(Blocks.SNOW) && (Integer) blockState.get(SnowBlock.LAYERS) == 1) { BlockState blockState = worldView.getBlockState(blockPos);
return true; if (blockState.is(Blocks.SNOW) && blockState.getValue(SnowLayerBlock.LAYERS) == 1) {
} else if (blockState.getFluidState().getLevel() == 8) { return true;
return false; } else if (blockState.getFluidState().getAmount() == 8) {
} else { return false;
int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, } else {
blockState.getOpacity(worldView, blockPos)); int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
return i < 5; return i < 5;
} }
} }
} }

View file

@ -2,27 +2,26 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.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.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
public class MossyGlowshroomCapBlock extends BlockBase { public class MossyGlowshroomCapBlock extends BlockBase {
public static final BooleanProperty TRANSITION = BlockProperties.TRANSITION; public static final BooleanProperty TRANSITION = BlockProperties.TRANSITION;
public MossyGlowshroomCapBlock() { public MossyGlowshroomCapBlock() {
super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sounds(SoundType.WOOD)); super(FabricBlockSettings.of(Material.WOOD).breakByTool(FabricToolTags.AXES).sound(SoundType.WOOD));
this.setDefaultState(this.stateManager.defaultBlockState().with(TRANSITION, false)); this.registerDefaultState(this.stateDefinition.any().setValue(TRANSITION, false));
} }
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return this.defaultBlockState().with(TRANSITION, return this.defaultBlockState().setValue(TRANSITION, EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(ctx.getLevel().getBlockState(ctx.getClickedPos().below())));
EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(ctx.getLevel().getBlockState(ctx.getBlockPos().below())));
} }
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,10 +17,9 @@ public class MossyGlowshroomSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.MOSSY_GLOWSHROOM.getFeature(); return EndFeatures.MOSSY_GLOWSHROOM.getFeature();
} }
@Override @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.END_MOSS) return world.getBlockState(pos.below()).is(EndBlocks.END_MOSS) || world.getBlockState(pos.below()).is(EndBlocks.END_MYCELIUM);
|| world.getBlockState(pos.below()).is(EndBlocks.END_MYCELIUM);
} }
} }

View file

@ -5,26 +5,26 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.WorldView; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.chunk.light.ChunkLightProvider; 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; import ru.betterend.blocks.basis.BlockBase;
public class MossyObsidian extends BlockBase { public class MossyObsidian extends BlockBase {
public MossyObsidian() { public MossyObsidian() {
super(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).hardness(3).ticksRandomly()); super(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).hardness(3).randomTicks());
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@ -33,25 +33,24 @@ public class MossyObsidian extends BlockBase {
} }
return Collections.singletonList(new ItemStack(Blocks.OBSIDIAN)); return Collections.singletonList(new ItemStack(Blocks.OBSIDIAN));
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) { if (random.nextInt(16) == 0 && !canSurvive(state, world, pos)) {
world.setBlockAndUpdate(pos, Blocks.OBSIDIAN.defaultBlockState()); world.setBlockAndUpdate(pos, Blocks.OBSIDIAN.defaultBlockState());
} }
} }
public static boolean canSurvive(BlockState state, WorldView worldView, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader worldView, BlockPos pos) {
BlockPos blockPos = pos.up(); BlockPos blockPos = pos.above();
BlockState blockState = worldView.getBlockState(blockPos); 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; return true;
} else if (blockState.getFluidState().getLevel() == 8) { } else if (blockState.getFluidState().getAmount() == 8) {
return false; return false;
} else { } else {
int i = ChunkLightProvider.getRealisticOpacity(worldView, state, pos, blockState, blockPos, Direction.UP, int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
blockState.getOpacity(worldView, blockPos)); return i < 5;
return i < 5; }
} }
}
} }

View file

@ -4,16 +4,16 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.pathing.NavigationType;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -27,21 +27,21 @@ public class MurkweedBlock extends EndPlantBlock {
double v = random.nextDouble() * 0.1; double v = random.nextDouble() * 0.1;
world.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, v, v, v); world.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, v, v, v);
} }
@Override @Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (entity instanceof LivingEntity && !((LivingEntity) entity).hasMobEffect(MobEffects.BLINDNESS)) { if (entity instanceof LivingEntity && !((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS)) {
((LivingEntity) entity).addMobEffect(new MobEffectInstance(MobEffects.BLINDNESS, 50)); ((LivingEntity) entity).addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 50));
} }
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.SHADOW_GRASS); return state.is(EndBlocks.SHADOW_GRASS);
} }
@Override @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; return false;
} }
} }

View file

@ -5,20 +5,20 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.enchantment.EnchantmentHelper; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; 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.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
@ -27,28 +27,28 @@ public class NeedlegrassBlock extends EndPlantBlock {
@Override @Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
entity.damage(DamageSource.CACTUS, 0.1F); entity.hurt(DamageSource.CACTUS, 0.1F);
} }
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} else { }
else {
return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM))); return Lists.newArrayList(new ItemStack(Items.STICK, MHelper.randRange(0, 2, MHelper.RANDOM)));
} }
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.SHADOW_GRASS); return state.is(EndBlocks.SHADOW_GRASS);
} }
@Override @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; return false;
} }
} }

View file

@ -5,137 +5,134 @@ import java.util.EnumMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.Axis;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.blocks.basis.BlockBaseNotFull;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.util.BlocksHelper; 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<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final DirectionProperty FACING = Properties.FACING; public static final DirectionProperty FACING = BlockStateProperties.FACING;
private static final EnumMap<Direction, VoxelShape> MEDIUM_SHAPES_OPEN = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> MEDIUM_SHAPES_OPEN = Maps.newEnumMap(Direction.class);
private static final EnumMap<Direction, VoxelShape> SMALL_SHAPES_OPEN = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> SMALL_SHAPES_OPEN = Maps.newEnumMap(Direction.class);
private static final EnumMap<Axis, VoxelShape> MEDIUM_SHAPES = Maps.newEnumMap(Axis.class); private static final EnumMap<Axis, VoxelShape> MEDIUM_SHAPES = Maps.newEnumMap(Axis.class);
private static final EnumMap<Axis, VoxelShape> SMALL_SHAPES = Maps.newEnumMap(Axis.class); private static final EnumMap<Axis, VoxelShape> SMALL_SHAPES = Maps.newEnumMap(Axis.class);
public NeonCactusBlock() { public NeonCactusBlock() {
super(FabricBlockSettings.copyOf(Blocks.CACTUS).luminance(state -> { super(FabricBlockSettings.copyOf(Blocks.CACTUS).lightLevel(state -> {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.TOP) { if (shape == TripleShape.TOP) {
return 15; return 15;
} }
return shape == TripleShape.MIDDLE ? 13 : 10; return shape == TripleShape.MIDDLE ? 13 : 10;
})); }));
setDefaultState( registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false).setValue(FACING, Direction.UP).setValue(SHAPE, TripleShape.TOP));
getDefaultState().with(WATERLOGGED, false).with(FACING, Direction.UP).with(SHAPE, TripleShape.TOP));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE, WATERLOGGED, FACING); stateManager.add(SHAPE, WATERLOGGED, FACING);
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
LevelAccessor worldAccess = ctx.getLevel(); LevelAccessor worldAccess = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos(); BlockPos blockPos = ctx.getClickedPos();
return this.defaultBlockState() return this.defaultBlockState().setValue(WATERLOGGED, worldAccess.getFluidState(blockPos).getType() == Fluids.WATER).setValue(FACING, ctx.getClickedFace());
.with(WATERLOGGED, worldAccess.getFluidState(blockPos).getFluid() == Fluids.WATER)
.with(FACING, ctx.getSide());
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING); return BlocksHelper.rotateHorizontal(state, rotation, FACING);
} }
@Override @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING); return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
} }
@Override @Override
public FluidState getFluidState(BlockState state) { 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 @Override
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
BlockPos pos, BlockPos posFrom) {
if ((Boolean) state.getValue(WATERLOGGED)) { 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; return state;
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @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); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) { if (shape == TripleShape.BOTTOM) {
return VoxelShapes.fullCube(); return Shapes.block();
} }
Direction dir = state.getValue(FACING); Direction dir = state.getValue(FACING);
BlockState next = view.getBlockState(pos.relative(dir)); BlockState next = view.getBlockState(pos.relative(dir));
if (next.is(this)) { if (next.is(this)) {
Axis axis = dir.getAxis(); Axis axis = dir.getAxis();
return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES.get(axis) : SMALL_SHAPES.get(axis); 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); return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES_OPEN.get(dir) : SMALL_SHAPES_OPEN.get(dir);
} }
} }
static { static {
MEDIUM_SHAPES.put(Axis.X, Block.createCuboidShape(0, 2, 2, 16, 14, 14)); MEDIUM_SHAPES.put(Axis.X, Block.box(0, 2, 2, 16, 14, 14));
MEDIUM_SHAPES.put(Axis.Y, Block.createCuboidShape(2, 0, 2, 14, 16, 14)); MEDIUM_SHAPES.put(Axis.Y, Block.box(2, 0, 2, 14, 16, 14));
MEDIUM_SHAPES.put(Axis.Z, Block.createCuboidShape(2, 2, 0, 14, 14, 16)); MEDIUM_SHAPES.put(Axis.Z, Block.box(2, 2, 0, 14, 14, 16));
SMALL_SHAPES.put(Axis.X, Block.createCuboidShape(0, 4, 4, 16, 12, 12)); SMALL_SHAPES.put(Axis.X, Block.box(0, 4, 4, 16, 12, 12));
SMALL_SHAPES.put(Axis.Y, Block.createCuboidShape(4, 0, 4, 12, 16, 12)); SMALL_SHAPES.put(Axis.Y, Block.box(4, 0, 4, 12, 16, 12));
SMALL_SHAPES.put(Axis.Z, Block.createCuboidShape(4, 4, 0, 12, 12, 16)); SMALL_SHAPES.put(Axis.Z, Block.box(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.UP, Block.box(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.DOWN, Block.box(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.NORTH, Block.box(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.SOUTH, Block.box(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.WEST, Block.box(2, 2, 2, 16, 14, 14));
MEDIUM_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 2, 2, 14, 14, 14)); MEDIUM_SHAPES_OPEN.put(Direction.EAST, Block.box(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.UP, Block.box(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.DOWN, Block.box(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.NORTH, Block.box(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.SOUTH, Block.box(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.WEST, Block.box(4, 4, 4, 16, 12, 12));
SMALL_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 4, 4, 12, 12, 12)); SMALL_SHAPES_OPEN.put(Direction.EAST, Block.box(0, 4, 4, 12, 12, 12));
} }
} }

View file

@ -2,10 +2,9 @@ package ru.betterend.blocks;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.world.level.block.Block;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry; 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.blocks.basis.PedestalBlock;
import ru.betterend.patterns.Patterns; import ru.betterend.patterns.Patterns;
@ -14,7 +13,7 @@ public class PedestalVanilla extends PedestalBlock {
public PedestalVanilla(Block parent) { public PedestalVanilla(Block parent) {
super(parent); super(parent);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
@ -22,7 +21,7 @@ public class PedestalVanilla extends PedestalBlock {
Map<String, String> textures = new HashMap<String, String>() { Map<String, String> textures = new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%mod%", blockId.getNamespace()); put("%mod%", blockId.getNamespace() );
put("%top%", "polished_" + name); put("%top%", "polished_" + name);
put("%base%", "polished_" + name); put("%base%", "polished_" + name);
put("%pillar%", name + "_pillar"); put("%pillar%", name + "_pillar");

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,9 +17,9 @@ public class PythadendronSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.PYTHADENDRON_TREE.getFeature(); return EndFeatures.PYTHADENDRON_TREE.getFeature();
} }
@Override @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); return world.getBlockState(pos.below()).is(EndBlocks.CHORUS_NYLIUM);
} }
} }

View file

@ -7,34 +7,34 @@ import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; 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.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack; 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.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; 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.BlockProperties.TripleShape;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
@ -47,89 +47,94 @@ import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IRenderTypeable { 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_BOTTOM = Block.box(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_MIDDLE_TOP = Block.box(2, 0, 2, 14, 16, 14);
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
public RespawnObeliskBlock() { 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; return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? 0 : 15;
})); }));
} }
@Override @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; return (state.getValue(SHAPE) == TripleShape.BOTTOM) ? VOXEL_SHAPE_BOTTOM : VOXEL_SHAPE_MIDDLE_TOP;
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(SHAPE); stateManager.add(SHAPE);
} }
@Override @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++) { 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 false;
} }
} }
return true; return true;
} }
@Override @Override
public void onPlaced(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
ItemStack itemStack) {
state = this.defaultBlockState(); state = this.defaultBlockState();
BlocksHelper.setWithUpdate(world, pos, state.with(SHAPE, TripleShape.BOTTOM)); BlocksHelper.setWithUpdate(world, pos, state.setValue(SHAPE, TripleShape.BOTTOM));
BlocksHelper.setWithUpdate(world, pos.up(), state.with(SHAPE, TripleShape.MIDDLE)); BlocksHelper.setWithUpdate(world, pos.above(), state.setValue(SHAPE, TripleShape.MIDDLE));
BlocksHelper.setWithUpdate(world, pos.up(2), state.with(SHAPE, TripleShape.TOP)); BlocksHelper.setWithUpdate(world, pos.above(2), state.setValue(SHAPE, TripleShape.TOP));
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) { if (shape == TripleShape.BOTTOM) {
if (world.getBlockState(pos.up()).is(this)) { if (world.getBlockState(pos.above()).is(this)) {
return state; return state;
} else { }
else {
return Blocks.AIR.defaultBlockState(); 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; return state;
} else { }
else {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} }
} else { }
else {
if (world.getBlockState(pos.below()).is(this)) { if (world.getBlockState(pos.below()).is(this)) {
return state; return state;
} else { }
else {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} }
} }
} }
@Override @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()) { if (player.isCreative()) {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.MIDDLE) { if (shape == TripleShape.MIDDLE) {
BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR); 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 @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(SHAPE) == TripleShape.BOTTOM) { if (state.getValue(SHAPE) == TripleShape.BOTTOM) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} else { }
else {
return Lists.newArrayList(); return Lists.newArrayList();
} }
} }
@ -138,12 +143,12 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getBlockProvider(); return ((IColorProvider) EndBlocks.AURORA_CRYSTAL).getProvider();
} }
@Override @Override
public ItemColor getItemProvider() { public ItemColor getItemProvider() {
return (stack, tintIndex) -> { return (stack, tintIndex) -> {
@ -152,20 +157,20 @@ public class RespawnObeliskBlock extends BlockBase implements IColorProvider, IR
} }
@Override @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) {
BlockHitResult hit) { ItemStack itemStack = player.getItemInHand(hand);
ItemStack itemStack = player.getStackInHand(hand);
boolean canActivate = itemStack.getItem() == EndItems.AMBER_GEM && itemStack.getCount() > 5; 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()) { if (!world.isClientSide && !(itemStack.getItem() instanceof BlockItem) && !player.isCreative()) {
ServerPlayer serverPlayerEntity = (ServerPlayer) player; 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; return InteractionResult.FAIL;
} else if (!world.isClientSide) { }
else if (!world.isClientSide) {
ServerPlayer serverPlayerEntity = (ServerPlayer) player; ServerPlayer serverPlayerEntity = (ServerPlayer) player;
serverPlayerEntity.setSpawnPoint(world.dimension(), pos, 0.0F, false, false); serverPlayerEntity.setRespawnPosition(world.dimension(), pos, 0.0F, false, false);
serverPlayerEntity.sendMessage(new TranslatableText("message.betterend.set_spawn"), true); serverPlayerEntity.displayClientMessage(new TranslatableComponent("message.betterend.set_spawn"), true);
double px = pos.getX() + 0.5; double px = pos.getX() + 0.5;
double py = pos.getY() + 0.5; double py = pos.getY() + 0.5;
double pz = pos.getZ() + 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) { if (state.getValue(SHAPE) == TripleShape.BOTTOM) {
py1 += 1; py1 += 1;
py2 += 2; py2 += 2;
} else if (state.getValue(SHAPE) == TripleShape.MIDDLE) { }
else if (state.getValue(SHAPE) == TripleShape.MIDDLE) {
py1 += 0; py1 += 0;
py2 += 1; py2 += 1;
} else { }
else {
py1 -= 2; py1 -= 2;
} }
((ServerLevel) world).sendParticles(particle, px, py1, pz, 20, 0.14, 0.5, 0.14, 0.1); ((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); ((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, world.playSound(null, px, py, py, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1F, 1F);
1F); if (!player.isCreative()) {
if (!player.isCreative()) { itemStack.shrink(6);
itemStack.decrement(6); }
}
} }
return player.isCreative() ? ActionResult.PASS : ActionResult.success(world.isClientSide); return player.isCreative() ? InteractionResult.PASS : InteractionResult.sidedSuccess(world.isClientSide);
} }
} }

View file

@ -2,10 +2,10 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block; 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.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; 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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -13,13 +13,12 @@ public class RunedFlavolite extends BlockBase {
public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE; public static final BooleanProperty ACTIVATED = BlockProperties.ACTIVE;
public RunedFlavolite() { public RunedFlavolite() {
super(FabricBlockSettings.copyOf(EndBlocks.FLAVOLITE.polished) super(FabricBlockSettings.copyOf(EndBlocks.FLAVOLITE.polished).resistance(Blocks.OBSIDIAN.getExplosionResistance()).lightLevel(state -> {
.resistance(Blocks.OBSIDIAN.getExplosionResistance()).luminance(state -> { return state.getValue(ACTIVATED) ? 8 : 0;
return state.getValue(ACTIVATED) ? 8 : 0; }));
})); this.registerDefaultState(stateDefinition.any().setValue(ACTIVATED, false));
this.setDefaultState(stateManager.defaultBlockState().with(ACTIVATED, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(ACTIVATED); stateManager.add(ACTIVATED);

View file

@ -1,24 +1,24 @@
package ru.betterend.blocks; 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.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.ShapeContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.level.BlockGetter;
import ru.betterend.blocks.basis.EndCropBlock; import ru.betterend.blocks.basis.EndCropBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
public class ShadowBerryBlock extends EndCropBlock { 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() { public ShadowBerryBlock() {
super(EndItems.SHADOW_BERRY_RAW, EndBlocks.SHADOW_GRASS); super(EndItems.SHADOW_BERRY_RAW, EndBlocks.SHADOW_GRASS);
} }
@Override @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; return SHAPE;
} }
} }

View file

@ -4,10 +4,10 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; 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.core.BlockPos;
import net.minecraft.world.level.Level; 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; import ru.betterend.registry.EndParticles;
public class ShadowGrassBlock extends EndTerrainBlock { 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) { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
super.animateTick(state, world, pos, random); super.animateTick(state, world, pos, random);
if (random.nextInt(32) == 0) { if (random.nextInt(32) == 0) {
world.addParticle(EndParticles.BLACK_SPORE, (double) pos.getX() + random.nextDouble(), 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);
(double) pos.getY() + 1.1D, (double) pos.getZ() + random.nextDouble(), 0.0D, 0.0D, 0.0D);
} }
} }
} }

View file

@ -4,31 +4,31 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.Direction; 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.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.blocks.basis.BlockBase;
import ru.betterend.entity.SilkMothEntity; import ru.betterend.entity.SilkMothEntity;
import ru.betterend.registry.EndEntities; import ru.betterend.registry.EndEntities;
@ -37,36 +37,35 @@ import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class SilkMothHiveBlock extends BlockBase { 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 static final IntegerProperty FULLNESS = BlockProperties.FULLNESS;
public SilkMothHiveBlock() { public SilkMothHiveBlock() {
super(FabricBlockSettings.of(Material.WOOD).hardness(0.5F).resistance(0.1F).sounds(SoundType.WOOL).nonOpaque() super(FabricBlockSettings.of(Material.WOOD).breakByHand(true).hardness(0.5F).resistance(0.1F).sound(SoundType.WOOL).noOcclusion().randomTicks());
.ticksRandomly().breakByHand(true)); this.registerDefaultState(defaultBlockState().setValue(FULLNESS, 0));
this.setDefaultState(getDefaultState().with(FULLNESS, 0));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(FACING, FULLNESS); stateManager.add(FACING, FULLNESS);
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
Direction dir = ctx.getPlayerFacing().getOpposite(); Direction dir = ctx.getHorizontalDirection().getOpposite();
return this.defaultBlockState().with(FACING, dir); return this.defaultBlockState().setValue(FACING, dir);
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING); return BlocksHelper.rotateHorizontal(state, rotation, FACING);
} }
@Override @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING); return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
Direction dir = state.getValue(FACING); Direction dir = state.getValue(FACING);
@ -74,45 +73,42 @@ public class SilkMothHiveBlock extends BlockBase {
if (!world.getBlockState(spawn).isAir()) { if (!world.getBlockState(spawn).isAir()) {
return; return;
} }
int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> { int count = world.getEntities(EndEntities.SILK_MOTH, new AABB(pos).inflate(16), (entity) -> { return true; }).size();
return true;
}).size();
if (count > 6) { if (count > 6) {
return; return;
} }
SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world); 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.moveTo(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.toYRot(), 0);
moth.setVelocity(new Vec3d(dir.getOffsetX() * 0.4, 0, dir.getOffsetZ() * 0.4)); moth.setDeltaMovement(new Vec3(dir.getStepX() * 0.4, 0, dir.getStepZ() * 0.4));
moth.setHive(world, pos); moth.setHive(world, pos);
world.spawnEntity(moth); world.addFreshEntity(moth);
world.playLocalSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); world.playSound(null, pos, SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1);
} }
@Override @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) {
BlockHitResult hit) { if (hand == InteractionHand.MAIN_HAND) {
if (hand == Hand.MAIN_HAND) { ItemStack stack = player.getMainHandItem();
ItemStack stack = player.getMainHandStack(); if (stack.getItem().is(FabricToolTags.SHEARS) && state.getValue(FULLNESS) == 3) {
if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.getValue(FULLNESS) == 3) { BlocksHelper.setWithUpdate(world, pos, state.setValue(FULLNESS, 0));
BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0));
Direction dir = state.getValue(FACING); Direction dir = state.getValue(FACING);
double px = pos.getX() + dir.getOffsetX() + 0.5; double px = pos.getX() + dir.getStepX() + 0.5;
double py = pos.getY() + dir.getOffsetY() + 0.5; double py = pos.getY() + dir.getStepY() + 0.5;
double pz = pos.getZ() + dir.getOffsetZ() + 0.5; double pz = pos.getZ() + dir.getStepZ() + 0.5;
ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(8, 16, world.getRandom())); ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(8, 16, world.getRandom()));
ItemEntity entity = new ItemEntity(world, px, py, pz, drop); ItemEntity entity = new ItemEntity(world, px, py, pz, drop);
world.spawnEntity(entity); world.addFreshEntity(entity);
if (world.getRandom().nextInt(4) == 0) { if (world.getRandom().nextInt(4) == 0) {
drop = new ItemStack(EndItems.SILK_MOTH_MATRIX); drop = new ItemStack(EndItems.SILK_MOTH_MATRIX);
entity = new ItemEntity(world, px, py, pz, drop); entity = new ItemEntity(world, px, py, pz, drop);
world.spawnEntity(entity); world.addFreshEntity(entity);
} }
if (!player.isCreative()) { 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;
} }
} }

View file

@ -6,39 +6,39 @@ import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.shape.VoxelShape; 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.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.BlockBase;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.entity.SilkMothEntity; import ru.betterend.entity.SilkMothEntity;
@ -50,24 +50,23 @@ import ru.betterend.util.MHelper;
public class SilkMothNestBlock extends BlockBase implements IRenderTypeable { public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
public static final BooleanProperty ACTIVE = BlockProperties.ACTIVE; 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; public static final IntegerProperty FULLNESS = BlockProperties.FULLNESS;
private static final VoxelShape TOP = createCuboidShape(6, 0, 6, 10, 16, 10); private static final VoxelShape TOP = box(6, 0, 6, 10, 16, 10);
private static final VoxelShape BOTTOM = createCuboidShape(0, 0, 0, 16, 16, 16); private static final VoxelShape BOTTOM = box(0, 0, 0, 16, 16, 16);
public SilkMothNestBlock() { public SilkMothNestBlock() {
super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sounds(SoundType.WOOL).nonOpaque() super(FabricBlockSettings.of(Material.WOOL).hardness(0.5F).resistance(0.1F).sound(SoundType.WOOL).noOcclusion().randomTicks());
.ticksRandomly()); this.registerDefaultState(defaultBlockState().setValue(ACTIVE, true).setValue(FULLNESS, 0));
this.setDefaultState(getDefaultState().with(ACTIVE, true).with(FULLNESS, 0));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(ACTIVE, FACING, FULLNESS); stateManager.add(ACTIVE, FACING, FULLNESS);
} }
@Override @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; return state.getValue(ACTIVE) ? BOTTOM : TOP;
} }
@ -75,54 +74,53 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
Direction dir = ctx.getPlayerFacing().getOpposite(); Direction dir = ctx.getHorizontalDirection().getOpposite();
return this.defaultBlockState().with(FACING, dir); return this.defaultBlockState().setValue(FACING, dir);
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
BlockPos pos, BlockPos neighborPos) {
if (!state.getValue(ACTIVE)) { if (!state.getValue(ACTIVE)) {
if (sideCoversSmallSquare(world, pos.up(), Direction.DOWN) if (canSupportCenter(world, pos.above(), Direction.DOWN) || world.getBlockState(pos.above()).is(BlockTags.LEAVES)) {
|| world.getBlockState(pos.up()).isIn(BlockTags.LEAVES)) {
return state; return state;
} else { }
else {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} }
} }
return state; return state;
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING); return BlocksHelper.rotateHorizontal(state, rotation, FACING);
} }
@Override @Override
public BlockState mirror(BlockState state, BlockMirror mirror) { public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING); return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return state.getValue(ACTIVE) ? Collections.singletonList(new ItemStack(this)) : Collections.emptyList(); return state.getValue(ACTIVE) ? Collections.singletonList(new ItemStack(this)) : Collections.emptyList();
} }
@Override @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()) { if (!state.getValue(ACTIVE) && player.isCreative()) {
BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR); BlocksHelper.setWithUpdate(world, pos.below(), Blocks.AIR);
} }
BlockState up = world.getBlockState(pos.up()); BlockState up = world.getBlockState(pos.above());
if (up.is(this) && !up.get(ACTIVE)) { if (up.is(this) && !up.getValue(ACTIVE)) {
BlocksHelper.setWithUpdate(world, pos.up(), Blocks.AIR); BlocksHelper.setWithUpdate(world, pos.above(), Blocks.AIR);
} }
super.onBreak(world, pos, state, player); super.playerWillDestroy(world, pos, state, player);
} }
@Override @Override
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
if (!state.getValue(ACTIVE)) { if (!state.getValue(ACTIVE)) {
@ -136,44 +134,40 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
if (!world.getBlockState(spawn).isAir()) { if (!world.getBlockState(spawn).isAir()) {
return; return;
} }
int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> { int count = world.getEntities(EndEntities.SILK_MOTH, new AABB(pos).inflate(16), (entity) -> { return true; }).size();
return true;
}).size();
if (count > 6) { if (count > 6) {
return; return;
} }
SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world); 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.moveTo(spawn.getX() + 0.5, spawn.getY() + 0.5, spawn.getZ() + 0.5, dir.toYRot(), 0);
moth.setVelocity(new Vec3d(dir.getOffsetX() * 0.4, 0, dir.getOffsetZ() * 0.4)); moth.setDeltaMovement(new Vec3(dir.getStepX() * 0.4, 0, dir.getStepZ() * 0.4));
moth.setHive(world, pos); moth.setHive(world, pos);
world.spawnEntity(moth); world.addFreshEntity(moth);
world.playLocalSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1); world.playSound(null, pos, SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1, 1);
} }
@Override @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) {
BlockHitResult hit) { if (hand == InteractionHand.MAIN_HAND) {
if (hand == Hand.MAIN_HAND) { ItemStack stack = player.getMainHandItem();
ItemStack stack = player.getMainHandStack(); if (stack.getItem().is(FabricToolTags.SHEARS) && state.getValue(ACTIVE) && state.getValue(FULLNESS) == 3) {
if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.getValue(ACTIVE) BlocksHelper.setWithUpdate(world, pos, state.setValue(FULLNESS, 0));
&& state.getValue(FULLNESS) == 3) {
BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0));
Direction dir = state.getValue(FACING); Direction dir = state.getValue(FACING);
double px = pos.getX() + dir.getOffsetX() + 0.5; double px = pos.getX() + dir.getStepX() + 0.5;
double py = pos.getY() + dir.getOffsetY() + 0.5; double py = pos.getY() + dir.getStepY() + 0.5;
double pz = pos.getZ() + dir.getOffsetZ() + 0.5; double pz = pos.getZ() + dir.getStepZ() + 0.5;
ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(1, 4, world.getRandom())); ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(1, 4, world.getRandom()));
ItemEntity entity = new ItemEntity(world, px, py, pz, drop); 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())); drop = new ItemStack(EndItems.SILK_MOTH_MATRIX, MHelper.randRange(1, 3, world.getRandom()));
entity = new ItemEntity(world, px, py, pz, drop); entity = new ItemEntity(world, px, py, pz, drop);
world.spawnEntity(entity); world.addFreshEntity(entity);
if (!player.isCreative()) { 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;
} }
} }

View file

@ -1,33 +1,31 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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.core.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndFeatures; import ru.betterend.registry.EndFeatures;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class SmallAmaranitaBlock extends EndPlantBlock { 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 @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) return state.is(EndBlocks.SANGNUM) || state.is(EndBlocks.MOSSY_OBSIDIAN) || state.is(EndBlocks.MOSSY_DRAGON_BONE);
|| state.is(EndBlocks.MOSSY_DRAGON_BONE);
} }
@Override @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); BlockPos bigPos = growBig(world, pos);
if (bigPos != null) { if (bigPos != null) {
if (EndFeatures.GIGANTIC_AMARANITA.getFeature().place(world, null, random, 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); EndFeatures.LARGE_AMARANITA.getFeature().place(world, null, random, pos, null);
} }
@Override @Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3d vec3d = state.getModelOffset(view, pos); Vec3 vec3d = state.getOffset(view, pos);
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
} }
private BlockPos growBig(ServerLevel world, BlockPos pos) { private BlockPos growBig(ServerLevel world, BlockPos pos) {
for (int x = -1; x < 2; x++) { for (int x = -1; x < 2; x++) {
for (int z = -1; z < 2; z++) { for (int z = -1; z < 2; z++) {
@ -58,20 +56,22 @@ public class SmallAmaranitaBlock extends EndPlantBlock {
} }
return null; return null;
} }
private boolean checkFrame(ServerLevel world, BlockPos pos) { private boolean checkFrame(ServerLevel world, BlockPos pos) {
return world.getBlockState(pos).is(this) && world.getBlockState(pos.south()).is(this) return world.getBlockState(pos).is(this) &&
&& world.getBlockState(pos.east()).is(this) && world.getBlockState(pos.south().east()).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) { private void replaceMushroom(ServerLevel world, BlockPos pos) {
if (world.getBlockState(pos).is(this)) { if (world.getBlockState(pos).is(this)) {
BlocksHelper.setWithUpdate(world, pos, Blocks.AIR); BlocksHelper.setWithUpdate(world, pos, Blocks.AIR);
} }
} }
@Override @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; return random.nextInt(8) == 0;
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.server.level.ServerLevel;
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.BlockGetter;
import net.minecraft.world.level.Level; 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.blocks.basis.AttachedBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -36,64 +36,67 @@ import ru.betterend.registry.EndFeatures;
import ru.betterend.registry.EndTags; import ru.betterend.registry.EndTags;
import ru.betterend.util.BlocksHelper; 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<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public SmallJellyshroomBlock() { public SmallJellyshroomBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.NETHER_WART) super(FabricBlockSettings.of(Material.PLANT)
.breakByHand(true).noCollision()); .breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.NETHER_WART)
.noCollission());
} }
@Override @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)); return BOUNDING_SHAPES.get(state.getValue(FACING));
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|| EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} else { }
else {
return Lists.newArrayList(); return Lists.newArrayList();
} }
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = state.getValue(FACING); Direction direction = state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite()); BlockPos blockPos = pos.relative(direction.getOpposite());
BlockState support = world.getBlockState(blockPos); 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 @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
static { static {
BOUNDING_SHAPES.put(Direction.UP, Block.createCuboidShape(3, 0, 3, 13, 16, 13)); BOUNDING_SHAPES.put(Direction.UP, Block.box(3, 0, 3, 13, 16, 13));
BOUNDING_SHAPES.put(Direction.DOWN, Block.createCuboidShape(3, 0, 3, 13, 16, 13)); BOUNDING_SHAPES.put(Direction.DOWN, Block.box(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.NORTH, Shapes.box(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.SOUTH, Shapes.box(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.WEST, Shapes.box(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.EAST, Shapes.box(0.0, 0.0, 0.0, 0.5, 1.0, 1.0));
} }
@Override @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(FACING) == Direction.UP && world.getBlockState(pos.below()).isIn(EndTags.END_GROUND); return state.getValue(FACING) == Direction.UP && world.getBlockState(pos.below()).is(EndTags.END_GROUND);
} }
@Override @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; return random.nextInt(16) == 0;
} }
@Override @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); BlocksHelper.setWithUpdate(world, pos, Blocks.AIR);
EndFeatures.JELLYSHROOM.getFeature().place(world, null, random, pos, null); EndFeatures.JELLYSHROOM.getFeature().place(world, null, random, pos, null);
} }

View file

@ -2,13 +2,18 @@ package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.block.SoundType;
import net.minecraft.world.level.material.Material;
import ru.betterend.blocks.basis.EndPillarBlock; import ru.betterend.blocks.basis.EndPillarBlock;
public class SmaragdantCrystalBlock extends EndPillarBlock { public class SmaragdantCrystalBlock extends EndPillarBlock {
public SmaragdantCrystalBlock() { public SmaragdantCrystalBlock() {
super(FabricBlockSettings.of(Material.GLASS).breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS) super(FabricBlockSettings.of(Material.GLASS)
.luminance(15).hardness(1F).resistance(1F).nonOpaque()); .breakByTool(FabricToolTags.PICKAXES)
.luminance(15)
.hardness(1F)
.resistance(1F)
.noOcclusion()
.sound(SoundType.GLASS));
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.AttachedBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
public class SmaragdantCrystalShardBlock extends AttachedBlock public class SmaragdantCrystalShardBlock extends AttachedBlock implements IRenderTypeable, SimpleWaterloggedBlock, LiquidBlockContainer {
implements IRenderTypeable, Waterloggable, FluidFillable {
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public SmaragdantCrystalShardBlock() { public SmaragdantCrystalShardBlock() {
super(FabricBlockSettings.of(Material.STONE).materialColor(MaterialColor.COLOR_GREEN) super(FabricBlockSettings.of(Material.STONE)
.breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS).luminance(15).requiresTool() .materialColor(MaterialColor.COLOR_GREEN)
.noCollision()); .breakByTool(FabricToolTags.PICKAXES)
.luminance(15)
.sound(SoundType.GLASS)
.requiresCorrectToolForDrops()
.noCollission());
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
super.createBlockStateDefinition(stateManager); super.createBlockStateDefinition(stateManager);
stateManager.add(WATERLOGGED); stateManager.add(WATERLOGGED);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @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); return !state.getValue(WATERLOGGED);
} }
@Override @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); return !state.getValue(WATERLOGGED);
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState state = super.getPlacementState(ctx); BlockState state = super.getStateForPlacement(ctx);
if (state != null) { if (state != null) {
WorldView worldView = ctx.getLevel(); LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos(); BlockPos blockPos = ctx.getClickedPos();
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER;
return state.with(WATERLOGGED, water); return state.setValue(WATERLOGGED, water);
} }
return null; return null;
} }
@Override @Override
public FluidState getFluidState(BlockState state) { 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 @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)); return BOUNDING_SHAPES.get(state.getValue(FACING));
} }
@Override @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); Direction direction = (Direction) state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite()); BlockPos blockPos = pos.relative(direction.getOpposite());
return world.getBlockState(blockPos).isSideSolidFullSquare(world, blockPos, direction); return world.getBlockState(blockPos).isFaceSturdy(world, blockPos, direction);
} }
static { static {
BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.125, 0.0, 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, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 1.0, 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, VoxelShapes.cuboid(0.125, 0.125, 0.125, 0.875F, 0.875F, 1.0)); BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(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.SOUTH, Shapes.box(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.WEST, Shapes.box(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.EAST, Shapes.box(0.0, 0.125, 0.125, 0.875F, 0.875F, 0.875F));
} }
} }

View file

@ -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.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; 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.blocks.basis.AttachedBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -41,79 +41,81 @@ import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
import ru.betterend.util.MHelper; 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<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public static final IntegerProperty AGE = IntegerProperty.of("age", 0, 2); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 2);
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public SulphurCrystalBlock() { public SulphurCrystalBlock() {
super(FabricBlockSettings.of(Material.STONE).materialColor(MaterialColor.COLOR_YELLOW) super(FabricBlockSettings.of(Material.STONE)
.breakByTool(FabricToolTags.PICKAXES).sounds(SoundType.GLASS).requiresTool().noCollision()); .materialColor(MaterialColor.COLOR_YELLOW)
.breakByTool(FabricToolTags.PICKAXES)
.sound(SoundType.GLASS)
.requiresCorrectToolForDrops()
.noCollission());
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
super.createBlockStateDefinition(stateManager); super.createBlockStateDefinition(stateManager);
stateManager.add(AGE, WATERLOGGED); stateManager.add(AGE, WATERLOGGED);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return state.getValue(AGE) < 2 ? Collections.emptyList() return state.getValue(AGE) < 2 ? Collections.emptyList() : Lists.newArrayList(new ItemStack(EndItems.CRYSTALLINE_SULPHUR, MHelper.randRange(1, 3, MHelper.RANDOM)));
: Lists.newArrayList(
new ItemStack(EndItems.CRYSTALLINE_SULPHUR, MHelper.randRange(1, 3, MHelper.RANDOM)));
} }
@Override @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); return !state.getValue(WATERLOGGED);
} }
@Override @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); return !state.getValue(WATERLOGGED);
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState state = super.getPlacementState(ctx); BlockState state = super.getStateForPlacement(ctx);
if (state != null) { if (state != null) {
WorldView worldView = ctx.getLevel(); LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getBlockPos(); BlockPos blockPos = ctx.getClickedPos();
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER; boolean water = worldView.getFluidState(blockPos).getType() == Fluids.WATER;
return state.with(WATERLOGGED, water); return state.setValue(WATERLOGGED, water);
} }
return null; return null;
} }
@Override @Override
public FluidState getFluidState(BlockState state) { 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 @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)); return BOUNDING_SHAPES.get(state.getValue(FACING));
} }
@Override @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); Direction direction = (Direction) state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite()); BlockPos blockPos = pos.relative(direction.getOpposite());
return world.getBlockState(blockPos).is(EndBlocks.BRIMSTONE); return world.getBlockState(blockPos).is(EndBlocks.BRIMSTONE);
} }
static { static {
BOUNDING_SHAPES.put(Direction.UP, VoxelShapes.cuboid(0.125, 0.0, 0.125, 0.875F, 0.5, 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, VoxelShapes.cuboid(0.125, 0.5, 0.125, 0.875F, 1.0, 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, VoxelShapes.cuboid(0.125, 0.125, 0.5, 0.875F, 0.875F, 1.0)); BOUNDING_SHAPES.put(Direction.NORTH, Shapes.box(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.SOUTH, Shapes.box(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.WEST, Shapes.box(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.EAST, Shapes.box(0.0, 0.125, 0.125, 0.5, 0.875F, 0.875F));
} }
} }

View file

@ -4,14 +4,14 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; 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.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.util.Mth;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.blocks.basis.VineBlock; import ru.betterend.blocks.basis.VineBlock;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
@ -19,13 +19,13 @@ import ru.betterend.util.MHelper;
public class TenaneaFlowersBlock extends VineBlock implements IColorProvider { public class TenaneaFlowersBlock extends VineBlock implements IColorProvider {
public static final Vec3i[] COLORS; public static final Vec3i[] COLORS;
public TenaneaFlowersBlock() { public TenaneaFlowersBlock() {
super(15); super(15);
} }
@Override @Override
public BlockColor getBlockProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {
long i = (MHelper.getRandom(pos.getX(), pos.getZ()) & 63) + pos.getY(); long i = (MHelper.getRandom(pos.getX(), pos.getZ()) & 63) + pos.getY();
double delta = i * 0.1; double delta = i * 0.1;
@ -33,15 +33,15 @@ public class TenaneaFlowersBlock extends VineBlock implements IColorProvider {
int index2 = (index + 1) & 3; int index2 = (index + 1) & 3;
delta -= index; delta -= index;
index &= 3; index &= 3;
Vec3i color1 = COLORS[index]; Vec3i color1 = COLORS[index];
Vec3i color2 = COLORS[index2]; Vec3i color2 = COLORS[index2];
int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX())); int r = MHelper.floor(Mth.lerp(delta, color1.getX(), color2.getX()));
int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY())); int g = MHelper.floor(Mth.lerp(delta, color1.getY(), color2.getY()));
int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ())); int b = MHelper.floor(Mth.lerp(delta, color1.getZ(), color2.getZ()));
float[] hsb = MHelper.fromRGBtoHSB(r, g, b); float[] hsb = MHelper.fromRGBtoHSB(r, g, b);
return MHelper.fromHSBtoRGB(hsb[0], MHelper.max(0.5F, hsb[1]), hsb[2]); 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); return MHelper.color(255, 255, 255);
}; };
} }
@Override @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; return false;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) { public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
super.animateTick(state, world, pos, 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); world.addParticle(EndParticles.TENANEA_PETAL, x, y, z, 0, 0, 0);
} }
} }
static { static {
COLORS = new Vec3i[] { new Vec3i(250, 111, 222), new Vec3i(167, 89, 255), new Vec3i(120, 207, 239), COLORS = new Vec3i[] {
new Vec3i(255, 87, 182) }; new Vec3i(250, 111, 222),
new Vec3i(167, 89, 255),
new Vec3i(120, 207, 239),
new Vec3i(255, 87, 182)
};
} }
} }

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -17,9 +17,9 @@ public class TenaneaSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.LUCERNIA.getFeature(); return EndFeatures.LUCERNIA.getFeature();
} }
@Override @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); return world.getBlockState(pos.below()).is(EndBlocks.RUTISCUS);
} }
} }

View file

@ -1,14 +1,17 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.block.SoundType;
import ru.betterend.blocks.basis.BlockBase; import ru.betterend.blocks.basis.BlockBase;
public class TerminiteBlock extends BlockBase { public class TerminiteBlock extends BlockBase {
public TerminiteBlock() { public TerminiteBlock() {
super(FabricBlockSettings.of(Material.METAL, MaterialColor.field_25708).hardness(7F).resistance(9F) super(FabricBlockSettings.of(Material.METAL, MaterialColor.WARPED_WART_BLOCK)
.requiresTool().sounds(SoundType.METAL)); .hardness(7F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.METAL));
} }
} }

View file

@ -6,15 +6,15 @@ import ru.betterend.blocks.basis.EndPlantBlock;
public class TerrainPlantBlock extends EndPlantBlock { public class TerrainPlantBlock extends EndPlantBlock {
private final Block[] ground; private final Block[] ground;
public TerrainPlantBlock(Block... ground) { public TerrainPlantBlock(Block... ground) {
super(true); super(true);
this.ground = ground; this.ground = ground;
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
for (Block block : ground) { for (Block block: ground) {
if (state.is(block)) { if (state.is(block)) {
return true; return true;
} }

View file

@ -4,11 +4,11 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; 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.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.DoublePlantBlock;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -18,32 +18,32 @@ public class TwistedUmbrellaMossBlock extends EndPlantBlock {
public TwistedUmbrellaMossBlock() { public TwistedUmbrellaMossBlock() {
super(11); super(11);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS);
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) {
return true; return true;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) {
return 1F; return 1F;
}
@Override
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return world.isEmptyBlock(pos.above());
} }
@Override @Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
return world.isAir(pos.up()); int rot = world.random.nextInt(4);
} BlockState bs = EndBlocks.TWISTED_UMBRELLA_MOSS_TALL.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot);
@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);
BlocksHelper.setWithoutUpdate(world, pos, bs); 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));
} }
} }

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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.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.blocks.basis.DoublePlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -14,14 +13,13 @@ public class TwistedUmbrellaMossTallBlock extends DoublePlantBlock {
public TwistedUmbrellaMossTallBlock() { public TwistedUmbrellaMossTallBlock() {
super(12); super(12);
} }
@Override @Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { 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, ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(EndBlocks.TWISTED_UMBRELLA_MOSS));
new ItemStack(EndBlocks.TWISTED_UMBRELLA_MOSS)); world.addFreshEntity(item);
world.spawnEntity(item);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS);

View file

@ -4,11 +4,11 @@ import java.util.Random;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; 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.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; 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.DoublePlantBlock;
import ru.betterend.blocks.basis.EndPlantBlock; import ru.betterend.blocks.basis.EndPlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -18,32 +18,32 @@ public class UmbrellaMossBlock extends EndPlantBlock {
public UmbrellaMossBlock() { public UmbrellaMossBlock() {
super(11); super(11);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS);
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public boolean hasEmissiveLighting(BlockView world, BlockPos pos) { public boolean hasEmissiveLighting(BlockGetter world, BlockPos pos) {
return true; return true;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) { public float getAmbientOcclusionLightLevel(BlockGetter world, BlockPos pos) {
return 1F; return 1F;
}
@Override
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return world.isEmptyBlock(pos.above());
} }
@Override @Override
public boolean canGrow(Level world, Random random, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
return world.isAir(pos.up()); int rot = world.random.nextInt(4);
} BlockState bs = EndBlocks.UMBRELLA_MOSS_TALL.defaultBlockState().setValue(DoublePlantBlock.ROTATION, rot);
@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);
BlocksHelper.setWithoutUpdate(world, pos, bs); 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));
} }
} }

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.util.Random; 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.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.blocks.basis.DoublePlantBlock;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
@ -14,14 +13,13 @@ public class UmbrellaMossTallBlock extends DoublePlantBlock {
public UmbrellaMossTallBlock() { public UmbrellaMossTallBlock() {
super(12); super(12);
} }
@Override @Override
public void grow(ServerLevel world, Random random, BlockPos pos, BlockState state) { 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, ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(EndBlocks.UMBRELLA_MOSS));
new ItemStack(EndBlocks.UMBRELLA_MOSS)); world.addFreshEntity(item);
world.spawnEntity(item);
} }
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS); return state.is(EndBlocks.END_MOSS) || state.is(EndBlocks.END_MYCELIUM) || state.is(EndBlocks.JUNGLE_MOSS);

View file

@ -1,22 +1,22 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.Blocks; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; 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.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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
@ -24,34 +24,32 @@ import ru.betterend.util.BlocksHelper;
public class UmbrellaTreeClusterBlock extends BlockBase { public class UmbrellaTreeClusterBlock extends BlockBase {
public static final BooleanProperty NATURAL = BlockProperties.NATURAL; public static final BooleanProperty NATURAL = BlockProperties.NATURAL;
public UmbrellaTreeClusterBlock() { 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)); .luminance(15));
setDefaultState(stateManager.defaultBlockState().with(NATURAL, false)); registerDefaultState(stateDefinition.any().setValue(NATURAL, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(NATURAL); stateManager.add(NATURAL);
} }
@Override @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) {
BlockHitResult hit) { ItemStack stack = player.getMainHandItem();
ItemStack stack = player.getMainHandStack();
if (stack.getItem() == Items.GLASS_BOTTLE) { if (stack.getItem() == Items.GLASS_BOTTLE) {
if (!player.isCreative()) { if (!player.isCreative()) {
stack.decrement(1); stack.shrink(1);
} }
stack = new ItemStack(EndItems.UMBRELLA_CLUSTER_JUICE); stack = new ItemStack(EndItems.UMBRELLA_CLUSTER_JUICE);
player.giveItemStack(stack); player.addItem(stack);
world.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.ITEM_BOTTLE_FILL, world.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, 1, 1, false);
SoundSource.BLOCKS, 1, 1, false); BlocksHelper.setWithUpdate(world, pos, EndBlocks.UMBRELLA_TREE_CLUSTER_EMPTY.defaultBlockState().setValue(NATURAL, state.getValue(NATURAL)));
BlocksHelper.setWithUpdate(world, pos, return InteractionResult.SUCCESS;
EndBlocks.UMBRELLA_TREE_CLUSTER_EMPTY.defaultBlockState().with(NATURAL, state.getValue(NATURAL)));
return ActionResult.SUCCESS;
} }
return ActionResult.FAIL; return InteractionResult.FAIL;
} }
} }

View file

@ -3,37 +3,37 @@ package ru.betterend.blocks;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.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.blocks.basis.BlockBase;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class UmbrellaTreeClusterEmptyBlock extends BlockBase { public class UmbrellaTreeClusterEmptyBlock extends BlockBase {
public static final BooleanProperty NATURAL = BlockProperties.NATURAL; public static final BooleanProperty NATURAL = BlockProperties.NATURAL;
public UmbrellaTreeClusterEmptyBlock() { public UmbrellaTreeClusterEmptyBlock() {
super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK).materialColor(MaterialColor.COLOR_PURPLE) super(FabricBlockSettings.copyOf(Blocks.NETHER_WART_BLOCK)
.ticksRandomly()); .materialColor(MaterialColor.COLOR_PURPLE)
setDefaultState(stateManager.defaultBlockState().with(NATURAL, false)); .randomTicks());
registerDefaultState(stateDefinition.any().setValue(NATURAL, false));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(NATURAL); stateManager.add(NATURAL);
} }
@Override @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) { if (state.getValue(NATURAL) && random.nextInt(16) == 0) {
BlocksHelper.setWithUpdate(world, pos, BlocksHelper.setWithUpdate(world, pos, EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState().setValue(UmbrellaTreeClusterBlock.NATURAL, true));
EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState().with(UmbrellaTreeClusterBlock.NATURAL, true));
} }
} }
} }

View file

@ -9,20 +9,20 @@ import com.google.common.collect.Lists;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; 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.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; 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.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.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
@ -34,66 +34,67 @@ import ru.betterend.util.MHelper;
public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderTypeable, BlockPatterned { public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderTypeable, BlockPatterned {
public static final IntegerProperty COLOR = BlockProperties.COLOR; public static final IntegerProperty COLOR = BlockProperties.COLOR;
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0);
public UmbrellaTreeMembraneBlock() { public UmbrellaTreeMembraneBlock() {
super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK)); super(FabricBlockSettings.copyOf(Blocks.SLIME_BLOCK));
} }
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
double px = ctx.getBlockPos().getX() * 0.1; double px = ctx.getClickedPos().getX() * 0.1;
double py = ctx.getBlockPos().getY() * 0.1; double py = ctx.getClickedPos().getY() * 0.1;
double pz = ctx.getBlockPos().getZ() * 0.1; double pz = ctx.getClickedPos().getZ() * 0.1;
return this.defaultBlockState().with(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4)); return this.defaultBlockState().setValue(COLOR, MHelper.floor(NOISE.eval(px, py, pz) * 3.5 + 4));
} }
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
stateManager.add(COLOR); stateManager.add(COLOR);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(COLOR) > 0) { if (state.getValue(COLOR) > 0) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} else { }
return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) else {
: Collections.emptyList(); return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) : Collections.emptyList();
} }
} }
@Override @Override
public String getStatesPattern(Reader data) { public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath(); String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block); return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block); return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
} }
@Override @Override
public ResourceLocation statePatternId() { public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE; return Patterns.STATE_SIMPLE;
} }
@Override @Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { public boolean propagatesSkylightDown(BlockState state, BlockGetter world, BlockPos pos) {
return state.getValue(COLOR) > 0; return state.getValue(COLOR) > 0;
} }
@Environment(EnvType.CLIENT) @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) { if (state.getValue(COLOR) > 0) {
return super.isSideInvisible(state, stateFrom, direction); return super.skipRendering(state, stateFrom, direction);
} else { }
else {
return false; return false;
} }
} }

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos; 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 net.minecraft.world.level.levelgen.feature.Feature;
import ru.betterend.blocks.basis.FeatureSaplingBlock; import ru.betterend.blocks.basis.FeatureSaplingBlock;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
@ -18,12 +18,12 @@ public class UmbrellaTreeSaplingBlock extends FeatureSaplingBlock {
protected Feature<?> getFeature() { protected Feature<?> getFeature() {
return EndFeatures.UMBRELLA_TREE.getFeature(); return EndFeatures.UMBRELLA_TREE.getFeature();
} }
@Override @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); return world.getBlockState(pos.below()).is(EndBlocks.JUNGLE_MOSS);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.TRANSLUCENT; return ERenderLayer.TRANSLUCENT;

Some files were not shown because too many files have changed in this diff Show more