did so much work, and it's still not over, I'm going to die

This commit is contained in:
Ell 2021-12-15 14:26:42 +01:00
parent 559c4165e8
commit 584514944b
75 changed files with 1115 additions and 1184 deletions

View file

@ -4,26 +4,26 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import java.util.Random;
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState {
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState, EntityBlock {
public BlockAncientLeaves() {
super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS));
@ -36,26 +36,15 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
return "ancient_leaves";
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new BlockEntityAncientLeaves();
}
@Override
public boolean hasBlockEntity(BlockState state) {
return true;
}
@Override
@OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() {
public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xE55B97;
}
@Override
@OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() {
public ItemColor getItemColor() {
return (stack, tintIndex) -> 0xE55B97;
}
@ -63,7 +52,7 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
super.animateTick(stateIn, levelIn, pos, rand);
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.down()).isOpaqueCube(levelIn, pos)) {
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.below()).isCollisionShapeFullBlock(levelIn, pos)) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) {
@ -86,14 +75,14 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) {
levelIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState());
levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState());
}
}
}
}
@Override
public boolean ticksRandomly(BlockState state) {
public boolean isRandomlyTicking(BlockState state) {
return true;
}
@ -101,4 +90,10 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAncientLeaves(pos, state);
}
}

View file

@ -4,17 +4,17 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
public class BlockAncientLog extends RotatedPillarBlock implements IModItem, ICustomBlockState {
private final String baseName;
public BlockAncientLog(String baseName) {
super(Properties.create(Material.WOOD, MaterialColor.PURPLE).hardnessAndResistance(2.0F).sound(SoundType.WOOD));
super(Properties.of(Material.WOOD, MaterialColor.COLOR_PURPLE).strength(2.0F).sound(SoundType.WOOD));
this.baseName = baseName;
ModRegistry.add(this);
}

View file

@ -3,33 +3,34 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.gen.LevelGenAncientTree;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.state.StateContainer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.event.ForgeEventFactory;
import java.util.Random;
import java.util.function.Supplier;
public class BlockAncientSapling extends BushBlock implements IGrowable, IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
protected static final VoxelShape SHAPE = Block.makeCuboidShape(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
public class BlockAncientSapling extends BushBlock implements BonemealableBlock, IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
protected static final VoxelShape SHAPE = box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
public BlockAncientSapling() {
super(Properties.create(Material.PLANTS).hardnessAndResistance(0.0F).sound(SoundType.PLANT));
super(Properties.of(Material.GRASS).strength(0.0F).sound(SoundType.GRASS));
ModRegistry.add(this);
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@ -38,9 +39,8 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
if (!level.isClientSide) {
super.randomTick(state, level, pos, random);
if (level.getLight(pos.up()) >= 9 && random.nextInt(7) == 0) {
this.grow(level, random, pos, state);
}
if (level.getLightEmission(pos.above()) >= 9 && random.nextInt(7) == 0)
this.performBonemeal(level, random, pos, state);
}
}
@ -50,26 +50,26 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(SaplingBlock.STAGE);
}
@Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) {
public boolean isValidBonemealTarget(BlockGetter p_50897_, BlockPos p_50898_, BlockState p_50899_, boolean p_50900_) {
return true;
}
@Override
public boolean canUseBonemeal(Level level, Random rand, BlockPos pos, BlockState state) {
return level.rand.nextFloat() < 0.45F;
public boolean isBonemealSuccess(Level level, Random rand, BlockPos pos, BlockState state) {
return level.random.nextFloat() < 0.45F;
}
@Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
if (state.get(SaplingBlock.STAGE) == 0) {
level.setBlockState(pos, state.func_235896_a_(SaplingBlock.STAGE), 4);
public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
if (state.getValue(SaplingBlock.STAGE) == 0) {
level.setBlock(pos, state.cycle(SaplingBlock.STAGE), 4);
} else if (ForgeEventFactory.saplingGrowTree(level, rand, pos)) {
ModFeatures.ANCIENT_TREE.func_241855_a(level, level.getChunkProvider().getChunkGenerator(), rand, pos, LevelGenAncientTree.CONFIG);
ModFeatures.Configured.ANCIENT_TREE.place(level, level.getChunkSource().getGenerator(), rand, pos);
}
}
@ -85,6 +85,6 @@ public class BlockAncientSapling extends BushBlock implements IGrowable, IModIte
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalContainer;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
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.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockAnimalContainer extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
private static final VoxelShape SHAPE = makeCuboidShape(5, 0, 5, 11, 13, 11);
private static final VoxelShape SHAPE = box(5, 0, 5, 11, 13, 11);
public BlockAnimalContainer() {
super("animal_container", BlockEntityAnimalContainer::new, Properties.from(Blocks.STONE));
super("animal_container", BlockEntityAnimalContainer::new, Properties.copy(Blocks.STONE));
}
@Override
@ -30,18 +30,18 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityAnimalContainer) {
int radius = ((BlockEntityAnimalContainer) tile).getRadius();
if (radius > 0)
return new AxisAlignedBB(pos).grow(radius);
return new AABB(pos).inflate(radius);
}
return null;
}

View file

@ -8,17 +8,17 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.INPC;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.npc.Npc;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
@ -29,8 +29,9 @@ import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockAnimalGenerator() {
super("animal_generator", BlockEntityAnimalGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
super("animal_generator", BlockEntityAnimalGenerator::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this);
}
@ -38,7 +39,7 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
if (entity.level.isClientSide || entity.level.getGameTime() % 40 != 0 || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return;
CompoundTag data = entity.getPersistentData();
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
@ -48,13 +49,12 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@SubscribeEvent
public void onEntityDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
if (entity.level.isClientSide || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return;
BlockPos pos = entity.getPosition();
BlockPos pos = entity.getOnPos();
Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator))
if (!(tile instanceof BlockEntityAnimalGenerator gen))
return false;
BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile;
CompoundTag data = entity.getPersistentData();
data.putBoolean(NaturesAura.MOD_ID + ":no_drops", true);
@ -62,7 +62,7 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
if (gen.isBusy())
return false;
boolean child = entity.isChild();
boolean child = entity.isBaby();
float timeMod = child ? 0.5F : 1;
float amountMod = child ? 0.667F : 1;
@ -73,9 +73,9 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
return false;
gen.setGenerationValues(time, amount);
BlockPos genPos = gen.getPos();
BlockPos genPos = gen.getBlockPos();
PacketHandler.sendToAllAround(entity.level, pos, 32, new PacketParticles(
(float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
(float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
child ? 1 : 0,
(int) (entity.getEyeHeight() * 10F),
genPos.getX(), genPos.getY(), genPos.getZ()));
@ -100,8 +100,8 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).inflate(5);
}
@Override

View file

@ -1,11 +1,12 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAnimalSpawner;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
public class BlockAnimalSpawner extends BlockContainerImpl {
public BlockAnimalSpawner() {
super("animal_spawner", BlockEntityAnimalSpawner::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
super("animal_spawner", BlockEntityAnimalSpawner::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
}
}

View file

@ -1,29 +1,29 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraDetector;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
public class BlockAuraDetector extends BlockContainerImpl {
public BlockAuraDetector() {
super("aura_detector", BlockEntityAuraDetector::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
super("aura_detector", BlockEntityAuraDetector::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) {
public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAuraDetector)
return ((BlockEntityAuraDetector) tile).redstonePower;
if (tile instanceof BlockEntityAuraDetector detector)
return detector.redstonePower;
else
return 0;
}

View file

@ -1,48 +1,44 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderAuraTimer;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.entity.player.Player;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
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.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.Random;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockState, ITESRProvider<BlockEntityAuraTimer>, ICustomRenderType {
private static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 15, 15);
private static final VoxelShape SHAPE = box(1, 0, 1, 15, 15, 15);
public BlockAuraTimer() {
super("aura_timer", BlockEntityAuraTimer::new, Properties.from(Blocks.SMOOTH_STONE));
this.setDefaultState(this.getDefaultState().with(BlockStateProperties.POWERED, false));
super("aura_timer", BlockEntityAuraTimer::new, Properties.copy(Blocks.SMOOTH_STONE));
this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.POWERED, false));
}
@Override
@ -51,46 +47,45 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
@OnlyIn(Dist.CLIENT)
public Tuple<BlockEntityType<BlockEntityAuraTimer>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityAuraTimer>>>> getTESR() {
public Tuple<BlockEntityType<? extends BlockEntityAuraTimer>, Supplier<BlockEntityRendererProvider<BlockEntityAuraTimer>>> getTESR() {
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutout;
return RenderType::cutout;
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(BlockStateProperties.POWERED);
}
@Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) {
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
return Helper.putStackOnTile(player, handIn, pos, 0, true);
}
@Override
public boolean canProvidePower(BlockState state) {
public boolean isSignalSource(BlockState state) {
return true;
}
@Override
public int getWeakPower(BlockState state, IBlockReader level, BlockPos pos, Direction side) {
return state.get(BlockStateProperties.POWERED) ? 15 : 0;
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction side) {
return state.getValue(BlockStateProperties.POWERED) ? 15 : 0;
}
@Override
public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.tick(state, levelIn, pos, random);
if (state.get(BlockStateProperties.POWERED))
levelIn.setBlockState(pos, state.with(BlockStateProperties.POWERED, false));
if (state.getValue(BlockStateProperties.POWERED))
levelIn.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.POWERED, false));
}
}

View file

@ -3,31 +3,32 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAutoCrafter;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.world.item.context.BlockPlaceContext;
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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.Material;
public class BlockAutoCrafter extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public BlockAutoCrafter() {
super("auto_crafter", BlockEntityAutoCrafter::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD));
super("auto_crafter", BlockEntityAutoCrafter::new, Properties.of(Material.WOOD).strength(1.5F).sound(SoundType.WOOD));
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return super.getStateForPlacement(context).with(FACING, context.getPlayer().getHorizontalFacing());
public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(FACING, context.getPlayer().getDirection());
}
@Override

View file

@ -3,25 +3,26 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityBlastFurnaceBooster;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.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.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F);
public BlockBlastFurnaceBooster() {
super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::new, Block.Properties.from(Blocks.BLAST_FURNACE).setLightLevel(s -> 0));
super("blast_furnace_booster", BlockEntityBlastFurnaceBooster::new, Block.Properties.copy(Blocks.BLAST_FURNACE).lightLevel(s -> 0));
}
@Override
@ -30,19 +31,19 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return super.getStateForPlacement(context).with(FACING, context.getPlacementHorizontalFacing().getOpposite());
public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection().getOpposite());
}
@Override

View file

@ -4,29 +4,30 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
public class BlockCatalyst extends BlockImpl implements ICustomBlockState {
public static final BooleanProperty NETHER = BlockNatureAltar.NETHER;
public BlockCatalyst(String baseName, Properties properties) {
super(baseName, properties);
this.setDefaultState(this.getDefaultState().with(NETHER, false));
this.registerDefaultState(this.defaultBlockState().setValue(NETHER, false));
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
public BlockState getStateForPlacement(BlockPlaceContext context) {
boolean nether = IAuraType.forLevel(context.getLevel()).isSimilar(NaturesAuraAPI.TYPE_NETHER);
return super.getStateForPlacement(context).with(NETHER, nether);
return super.getStateForPlacement(context).setValue(NETHER, nether);
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(NETHER);
}

View file

@ -3,11 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChorusGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.level.block.Blocks;
public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockChorusGenerator() {
super("chorus_generator", BlockEntityChorusGenerator::new, Properties.from(Blocks.END_STONE));
super("chorus_generator", BlockEntityChorusGenerator::new, Properties.copy(Blocks.END_STONE));
}
@Override

View file

@ -7,33 +7,28 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12);
private static final VoxelShape SHAPE = box(4, 4, 4, 12, 12, 12);
public BlockChunkLoader() {
super("chunk_loader", BlockEntityChunkLoader::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
super("chunk_loader", BlockEntityChunkLoader::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
}
@Override
@ -43,12 +38,12 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range();
if (range > 0) {
return new AxisAlignedBB(
return new AABB(
(pos.getX() - range) >> 4 << 4,
0,
(pos.getZ() - range) >> 4 << 4,
@ -70,8 +65,8 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
int range = ((BlockEntityChunkLoader) tile).range();
for (int i = Mth.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true);
pos.getX() + levelIn.random.nextFloat(), pos.getY() + levelIn.random.nextFloat(), pos.getZ() + levelIn.random.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.random.nextFloat(), 100, 0, false, true);
}
}
}
@ -83,18 +78,13 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
public String getTranslationKey() {
return ModConfig.instance.chunkLoader.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
}
@Override
public void addInformation(ItemStack stack, @Nullable IBlockReader levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, levelIn, tooltip, flagIn);
public String getDescriptionId() {
return ModConfig.instance.chunkLoader.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
}
@Override

View file

@ -3,14 +3,13 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
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.material.Material;
import java.util.Random;
import java.util.function.Supplier;
@ -18,13 +17,13 @@ import java.util.function.Supplier;
public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState, ICustomRenderType {
public BlockDecayedLeaves() {
super("decayed_leaves", Properties.create(Material.LEAVES).hardnessAndResistance(0.2F).sound(SoundType.PLANT).notSolid().tickRandomly());
super("decayed_leaves", Properties.of(Material.LEAVES).strength(0.2F).sound(SoundType.GRASS).noOcclusion().randomTicks());
}
@Override
public void tick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
if (!level.isClientSide) {
level.setBlockState(pos, Blocks.AIR.getDefaultState());
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}
}
@ -33,13 +32,8 @@ public class BlockDecayedLeaves extends BlockImpl implements ICustomBlockState,
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
public int getOpacity(BlockState state, IBlockReader levelIn, BlockPos pos) {
return 1;
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -4,26 +4,30 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootParameters;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.ILevelReader;
import net.minecraft.level.Level;
import net.minecraft.level.gen.Heightmap;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.EntityBlock;
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.levelgen.Heightmap;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -32,52 +36,46 @@ import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Supplier;
public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType {
public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockState, ICustomItemModel, ICustomRenderType, EntityBlock {
protected static final VoxelShape SHAPE = Block.makeCuboidShape(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
protected static final VoxelShape SHAPE = box(5.0D, 0.0D, 5.0D, 11.0D, 10.0D, 11.0D);
public BlockEndFlower() {
super(Properties.create(Material.PLANTS).doesNotBlockMovement().hardnessAndResistance(0.5F).sound(SoundType.PLANT));
super(Properties.of(Material.GRASS).noCollission().strength(0.5F).sound(SoundType.GRASS));
MinecraftForge.EVENT_BUS.register(this);
ModRegistry.add(this);
ModRegistry.add(new ModTileType<>(BlockEntityEndFlower::new, this));
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
Vector3d vec3d = state.getOffset(levelIn, pos);
return SHAPE.withOffset(vec3d.x, vec3d.y, vec3d.z);
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
Vec3 vec3d = state.getOffset(levelIn, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
}
@SubscribeEvent
public void onDragonTick(LivingUpdateEvent event) {
LivingEntity living = event.getEntityLiving();
if (living.level.isClientSide || !(living instanceof EnderDragonEntity))
if (living.level.isClientSide || !(living instanceof EnderDragon dragon))
return;
EnderDragonEntity dragon = (EnderDragonEntity) living;
if (dragon.deathTicks < 150 || dragon.deathTicks % 10 != 0)
if (dragon.deathTime < 150 || dragon.deathTime % 10 != 0)
return;
for (int i = 0; i < 6; i++) {
int x = dragon.level.rand.nextInt(256) - 128;
int z = dragon.level.rand.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
if (!dragon.level.isBlockLoaded(pos))
int x = dragon.level.random.nextInt(256) - 128;
int z = dragon.level.random.nextInt(256) - 128;
BlockPos pos = new BlockPos(x, dragon.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
if (!dragon.level.isLoaded(pos))
continue;
if (dragon.level.getBlockState(pos.down()).getBlock() != Blocks.END_STONE)
if (dragon.level.getBlockState(pos.below()).getBlock() != Blocks.END_STONE)
continue;
dragon.level.setBlockState(pos, this.getDefaultState());
dragon.level.setBlockAndUpdate(pos, this.defaultBlockState());
}
}
@Override
protected boolean isValidGround(BlockState state, IBlockReader levelIn, BlockPos pos) {
return state.getBlock() == Blocks.END_STONE;
}
@Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
return levelIn.getBlockState(pos.down()).getBlock() == Blocks.END_STONE;
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
return levelIn.getBlockState(pos.below()).getBlock() == Blocks.END_STONE;
}
@Override
@ -87,29 +85,24 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Nullable
@Override
public BlockEntity createBlockEntity(BlockState state, IBlockReader level) {
return new BlockEntityEndFlower();
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityEndFlower(pos, state);
}
@Override
public boolean hasBlockEntity(BlockState state) {
return true;
public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
return willHarvest || super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
}
@Override
public boolean removedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
return willHarvest || super.removedByPlayer(state, level, pos, player, willHarvest, fluid);
}
@Override
public void harvestBlock(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
super.harvestBlock(levelIn, player, pos, state, te, stack);
levelIn.setBlockState(pos, Blocks.AIR.getDefaultState());
public void playerDestroy(Level levelIn, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity te, ItemStack stack) {
super.playerDestroy(levelIn, player, pos, state, te, stack);
levelIn.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
BlockEntity tile = builder.get(LootParameters.BLOCK_ENTITY);
BlockEntity tile = builder.getParameter(LootContextParams.BLOCK_ENTITY);
if (tile instanceof BlockEntityEndFlower && ((BlockEntityEndFlower) tile).isDrainMode)
return NonNullList.create();
return super.getDrops(state, builder);
@ -127,6 +120,6 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutout;
return RenderType::cutout;
}
}

View file

@ -6,19 +6,19 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFieldCreator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.level.Level;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -26,44 +26,44 @@ import java.util.Random;
import java.util.function.Supplier;
public class BlockFieldCreator extends BlockContainerImpl implements ICustomBlockState, ICustomRenderType {
public BlockFieldCreator() {
super("field_creator", BlockEntityFieldCreator::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).notSolid().sound(SoundType.STONE));
super("field_creator", BlockEntityFieldCreator::new, Properties.of(Material.STONE).strength(2F).noCollission().sound(SoundType.STONE));
}
@Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult p_225533_6_) {
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFieldCreator) {
if (!levelIn.isClientSide) {
String key = NaturesAura.MOD_ID + ":field_creator_pos";
CompoundTag compound = player.getPersistentData();
if (!player.isSneaking() && compound.contains(key)) {
BlockPos stored = BlockPos.fromLong(compound.getLong(key));
if (!player.isCrouching() && compound.contains(key)) {
BlockPos stored = BlockPos.of(compound.getLong(key));
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile;
if (!pos.equals(stored)) {
if (creator.isCloseEnough(stored)) {
BlockEntity otherTile = levelIn.getBlockEntity(stored);
if (otherTile instanceof BlockEntityFieldCreator) {
if (otherTile instanceof BlockEntityFieldCreator otherCreator) {
creator.connectionOffset = stored.subtract(pos);
creator.isMain = true;
creator.sendToClients();
BlockEntityFieldCreator otherCreator = (BlockEntityFieldCreator) otherTile;
otherCreator.connectionOffset = pos.subtract(stored);
otherCreator.isMain = false;
otherCreator.sendToClients();
compound.remove(key);
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".connected"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".connected"), true);
} else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos_gone"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".stored_pos_gone"), true);
} else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".too_far"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".too_far"), true);
} else
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".same_position"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".same_position"), true);
} else {
compound.putLong(key, pos.toLong());
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true);
compound.putLong(key, pos.asLong());
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".stored_pos"), true);
}
}
return InteractionResult.SUCCESS;
@ -75,21 +75,18 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFieldCreator) {
BlockEntityFieldCreator creator = (BlockEntityFieldCreator) tile;
if (creator.isCharged) {
BlockPos connected = creator.getConnectedPos();
if (connected != null)
NaturesAuraAPI.instance().spawnParticleStream(
pos.getX() + 0.25F + rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + rand.nextFloat() * 0.5F,
connected.getX() + 0.25F + rand.nextFloat() * 0.5F,
connected.getY() + 0.25F + rand.nextFloat() * 0.5F,
connected.getZ() + 0.25F + rand.nextFloat() * 0.5F,
0.65F, 0x4245f4, 1F
);
}
if (tile instanceof BlockEntityFieldCreator creator && creator.isCharged) {
BlockPos connected = creator.getConnectedPos();
if (connected != null)
NaturesAuraAPI.instance().spawnParticleStream(
pos.getX() + 0.25F + rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + rand.nextFloat() * 0.5F,
connected.getX() + 0.25F + rand.nextFloat() * 0.5F,
connected.getY() + 0.25F + rand.nextFloat() * 0.5F,
connected.getZ() + 0.25F + rand.nextFloat() * 0.5F,
0.65F, 0x4245f4, 1F
);
}
}
@ -100,6 +97,6 @@ public class BlockFieldCreator extends BlockContainerImpl implements ICustomBloc
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -4,23 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFireworkGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFireworkGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFireworkGenerator() {
super("firework_generator", BlockEntityFireworkGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
super("firework_generator", BlockEntityFireworkGenerator::new, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(4);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).inflate(4);
}
@Override

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFlowerGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockFlowerGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockFlowerGenerator() {
super("flower_generator", BlockEntityFlowerGenerator::new, Properties.create(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F));
super("flower_generator", BlockEntityFlowerGenerator::new, Properties.of(Material.WOOD).sound(SoundType.WOOD).strength(2F));
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(3, 1, 3);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).inflate(3, 1, 3);
}
@Override

View file

@ -2,13 +2,14 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.Block;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FlowerPotBlock;
import java.util.function.Supplier;
public class BlockFlowerPot extends FlowerPotBlock implements ICustomBlockState, IModItem, INoItemBlock, ICustomRenderType {
public BlockFlowerPot(Supplier<FlowerPotBlock> emptyPot, Supplier<? extends Block> block, Properties props) {
super(emptyPot, block, props);
ModRegistry.add(this);
@ -18,16 +19,16 @@ public class BlockFlowerPot extends FlowerPotBlock implements ICustomBlockState,
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models()
.withExistingParent(this.getBaseName(), "block/flower_pot_cross")
.texture("plant", "block/" + this.getFlower().getRegistryName().getPath()));
.texture("plant", "block/" + this.getContent().getRegistryName().getPath()));
}
@Override
public String getBaseName() {
return "potted_" + this.getFlower().getRegistryName().getPath();
return "potted_" + this.getContent().getRegistryName().getPath();
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutout;
return RenderType::cutout;
}
}

View file

@ -4,41 +4,41 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
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.DirectionProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nullable;
import java.util.Random;
public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlockState {
public static final DirectionProperty FACING = BlockStateProperties.FACING;
private static final VoxelShape[] SHAPES = new VoxelShape[]{
Block.makeCuboidShape(2, 12, 2, 14, 16, 14), // Down
Block.makeCuboidShape(2, 0, 2, 14, 4, 14), // Up
Block.makeCuboidShape(2, 2, 12, 14, 14, 16), // North
Block.makeCuboidShape(2, 2, 0, 14, 14, 4), // South
Block.makeCuboidShape(12, 2, 2, 16, 14, 14), // West
Block.makeCuboidShape(0, 2, 2, 4, 14, 14) // East
box(2, 12, 2, 14, 16, 14), // Down
box(2, 0, 2, 14, 4, 14), // Up
box(2, 2, 12, 14, 14, 16), // North
box(2, 2, 0, 14, 14, 4), // South
box(12, 2, 2, 16, 14, 14), // West
box(0, 2, 2, 4, 14, 14) // East
};
public BlockFurnaceHeater() {
super("furnace_heater", BlockEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
super("furnace_heater", BlockEntityFurnaceHeater::new, Properties.of(Material.STONE).strength(3F));
}
@Override
@ -50,8 +50,8 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityFurnaceHeater && ((BlockEntityFurnaceHeater) tile).isActive) {
Direction facing = stateIn.get(FACING);
if (tile instanceof BlockEntityFurnaceHeater heater && heater.isActive) {
Direction facing = stateIn.getValue(FACING);
float x;
float y;
@ -65,35 +65,35 @@ public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlo
y = 1F;
z = 0.35F + rand.nextFloat() * 0.3F;
} else {
x = facing.getZOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getXOffset() < 0 ? 1 : 0;
x = facing.getStepZ() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getStepX() < 0 ? 1 : 0;
y = 0.35F + rand.nextFloat() * 0.3F;
z = facing.getXOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getZOffset() < 0 ? 1 : 0;
z = facing.getStepX() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getStepZ() < 0 ? 1 : 0;
}
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + x, pos.getY() + y, pos.getZ() + z,
(rand.nextFloat() * 0.016F + 0.01F) * facing.getXOffset(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getYOffset(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getZOffset(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepX(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepY(),
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepZ(),
0xf46e42, rand.nextFloat() + 0.5F, 55, 0F, true, true);
}
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
return SHAPES[state.get(FACING).getIndex()];
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPES[state.getValue(FACING).ordinal()];
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return super.getStateForPlacement(context).with(FACING, context.getFace());
public BlockState getStateForPlacement(BlockPlaceContext context) {
return super.getStateForPlacement(context).setValue(FACING, context.getClickedFace());
}
@Override

View file

@ -1,29 +1,27 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderGeneratorLimitRemover;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.util.Tuple;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.material.Material;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState {
public BlockGeneratorLimitRemover() {
super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
}
@Override
public Tuple<BlockEntityType<BlockEntityGeneratorLimitRemover>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityGeneratorLimitRemover>>>> getTESR() {
public Tuple<BlockEntityType<? extends BlockEntityGeneratorLimitRemover>, Supplier<BlockEntityRendererProvider<BlockEntityGeneratorLimitRemover>>> getTESR() {
return new Tuple<>(ModTileEntities.GENERATOR_LIMIT_REMOVER, () -> RenderGeneratorLimitRemover::new);
}

View file

@ -6,104 +6,104 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.state.properties.RedstoneSide;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.ILevel;
import net.minecraft.level.ILevelReader;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RedStoneWireBlock;
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.block.state.properties.RedstoneSide;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.function.Supplier;
public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock, ICustomBlockState, ICustomItemModel, ICustomRenderType {
public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.REDSTONE_NORTH;
public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.REDSTONE_EAST;
public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.REDSTONE_SOUTH;
public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.REDSTONE_WEST;
protected static final VoxelShape[] SHAPES = new VoxelShape[]{Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.makeCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
public static final EnumProperty<RedstoneSide> NORTH = BlockStateProperties.NORTH_REDSTONE;
public static final EnumProperty<RedstoneSide> EAST = BlockStateProperties.EAST_REDSTONE;
public static final EnumProperty<RedstoneSide> SOUTH = BlockStateProperties.SOUTH_REDSTONE;
public static final EnumProperty<RedstoneSide> WEST = BlockStateProperties.WEST_REDSTONE;
protected static final VoxelShape[] SHAPES = new VoxelShape[]{box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
public BlockGoldPowder() {
super("gold_powder", Properties.from(Blocks.REDSTONE_WIRE));
this.setDefaultState(this.stateContainer.getBaseState().with(NORTH, RedstoneSide.NONE).with(EAST, RedstoneSide.NONE).with(SOUTH, RedstoneSide.NONE).with(WEST, RedstoneSide.NONE));
super("gold_powder", Properties.copy(Blocks.REDSTONE_WIRE));
this.registerDefaultState(this.defaultBlockState().setValue(NORTH, RedstoneSide.NONE).setValue(EAST, RedstoneSide.NONE).setValue(SOUTH, RedstoneSide.NONE).setValue(WEST, RedstoneSide.NONE));
}
private static int getShapeIndex(BlockState state) {
int i = 0;
boolean n = state.get(NORTH) != RedstoneSide.NONE;
boolean e = state.get(EAST) != RedstoneSide.NONE;
boolean s = state.get(SOUTH) != RedstoneSide.NONE;
boolean w = state.get(WEST) != RedstoneSide.NONE;
boolean n = state.getValue(NORTH) != RedstoneSide.NONE;
boolean e = state.getValue(EAST) != RedstoneSide.NONE;
boolean s = state.getValue(SOUTH) != RedstoneSide.NONE;
boolean w = state.getValue(WEST) != RedstoneSide.NONE;
if (n || s && !n && !e && !w) {
i |= 1 << Direction.NORTH.getHorizontalIndex();
i |= 1 << Direction.NORTH.ordinal();
}
if (e || w && !n && !e && !s) {
i |= 1 << Direction.EAST.getHorizontalIndex();
i |= 1 << Direction.EAST.ordinal();
}
if (s || n && !e && !s && !w) {
i |= 1 << Direction.SOUTH.getHorizontalIndex();
i |= 1 << Direction.SOUTH.ordinal();
}
if (w || e && !n && !s && !w) {
i |= 1 << Direction.WEST.getHorizontalIndex();
i |= 1 << Direction.WEST.ordinal();
}
return i;
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST);
}
@Override
public IBlockColor getBlockColor() {
public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> 0xf4cb42;
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPES[getShapeIndex(state)];
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
IBlockReader iblockreader = context.getLevel();
BlockPos blockpos = context.getPos();
return this.getDefaultState().with(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).with(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).with(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).with(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH));
public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockGetter iblockreader = context.getLevel();
BlockPos blockpos = context.getClickedPos();
return this.defaultBlockState().setValue(WEST, this.getSide(iblockreader, blockpos, Direction.WEST)).setValue(EAST, this.getSide(iblockreader, blockpos, Direction.EAST)).setValue(NORTH, this.getSide(iblockreader, blockpos, Direction.NORTH)).setValue(SOUTH, this.getSide(iblockreader, blockpos, Direction.SOUTH));
}
@Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, ILevel levelIn, BlockPos currentPos, BlockPos facingPos) {
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos) {
if (facing == Direction.DOWN) {
return stateIn;
} else {
return facing == Direction.UP ? stateIn.with(WEST, this.getSide(levelIn, currentPos, Direction.WEST)).with(EAST, this.getSide(levelIn, currentPos, Direction.EAST)).with(NORTH, this.getSide(levelIn, currentPos, Direction.NORTH)).with(SOUTH, this.getSide(levelIn, currentPos, Direction.SOUTH)) : stateIn.with(RedstoneWireBlock.FACING_PROPERTY_MAP.get(facing), this.getSide(levelIn, currentPos, facing));
return facing == Direction.UP ? stateIn.setValue(WEST, this.getSide(levelIn, currentPos, Direction.WEST)).setValue(EAST, this.getSide(levelIn, currentPos, Direction.EAST)).setValue(NORTH, this.getSide(levelIn, currentPos, Direction.NORTH)).setValue(SOUTH, this.getSide(levelIn, currentPos, Direction.SOUTH)) : stateIn.setValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(facing), this.getSide(levelIn, currentPos, facing));
}
}
private RedstoneSide getSide(IBlockReader levelIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.offset(face);
private RedstoneSide getSide(BlockGetter levelIn, BlockPos pos, Direction face) {
BlockPos blockpos = pos.relative(face);
BlockState blockstate = levelIn.getBlockState(blockpos);
BlockPos blockpos1 = pos.up();
BlockPos blockpos1 = pos.above();
BlockState blockstate1 = levelIn.getBlockState(blockpos1);
if (!blockstate1.isNormalCube(levelIn, blockpos1)) {
boolean flag = blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.up()))) {
if (blockstate.hasOpaqueCollisionShape(levelIn, blockpos)) {
if (!blockstate1.isCollisionShapeFullBlock(levelIn, blockpos1)) {
boolean flag = blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
if (flag && this.canConnectTo(levelIn.getBlockState(blockpos.above()))) {
if (blockstate.isCollisionShapeFullBlock(levelIn, blockpos)) {
return RedstoneSide.UP;
}
@ -111,7 +111,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
}
}
return !this.canConnectTo(blockstate) && (blockstate.isNormalCube(levelIn, blockpos) || !this.canConnectTo(levelIn.getBlockState(blockpos.down()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
return !this.canConnectTo(blockstate) && (blockstate.isCollisionShapeFullBlock(levelIn, blockpos) || !this.canConnectTo(levelIn.getBlockState(blockpos.below()))) ? RedstoneSide.NONE : RedstoneSide.SIDE;
}
protected boolean canConnectTo(BlockState blockState) {
@ -120,32 +120,32 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
}
@Override
public boolean isValidPosition(BlockState state, ILevelReader levelIn, BlockPos pos) {
BlockPos blockpos = pos.down();
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
BlockPos blockpos = pos.below();
BlockState blockstate = levelIn.getBlockState(blockpos);
return blockstate.isSolidSide(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
return blockstate.isFaceSturdy(levelIn, blockpos, Direction.UP) || blockstate.getBlock() == Blocks.HOPPER;
}
@Override
public VoxelShape getCollisionShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getCollisionShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return Shapes.empty();
}
@Override
public void onBlockAdded(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) {
public void onPlace(BlockState state, Level levelIn, BlockPos pos, BlockState oldState, boolean isMoving) {
if (oldState.getBlock() != state.getBlock() && !levelIn.isClientSide) {
for (Direction direction : Direction.Plane.VERTICAL) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
levelIn.updateNeighborsAt(pos.relative(direction), this);
}
for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1));
this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
}
for (Direction direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up());
BlockPos blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down());
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.below());
}
}
@ -153,22 +153,22 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
}
@Override
public void onReplaced(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
public void onRemove(BlockState state, Level levelIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (!isMoving && state.getBlock() != newState.getBlock()) {
super.onReplaced(state, levelIn, pos, newState, isMoving);
super.onRemove(state, levelIn, pos, newState, isMoving);
if (!levelIn.isClientSide) {
for (Direction direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
levelIn.updateNeighborsAt(pos.relative(direction), this);
}
for (Direction direction1 : Direction.Plane.HORIZONTAL) {
this.notifyWireNeighborsOfStateChange(levelIn, pos.offset(direction1));
this.notifyWireNeighborsOfStateChange(levelIn, pos.relative(direction1));
}
for (Direction direction2 : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(direction2);
if (levelIn.getBlockState(blockpos).isNormalCube(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.up());
BlockPos blockpos = pos.relative(direction2);
if (levelIn.getBlockState(blockpos).isCollisionShapeFullBlock(levelIn, blockpos)) {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.above());
} else {
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.down());
this.notifyWireNeighborsOfStateChange(levelIn, blockpos.below());
}
}
@ -179,33 +179,33 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override
public void neighborChanged(BlockState state, Level levelIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
if (!levelIn.isClientSide) {
if (!state.isValidPosition(levelIn, pos)) {
spawnDrops(state, levelIn, pos);
if (!state.canSurvive(levelIn, pos)) {
dropResources(state, levelIn, pos);
levelIn.removeBlock(pos, false);
}
}
}
@Override
public void updateDiagonalNeighbors(BlockState state, ILevel levelIn, BlockPos pos, int flags, int recursionLeft) {
BlockPos.Mutable pool = new BlockPos.Mutable();
public void updateIndirectNeighbourShapes(BlockState state, LevelAccessor levelIn, BlockPos pos, int flags, int recursionLeft) {
BlockPos.MutableBlockPos pool = new BlockPos.MutableBlockPos();
for (Direction direction : Direction.Plane.HORIZONTAL) {
RedstoneSide redstoneside = state.get(RedstoneWireBlock.FACING_PROPERTY_MAP.get(direction));
if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.setPos(pos).move(direction)).getBlock() != this) {
RedstoneSide redstoneside = state.getValue(RedStoneWireBlock.PROPERTY_BY_DIRECTION.get(direction));
if (redstoneside != RedstoneSide.NONE && levelIn.getBlockState(pool.set(pos).move(direction)).getBlock() != this) {
pool.move(Direction.DOWN);
BlockState blockstate = levelIn.getBlockState(pool);
if (blockstate.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos = pool.offset(direction.getOpposite());
BlockState blockstate1 = blockstate.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos);
replaceBlock(blockstate, blockstate1, levelIn, pool, flags);
BlockPos blockpos = pool.relative(direction.getOpposite());
BlockState blockstate1 = blockstate.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos), levelIn, pool, blockpos);
updateOrDestroy(blockstate, blockstate1, levelIn, pool, flags);
}
pool.setPos(pos).move(direction).move(Direction.UP);
pool.set(pos).move(direction).move(Direction.UP);
BlockState blockstate3 = levelIn.getBlockState(pool);
if (blockstate3.getBlock() != Blocks.OBSERVER) {
BlockPos blockpos1 = pool.offset(direction.getOpposite());
BlockState blockstate2 = blockstate3.updatePostPlacement(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1);
replaceBlock(blockstate3, blockstate2, levelIn, pool, flags);
BlockPos blockpos1 = pool.relative(direction.getOpposite());
BlockState blockstate2 = blockstate3.updateShape(direction.getOpposite(), levelIn.getBlockState(blockpos1), levelIn, pool, blockpos1);
updateOrDestroy(blockstate3, blockstate2, levelIn, pool, flags);
}
}
}
@ -214,10 +214,10 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
private void notifyWireNeighborsOfStateChange(Level levelIn, BlockPos pos) {
if (levelIn.getBlockState(pos).getBlock() == this) {
levelIn.notifyNeighborsOfStateChange(pos, this);
levelIn.updateNeighborsAt(pos, this);
for (Direction direction : Direction.values()) {
levelIn.notifyNeighborsOfStateChange(pos.offset(direction), this);
levelIn.updateNeighborsAt(pos.relative(direction), this);
}
}
}
@ -234,6 +234,6 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -4,21 +4,21 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.level.biome.BiomeColors;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -30,7 +30,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
public static final IntegerProperty STAGE = IntegerProperty.create("stage", 0, HIGHEST_STAGE);
public BlockGoldenLeaves() {
super(Properties.create(Material.LEAVES, MaterialColor.GOLD).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT));
super(Properties.of(Material.LEAVES, MaterialColor.GOLD).strength(0.2F).randomTicks().noCollission().sound(SoundType.GRASS));
ModRegistry.add(this);
}
@ -38,9 +38,9 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
BlockState state = level.getBlockState(pos);
if (state.getBlock() instanceof LeavesBlock && !(state.getBlock() instanceof BlockAncientLeaves || state.getBlock() instanceof BlockGoldenLeaves)) {
if (!level.isClientSide) {
level.setBlockState(pos, ModBlocks.GOLDEN_LEAVES.getDefaultState()
.with(DISTANCE, state.hasProperty(DISTANCE) ? state.get(DISTANCE) : 1)
.with(PERSISTENT, state.hasProperty(PERSISTENT) ? state.get(PERSISTENT) : false));
level.setBlockAndUpdate(pos, ModBlocks.GOLDEN_LEAVES.defaultBlockState()
.setValue(DISTANCE, state.hasProperty(DISTANCE) ? state.getValue(DISTANCE) : 1)
.setValue(PERSISTENT, state.hasProperty(PERSISTENT) ? state.getValue(PERSISTENT) : false));
}
return true;
}
@ -55,7 +55,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override
@OnlyIn(Dist.CLIENT)
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, Random rand) {
if (stateIn.get(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F)
if (stateIn.getValue(STAGE) == HIGHEST_STAGE && rand.nextFloat() >= 0.75F)
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + rand.nextFloat(),
pos.getY() + rand.nextFloat(),
@ -65,19 +65,19 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(STAGE);
}
@Override
@OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() {
public BlockColor getBlockColor() {
return (state, levelIn, pos, tintIndex) -> {
int color = 0xF2FF00;
if (state != null && levelIn != null && pos != null) {
int foliage = BiomeColors.getFoliageColor(levelIn, pos);
return Helper.blendColors(color, foliage, state.get(STAGE) / (float) HIGHEST_STAGE);
int foliage = BiomeColors.getAverageFoliageColor(levelIn, pos);
return Helper.blendColors(color, foliage, state.getValue(STAGE) / (float) HIGHEST_STAGE);
} else {
return color;
}
@ -86,7 +86,7 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
@Override
@OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() {
public ItemColor getItemColor() {
return (stack, tintIndex) -> 0xF2FF00;
}
@ -94,21 +94,21 @@ public class BlockGoldenLeaves extends LeavesBlock implements IModItem, IColorPr
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
super.randomTick(state, levelIn, pos, random);
if (!levelIn.isClientSide) {
int stage = state.get(STAGE);
int stage = state.getValue(STAGE);
if (stage < HIGHEST_STAGE) {
levelIn.setBlockState(pos, state.with(STAGE, stage + 1));
levelIn.setBlockAndUpdate(pos, state.setValue(STAGE, stage + 1));
}
if (stage > 1) {
BlockPos offset = pos.offset(Direction.func_239631_a_(random));
if (levelIn.isBlockLoaded(offset))
BlockPos offset = pos.relative(Direction.getRandom(random));
if (levelIn.isLoaded(offset))
convert(levelIn, offset);
}
}
}
@Override
public boolean ticksRandomly(BlockState state) {
public boolean isRandomlyTicking(BlockState p_54449_) {
return true;
}

View file

@ -5,27 +5,31 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.Player;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.IHopper;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Mth;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.Hopper;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
@ -33,23 +37,23 @@ import javax.annotation.Nullable;
public class BlockGratedChute extends BlockContainerImpl implements ICustomBlockState, ICustomItemModel {
public static final DirectionProperty FACING = HopperBlock.FACING;
private static final VoxelShape INPUT_SHAPE = Block.makeCuboidShape(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private static final VoxelShape MIDDLE_SHAPE = Block.makeCuboidShape(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
private static final VoxelShape INPUT_SHAPE = box(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private static final VoxelShape MIDDLE_SHAPE = box(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(MIDDLE_SHAPE, INPUT_SHAPE);
private static final VoxelShape COMBINED_SHAPE = Shapes.combineAndSimplify(INPUT_MIDDLE_SHAPE, IHopper.INSIDE_BOWL_SHAPE, IBooleanFunction.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(COMBINED_SHAPE, Block.makeCuboidShape(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = IHopper.INSIDE_BOWL_SHAPE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(IHopper.INSIDE_BOWL_SHAPE, Block.makeCuboidShape(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
private static final VoxelShape COMBINED_SHAPE = Shapes.join(INPUT_MIDDLE_SHAPE, Hopper.INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(COMBINED_SHAPE, box(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(COMBINED_SHAPE, box(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(COMBINED_SHAPE, box(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = Hopper.INSIDE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, box(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
public BlockGratedChute() {
super("grated_chute", BlockEntityGratedChute::new, Properties.create(Material.IRON).hardnessAndResistance(3.0F, 8.0F).sound(SoundType.METAL));
super("grated_chute", BlockEntityGratedChute::new, Properties.of(Material.METAL).strength(3.0F, 8.0F).sound(SoundType.METAL));
}
@Override
@ -58,50 +62,37 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
switch (state.get(FACING)) {
case DOWN:
return DOWN_SHAPE;
case NORTH:
return NORTH_SHAPE;
case SOUTH:
return SOUTH_SHAPE;
case WEST:
return WEST_SHAPE;
case EAST:
return EAST_SHAPE;
default:
return COMBINED_SHAPE;
}
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return switch (state.getValue(FACING)) {
case DOWN -> DOWN_SHAPE;
case NORTH -> NORTH_SHAPE;
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
case EAST -> EAST_SHAPE;
default -> COMBINED_SHAPE;
};
}
@Override
public VoxelShape getRaytraceShape(BlockState state, IBlockReader levelIn, BlockPos pos) {
switch (state.get(FACING)) {
case DOWN:
return DOWN_RAYTRACE_SHAPE;
case NORTH:
return NORTH_RAYTRACE_SHAPE;
case SOUTH:
return SOUTH_RAYTRACE_SHAPE;
case WEST:
return WEST_RAYTRACE_SHAPE;
case EAST:
return EAST_RAYTRACE_SHAPE;
default:
return IHopper.INSIDE_BOWL_SHAPE;
}
public VoxelShape getInteractionShape(BlockState state, BlockGetter levelIn, BlockPos pos) {
return switch (state.getValue(FACING)) {
case DOWN -> DOWN_RAYTRACE_SHAPE;
case NORTH -> NORTH_RAYTRACE_SHAPE;
case SOUTH -> SOUTH_RAYTRACE_SHAPE;
case WEST -> WEST_RAYTRACE_SHAPE;
case EAST -> EAST_RAYTRACE_SHAPE;
default -> Hopper.INSIDE;
};
}
@Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) {
if (!player.isSneaking())
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!player.isCrouching())
return InteractionResult.FAIL;
BlockEntity tile = levelIn.getBlockEntity(pos);
if (!(tile instanceof BlockEntityGratedChute))
if (!(tile instanceof BlockEntityGratedChute chute))
return InteractionResult.FAIL;
if (!levelIn.isClientSide) {
BlockEntityGratedChute chute = (BlockEntityGratedChute) tile;
chute.isBlacklist = !chute.isBlacklist;
chute.sendToClients();
}
@ -110,25 +101,25 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction newFacing = context.getFace().getOpposite();
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction newFacing = context.getClickedFace().getOpposite();
if (newFacing == Direction.UP)
newFacing = Direction.DOWN;
return super.getStateForPlacement(context).with(FACING, newFacing);
return super.getStateForPlacement(context).setValue(FACING, newFacing);
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}
@Override
public boolean hasComparatorInputOverride(BlockState state) {
public boolean hasAnalogOutputSignal(BlockState p_60457_) {
return true;
}
@Override
public int getComparatorInputOverride(BlockState blockState, Level levelIn, BlockPos pos) {
public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityGratedChute) {
IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler();
@ -141,8 +132,8 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}

View file

@ -2,23 +2,24 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityHopperUpgrade;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable {
public BlockHopperUpgrade() {
super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.create(Material.IRON).hardnessAndResistance(2.5F).sound(SoundType.METAL));
super("hopper_upgrade", BlockEntityHopperUpgrade::new, Properties.of(Material.METAL).strength(2.5F).sound(SoundType.METAL));
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(7);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).inflate(7);
}
@Override

View file

@ -12,7 +12,7 @@ import net.minecraft.item.BlockItemUseContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.BlockGetter;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -39,7 +39,7 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
}

View file

@ -4,7 +4,7 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityMossGenerator;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
@ -17,8 +17,8 @@ public class BlockMossGenerator extends BlockContainerImpl implements IVisualiza
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(2);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(2);
}
@Override

View file

@ -7,7 +7,7 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.IGrowable;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.BlockGetter;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
@ -36,7 +36,7 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
}
@Override
public boolean canGrow(IBlockReader levelIn, BlockPos pos, BlockState state, boolean isClient) {
public boolean canGrow(BlockGetter levelIn, BlockPos pos, BlockState state, boolean isClient) {
return levelIn.getBlockState(pos.up()).isAir(levelIn, pos.up());
}

View file

@ -10,7 +10,7 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SaplingBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
@ -59,8 +59,8 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(10);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(10);
}
@Override

View file

@ -22,7 +22,7 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.BlockGetter;
import net.minecraft.level.Level;
import java.util.function.Function;
@ -47,7 +47,7 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
}

View file

@ -12,7 +12,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
@ -42,7 +42,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
if (radius <= 0F)
return false;
BlockPos stopperPos = stopper.getPos();
if (!new AxisAlignedBB(stopperPos).grow(radius).intersects(item.getBoundingBox()))
if (!new AABB(stopperPos).grow(radius).intersects(item.getBoundingBox()))
return false;
event.setCanceled(true);
@ -57,12 +57,12 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityPickupStopper) {
double radius = ((BlockEntityPickupStopper) tile).getRadius();
if (radius > 0)
return new AxisAlignedBB(pos).grow(radius);
return new AABB(pos).grow(radius);
}
return null;
}

View file

@ -6,7 +6,7 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
@ -20,8 +20,8 @@ public class BlockPlacer extends BlockContainerImpl implements IVisualizable, IC
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(5);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(5);
}
@Override

View file

@ -10,7 +10,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.BlockGetter;
public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState {
@ -26,7 +26,7 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
}

View file

@ -8,7 +8,7 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.monster.SlimeEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
@ -33,8 +33,8 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
return new AxisAlignedBB(pos).grow(8);
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(8);
}
@Override

View file

@ -6,7 +6,7 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.Blocks;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist;
@ -19,12 +19,12 @@ public class BlockSnowCreator extends BlockContainerImpl implements IVisualizabl
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntitySnowCreator) {
int radius = ((BlockEntitySnowCreator) tile).getRange();
if (radius > 0)
return new AxisAlignedBB(pos).grow(radius);
return new AABB(pos).grow(radius);
}
return null;
}

View file

@ -16,13 +16,13 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.entity.MobEntity;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.BlockGetter;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
@ -67,7 +67,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
continue;
BlockPos lampPos = lamp.getPos();
if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)))
if (!new AABB(lampPos).grow(range).contains(new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)))
continue;
MobEntity entity = (MobEntity) event.getEntityLiving();
@ -85,18 +85,18 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
}
@Override
@OnlyIn(Dist.CLIENT)
public AxisAlignedBB getVisualizationBounds(Level level, BlockPos pos) {
public AABB getVisualizationBounds(Level level, BlockPos pos) {
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntitySpawnLamp) {
int radius = ((BlockEntitySpawnLamp) tile).getRadius();
if (radius > 0)
return new AxisAlignedBB(pos).grow(radius);
return new AABB(pos).grow(radius);
}
return null;
}

View file

@ -4,19 +4,19 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.StairsBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockState;
import java.util.function.Supplier;
public class BlockStairsNA extends StairsBlock implements IModItem, ICustomBlockState {
public class BlockStairsNA extends StairBlock implements IModItem, ICustomBlockState {
public final String textureName;
private final String baseName;
public BlockStairsNA(String baseName, String textureName, Supplier<BlockState> modelState, Block.Properties properties) {
super(modelState, properties.variableOpacity());
super(modelState, properties.dynamicShape());
this.baseName = baseName;
this.textureName = textureName;
ModRegistry.add(this);

View file

@ -2,45 +2,42 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.recipes.ModRecipes;
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.Shapes;
import net.minecraft.level.IBlockReader;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
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.crafting.Ingredient;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.mutable.MutableObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState {
@ -48,7 +45,7 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F);
public BlockWoodStand() {
super("wood_stand", BlockEntityWoodStand::new, Properties.create(Material.WOOD).hardnessAndResistance(1.5F).sound(SoundType.WOOD).harvestLevel(0).harvestTool(ToolType.AXE));
super("wood_stand", BlockEntityWoodStand::new, Properties.of(Material.WOOD).strength(1.5F).sound(SoundType.WOOD));
MinecraftForge.EVENT_BUS.register(this);
}
@ -58,28 +55,27 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel();
LevelAccessor level = event.getWorld();
BlockPos pos = event.getPos();
if (!level.isClientSide() && level instanceof Level) {
if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) {
BlockState sapling = level.getBlockState(pos);
ItemStack saplingStack = sapling.getBlock().getItem(level, pos, sapling);
ItemStack saplingStack = sapling.getBlock().getCloneItemStack(level, pos, sapling);
if (!saplingStack.isEmpty()) {
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null)) {
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null)) {
if (recipe.saplingType.test(saplingStack)) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
MutableObject<BlockEntityWoodStand> toPick = new MutableObject<>();
boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
BlockEntity tile = level.getBlockEntity(tilePos);
if (tile instanceof BlockEntityWoodStand) {
BlockEntityWoodStand stand = (BlockEntityWoodStand) tile;
if (tile instanceof BlockEntityWoodStand stand) {
ItemStack stack = stand.items.getStackInSlot(0);
if (!stack.isEmpty()) {
for (int i = required.size() - 1; i >= 0; i--) {
@ -111,12 +107,12 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
}
@Override
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) {
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
return Helper.putStackOnTile(player, handIn, pos, 0, true);
}
@Override
public Tuple<BlockEntityType<BlockEntityWoodStand>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityWoodStand>>>> getTESR() {
public Tuple<BlockEntityType<? extends BlockEntityWoodStand>, Supplier<BlockEntityRendererProvider<BlockEntityWoodStand>>> getTESR() {
return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new);
}
@ -124,4 +120,5 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
}

View file

@ -1,34 +1,31 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraTimer;
import de.ellpeck.naturesaura.items.ItemAuraBottle;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
public class RenderAuraTimer implements BlockEntityRenderer<BlockEntityAuraTimer> {
public class RenderAuraTimer extends BlockEntityRenderer<BlockEntityAuraTimer> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/aura_timer_aura.png");
private final AuraModel model = new AuraModel();
// private final AuraModel model = new AuraModel();
public RenderAuraTimer(BlockEntityRendererProvider.Context context) {
public RenderAuraTimer(BlockEntityRendererDispatcher disp) {
super(disp);
}
@Override
public void render(BlockEntityAuraTimer tile, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) {
public void render(BlockEntityAuraTimer tile, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
ItemStack bottle = tile.getItemHandler().getStackInSlot(0);
if (bottle.isEmpty())
return;
stack.push();
stack.pushPose();
stack.translate(4 / 16F, 2.001F / 16, 4 / 16F);
float percentage = 1 - tile.getTimerPercentage();
@ -38,11 +35,13 @@ public class RenderAuraTimer extends BlockEntityRenderer<BlockEntityAuraTimer> {
float r = (type.getColor() >> 16 & 255) / 255F;
float g = (type.getColor() >> 8 & 255) / 255F;
float b = (type.getColor() & 255) / 255F;
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), combinedLightIn, combinedOverlayIn, r, g, b, 0.75F);
stack.pop();
//this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), combinedLightIn, combinedOverlayIn, r, g, b, 0.75F);
stack.popPose();
}
private static class AuraModel extends Model {
// TODO model rendering
/* private static class AuraModel extends Model {
private final ModelRenderer box;
@ -57,5 +56,5 @@ public class RenderAuraTimer extends BlockEntityRenderer<BlockEntityAuraTimer> {
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
}
}
}*/
}

View file

@ -1,52 +1,50 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityGeneratorLimitRemover;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RenderGeneratorLimitRemover extends BlockEntityRenderer<BlockEntityGeneratorLimitRemover> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/generator_limit_remover_glint.png");
private final ModelLimitRemoverGlint model = new ModelLimitRemoverGlint();
public class RenderGeneratorLimitRemover implements BlockEntityRenderer<BlockEntityGeneratorLimitRemover> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/generator_limit_remover_glint.png");
//private final ModelLimitRemoverGlint model = new ModelLimitRemoverGlint();
public RenderGeneratorLimitRemover(BlockEntityRendererProvider.Context context) {
public RenderGeneratorLimitRemover(BlockEntityRendererDispatcher disp) {
super(disp);
}
@Override
public void render(BlockEntityGeneratorLimitRemover te, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
BlockEntity above = te.getLevel().getBlockEntity(te.getPos().up());
public void render(BlockEntityGeneratorLimitRemover te, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
BlockEntity above = te.getLevel().getBlockEntity(te.getBlockPos().above());
if (above instanceof BlockEntityImpl && ((BlockEntityImpl) above).wantsLimitRemover()) {
this.renderGlint(matrixStack, iRenderTypeBuffer, 1, combinedOverlayIn);
this.renderGlint(matrixStack, iRenderTypeBuffer, 0, combinedOverlayIn);
}
}
private void renderGlint(MatrixStack stack, IRenderTypeBuffer buffer, double yOff, int combinedOverlayIn) {
stack.push();
private void renderGlint(PoseStack stack, MultiBufferSource buffer, double yOff, int combinedOverlayIn) {
stack.pushPose();
int brightness = 15 << 20 | 15 << 4;
float alpha = ((float) Math.sin(System.currentTimeMillis() / 800D) + 1F) / 2F;
stack.translate(-0.001F, yOff + 1 + 0.001F, 1 + 0.001F);
stack.rotate(Vector3f.XP.rotationDegrees(180F));
stack.mulPose(Vector3f.XP.rotationDegrees(180F));
stack.scale(1.002F, 1.002F, 1.002F);
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, alpha);
stack.pop();
//this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, alpha);
stack.popPose();
}
private static class ModelLimitRemoverGlint extends Model {
// TODO model rendering
/* private static class ModelLimitRemoverGlint extends Model {
private final ModelRenderer box;
@ -61,5 +59,5 @@ public class RenderGeneratorLimitRemover extends BlockEntityRenderer<BlockEntity
public void render(MatrixStack matrixStack, IVertexBuilder iVertexBuilder, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStack, iVertexBuilder, packedLightIn, packedOverlayIn, red, green, blue, alpha);
}
}
}*/
}

View file

@ -1,31 +1,27 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityNatureAltar;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.world.item.ItemStack;
public class RenderNatureAltar extends BlockEntityRenderer<BlockEntityNatureAltar> {
public RenderNatureAltar(BlockEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
}
public class RenderNatureAltar implements BlockEntityRenderer<BlockEntityNatureAltar> {
@Override
public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityIn.items.getStackInSlot(0);
if (!stack.isEmpty()) {
matrixStackIn.push();
matrixStackIn.pushPose();
float time = tileEntityIn.bobTimer + partialTicks;
float bob = (float) Math.sin(time / 10F) * 0.1F;
matrixStackIn.translate(0.5F, 1.2F + bob, 0.5F);
matrixStackIn.rotate(Vector3f.YP.rotationDegrees(time * 3 % 360));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn);
matrixStackIn.pop();
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStackIn, bufferIn, 0);
matrixStackIn.popPose();
}
}
}

View file

@ -1,37 +1,32 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import java.util.Random;
public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOfferingTable> {
public class RenderOfferingTable implements BlockEntityRenderer<BlockEntityOfferingTable> {
private final Random rand = new Random();
public RenderOfferingTable(BlockEntityRendererDispatcher disp) {
super(disp);
}
@Override
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityOfferingTable.items.getStackInSlot(0);
if (!stack.isEmpty()) {
this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getDamage());
this.rand.setSeed(Item.getId(stack.getItem()) + stack.getDamageValue());
int amount = Mth.ceil(stack.getCount() / 2F);
for (int i = 0; i < amount; i++) {
matrixStack.push();
matrixStack.pushPose();
Item item = stack.getItem();
float scale;
@ -48,12 +43,12 @@ public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOffering
0.35F + this.rand.nextFloat() * 0.3F,
0.9F + yOff + i * 0.001F,
0.35F + this.rand.nextFloat() * 0.3F);
matrixStack.rotate(Vector3f.YP.rotationDegrees(this.rand.nextFloat() * 360));
matrixStack.rotate(Vector3f.XP.rotationDegrees(90F));
matrixStack.mulPose(Vector3f.YP.rotationDegrees(this.rand.nextFloat() * 360));
matrixStack.mulPose(Vector3f.XP.rotationDegrees(90F));
matrixStack.scale(scale, scale, scale);
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStack, iRenderTypeBuffer);
matrixStack.pop();
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, combinedLightIn, combinedOverlayIn, matrixStack, iRenderTypeBuffer, 0);
matrixStack.popPose();
}
}
}

View file

@ -1,64 +1,57 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RenderProjectileGenerator extends BlockEntityRenderer<BlockEntityProjectileGenerator> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
private final ModelOverlay model = new ModelOverlay();
public class RenderProjectileGenerator implements BlockEntityRenderer<BlockEntityProjectileGenerator> {
public RenderProjectileGenerator(BlockEntityRendererDispatcher rendererDispatcherIn) {
super(rendererDispatcherIn);
}
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
//private final ModelOverlay model = new ModelOverlay();
@Override
public void render(BlockEntityProjectileGenerator te, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) {
stack.push();
public void render(BlockEntityProjectileGenerator te, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
stack.pushPose();
if (te.nextSide == Direction.NORTH) {
stack.rotate(Vector3f.YP.rotationDegrees(270));
stack.mulPose(Vector3f.YP.rotationDegrees(270));
stack.translate(-0.002F, 0, -1);
} else if (te.nextSide == Direction.EAST) {
stack.rotate(Vector3f.YP.rotationDegrees(180));
stack.mulPose(Vector3f.YP.rotationDegrees(180));
stack.translate(-1.002F, 0, -1);
} else if (te.nextSide == Direction.SOUTH) {
stack.rotate(Vector3f.YP.rotationDegrees(90));
stack.mulPose(Vector3f.YP.rotationDegrees(90));
stack.translate(-1.002F, 0, 0);
} else {
stack.translate(-0.002F, 0, 0);
}
int brightness = 15 << 20 | 15 << 4;
this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, 1);
stack.pop();
//this.model.render(stack, buffer.getBuffer(this.model.getRenderType(RES)), brightness, combinedOverlayIn, 1, 1, 1, 1);
stack.popPose();
}
private static class ModelOverlay extends Model {
// TODO model rendering
/* private static class ModelOverlay extends Model {
private final ModelRenderer box;
private final ModelPart box;
public ModelOverlay() {
super(RenderType::getEntityTranslucent);
this.box = new ModelRenderer(this, 0, 0);
super(RenderType::entityTranslucent);
this.box = new ModelPart(this, 0, 0);
this.box.setTextureSize(64, 64);
this.box.addBox(0, 0, 0, 16, 16, 16);
this.box.(0, 0, 0, 16, 16, 16);
}
@Override
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
}
}
}*/
}

View file

@ -1,30 +1,30 @@
package de.ellpeck.naturesaura.blocks.tiles.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
public class RenderWoodStand extends BlockEntityRenderer<BlockEntityWoodStand> {
public class RenderWoodStand implements BlockEntityRenderer<BlockEntityWoodStand> {
public RenderWoodStand(BlockEntityRendererProvider.Context context) {
public RenderWoodStand(BlockEntityRendererDispatcher disp) {
super(disp);
}
@Override
public void render(BlockEntityWoodStand tileEntityWoodStand, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int i, int i1) {
public void render(BlockEntityWoodStand tileEntityWoodStand, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int i, int i1) {
ItemStack stack = tileEntityWoodStand.items.getStackInSlot(0);
if (!stack.isEmpty()) {
matrixStack.push();
matrixStack.pushPose();
Item item = stack.getItem();
if (item instanceof BlockItem && ((BlockItem) item).getBlock().getDefaultState().getMaterial().isSolid()) {
if (item instanceof BlockItem blockItem && blockItem.getBlock().defaultBlockState().getMaterial().isSolid()) {
matrixStack.translate(0.5F, 0.755F, 0.5F);
float scale = 0.95F;
matrixStack.scale(scale, scale, scale);
@ -32,10 +32,10 @@ public class RenderWoodStand extends BlockEntityRenderer<BlockEntityWoodStand> {
matrixStack.translate(0.5F, 0.825F, 0.4F);
float scale = 0.75F;
matrixStack.scale(scale, scale, scale);
matrixStack.rotate(Vector3f.XP.rotationDegrees(90));
matrixStack.mulPose(Vector3f.XP.rotationDegrees(90));
}
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, i, i1, matrixStack, iRenderTypeBuffer);
matrixStack.pop();
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, i, i1, matrixStack, iRenderTypeBuffer, 0);
matrixStack.popPose();
}
}
}

View file

@ -11,7 +11,7 @@ import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
@ -22,7 +22,7 @@ public class AngerEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "anger");
private AxisAlignedBB bb;
private AABB bb;
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0)
@ -33,7 +33,7 @@ public class AngerEffect implements IDrainSpotEffect {
int dist = Math.min(Math.abs(aura) / 50000, 75);
if (dist < 10)
return false;
this.bb = new AxisAlignedBB(pos).grow(dist);
this.bb = new AABB(pos).grow(dist);
return true;
}

View file

@ -16,7 +16,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
@ -33,7 +33,7 @@ public class AnimalEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "animal");
private int chance;
private AxisAlignedBB bb;
private AABB bb;
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot <= 0)
@ -46,7 +46,7 @@ public class AnimalEffect implements IDrainSpotEffect {
if (this.chance <= 0)
return false;
int dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
this.bb = new AxisAlignedBB(pos).grow(dist);
this.bb = new AABB(pos).grow(dist);
return true;
}

View file

@ -12,7 +12,7 @@ import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.EffectInstance;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
@ -25,7 +25,7 @@ public class BreathlessEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "breathless");
private int amp;
private AxisAlignedBB bb;
private AABB bb;
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot >= 0)
@ -37,7 +37,7 @@ public class BreathlessEffect implements IDrainSpotEffect {
if (dist < 10)
return false;
this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3);
this.bb = new AxisAlignedBB(pos).grow(dist);
this.bb = new AABB(pos).grow(dist);
return true;
}

View file

@ -10,7 +10,7 @@ import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
@ -24,7 +24,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "cache_recharge");
private int amount;
private AxisAlignedBB bb;
private AABB bb;
private boolean calcValues(Level level, BlockPos pos, Integer spot) {
if (spot < 100000)
@ -34,7 +34,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
if (aura < 1500000)
return false;
int dist = Mth.clamp(aura / 3500, 3, 15);
this.bb = new AxisAlignedBB(pos).grow(dist);
this.bb = new AABB(pos).grow(dist);
this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight());
return true;
}

View file

@ -4,12 +4,13 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
public class BlockStateGenerator extends BlockStateProvider {
public BlockStateGenerator(DataGenerator gen, ExistingFileHelper exFileHelper) {
super(gen, NaturesAura.MOD_ID, exFileHelper);
}
@ -17,11 +18,10 @@ public class BlockStateGenerator extends BlockStateProvider {
@Override
protected void registerStatesAndModels() {
for (IModItem item : ModRegistry.ALL_ITEMS) {
if (!(item instanceof Block))
if (!(item instanceof Block block))
continue;
Block block = (Block) item;
if (block instanceof ICustomBlockState) {
((ICustomBlockState) block).generateCustomBlockState(this);
if (block instanceof ICustomBlockState custom) {
custom.generateCustomBlockState(this);
} else {
this.simpleBlock(block);
}

View file

@ -5,13 +5,14 @@ import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.INoItemBlock;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.item.Item;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
public class ItemModelGenerator extends ItemModelProvider {
public ItemModelGenerator(DataGenerator generator, ExistingFileHelper existingFileHelper) {
super(generator, NaturesAura.MOD_ID, existingFileHelper);
}

View file

@ -1,19 +1,19 @@
package de.ellpeck.naturesaura.entities.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.entities.EntityEffectInhibitor;
import de.ellpeck.naturesaura.items.ItemEffectPowder;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -25,26 +25,26 @@ public class RenderEffectInhibitor extends EntityRenderer<EntityEffectInhibitor>
private final Map<ResourceLocation, ItemStack> items = new HashMap<>();
public RenderEffectInhibitor(EntityRendererManager renderManager) {
super(renderManager);
public RenderEffectInhibitor(EntityRendererProvider.Context p_174008_) {
super(p_174008_);
}
@Override
public ResourceLocation getEntityTexture(EntityEffectInhibitor entity) {
return AtlasTexture.LOCATION_BLOCKS_TEXTURE;
public ResourceLocation getTextureLocation(EntityEffectInhibitor entity) {
return TextureAtlas.LOCATION_BLOCKS;
}
@Override
public void render(EntityEffectInhibitor entity, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
matrixStackIn.push();
float time = entity.renderTicks + entity.getEntityId() + partialTicks;
public void render(EntityEffectInhibitor entity, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
matrixStackIn.pushPose();
float time = entity.renderTicks + entity.getId() + partialTicks;
float bob = (float) Math.sin(time / 10F) * 0.05F;
matrixStackIn.translate(0, 0.15F + bob, 0);
matrixStackIn.rotate(Vector3f.YP.rotationDegrees(time * 3 % 360));
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(time * 3 % 360));
ResourceLocation effect = entity.getInhibitedEffect();
ItemStack stack = this.items.computeIfAbsent(effect,
res -> ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER), effect));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn);
matrixStackIn.pop();
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn, 0);
matrixStackIn.popPose();
}
}

View file

@ -1,45 +1,37 @@
package de.ellpeck.naturesaura.entities.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.entities.EntityMoverMinecart;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MinecartRenderer;
import net.minecraft.client.renderer.model.Model;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
public class RenderMoverMinecart extends MinecartRenderer<EntityMoverMinecart> {
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/mover_cart.png");
private final ModelMoverMinecart model = new ModelMoverMinecart();
public RenderMoverMinecart(EntityRendererManager renderManagerIn) {
super(renderManagerIn);
public RenderMoverMinecart(EntityRendererProvider.Context p_174300_) {
super(p_174300_, ModelLayers.MINECART);
}
//private final ModelMoverMinecart model = new ModelMoverMinecart();
@Override
public void render(EntityMoverMinecart entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
}
@Override
protected void renderBlockState(EntityMoverMinecart entityIn, float partialTicks, BlockState stateIn, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
matrixStackIn.push();
protected void renderMinecartContents(EntityMoverMinecart entityIn, float partialTicks, BlockState stateIn, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
matrixStackIn.pushPose();
matrixStackIn.translate(0, 22 / 16F, 0);
matrixStackIn.translate(0, 0, 1);
matrixStackIn.rotate(Vector3f.XP.rotationDegrees(180));
this.model.render(matrixStackIn, bufferIn.getBuffer(this.model.getRenderType(RES)), packedLightIn, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
matrixStackIn.pop();
matrixStackIn.mulPose(Vector3f.XP.rotationDegrees(180));
//this.model.render(matrixStackIn, bufferIn.getBuffer(this.model.getRenderType(RES)), packedLightIn, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
matrixStackIn.popPose();
}
private static class ModelMoverMinecart extends Model {
// TODO model rendering
/* private static class ModelMoverMinecart extends Model {
private final ModelRenderer box;
@ -54,5 +46,5 @@ public class RenderMoverMinecart extends MinecartRenderer<EntityMoverMinecart> {
public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
this.box.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn, red, green, blue, alpha);
}
}
}*/
}

View file

@ -1,24 +1,25 @@
package de.ellpeck.naturesaura.entities.render;
import net.minecraft.client.renderer.culling.ClippingHelper;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
public class RenderStub extends EntityRenderer<Entity> {
public RenderStub(EntityRendererManager renderManager) {
super(renderManager);
public class RenderStub<T extends Entity> extends EntityRenderer<T> {
public RenderStub(EntityRendererProvider.Context p_174008_) {
super(p_174008_);
}
@Override
public boolean shouldRender(Entity livingEntityIn, ClippingHelper camera, double camX, double camY, double camZ) {
public boolean shouldRender(T livingEntityIn, Frustum camera, double camX, double camY, double camZ) {
return false;
}
@Override
public ResourceLocation getEntityTexture(Entity entity) {
return AtlasTexture.LOCATION_BLOCKS_TEXTURE;
public ResourceLocation getTextureLocation(T p_114482_) {
return TextureAtlas.LOCATION_BLOCKS;
}
}

View file

@ -30,7 +30,7 @@ import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Mth;
@ -244,7 +244,7 @@ public class ClientEvents {
private void renderVisualize(IVisualizable visualize, Level
level, BlockPos pos) {
AxisAlignedBB box = visualize.getVisualizationBounds(level, pos);
AABB box = visualize.getVisualizationBounds(level, pos);
if (box == null)
return;
box = box.grow(0.05F);

View file

@ -0,0 +1,137 @@
package de.ellpeck.naturesaura.gen;
import com.mojang.serialization.Codec;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.TreeFeature;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.material.Material;
import java.util.Random;
import static net.minecraft.core.Direction.Axis;
public class LevelGenAncientTree extends Feature<TreeConfiguration> {
public LevelGenAncientTree() {
super(Codec.unit(ModFeatures.Configured.ANCIENT_TREE.config()));
}
@Override
public boolean place(FeaturePlaceContext<TreeConfiguration> ctx) {
var level = ctx.level();
var pos = ctx.origin();
var rand = ctx.random();
int height = rand.nextInt(3) + 5;
BlockPos trunkTop = pos.above(height);
this.setBlock(level, pos, Blocks.AIR.defaultBlockState());
//Roots
int rootsAmount = rand.nextInt(4) + 5;
for (int i = 0; i < rootsAmount; i++) {
int length = rand.nextInt(3) + 3;
float angle = 2F * (float) Math.PI * (i / (float) rootsAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = pos.offset(x, 0, z);
while (level.isStateAtPosition(goal, state -> state.getMaterial().isReplaceable())) {
goal = goal.below();
if (goal.distSqr(pos) >= 10 * 10)
break;
}
this.makeBranch(level, pos.above(rand.nextInt(1)), goal, ModBlocks.ANCIENT_BARK.defaultBlockState(), false);
}
//Trunk
for (int x = 0; x <= 1; x++) {
for (int z = 0; z <= 1; z++) {
for (int i = height - (x + z) * (rand.nextInt(2) + 2); i >= 0; i--) {
BlockPos goal = pos.offset(x, i, z);
if (!level.isStateAtPosition(goal, s -> !TreeFeature.validTreePos(level, goal))) {
this.setBlock(level, goal, ModBlocks.ANCIENT_LOG.defaultBlockState().setValue(RotatedPillarBlock.AXIS, Axis.Y));
}
}
}
}
this.makeLeaves(level, trunkTop.above(rand.nextInt(2) - 1), ModBlocks.ANCIENT_LEAVES.defaultBlockState(), rand.nextInt(2) + 3, rand);
//Branches
int branchAmount = rand.nextInt(3) + 4;
for (int i = 0; i < branchAmount; i++) {
int length = rand.nextInt(2) + 3;
float angle = 2F * (float) Math.PI * (i / (float) branchAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = trunkTop.offset(x, rand.nextInt(3) + 1, z);
this.makeBranch(level, trunkTop, goal, ModBlocks.ANCIENT_LOG.defaultBlockState(), true);
this.makeLeaves(level, goal, ModBlocks.ANCIENT_LEAVES.defaultBlockState(), rand.nextInt(2) + 2, rand);
}
return true;
}
private void makeBranch(WorldGenLevel level, BlockPos first, BlockPos second, BlockState state, boolean hasAxis) {
BlockPos pos = second.offset(-first.getX(), -first.getY(), -first.getZ());
int length = this.getHighestCoord(pos);
float stepX = (float) pos.getX() / (float) length;
float stepY = (float) pos.getY() / (float) length;
float stepZ = (float) pos.getZ() / (float) length;
for (int i = 0; i <= length; i++) {
BlockPos goal = first.offset(0.5F + i * stepX, 0.5F + i * stepY, 0.5F + i * stepZ);
if (!level.isStateAtPosition(goal, s -> !TreeFeature.validTreePos(level, goal))) {
if (hasAxis) {
Axis axis = this.getLogAxis(first, goal);
this.setBlock(level, goal, state.setValue(RotatedPillarBlock.AXIS, axis));
} else {
this.setBlock(level, goal, state);
}
}
}
}
private void makeLeaves(WorldGenLevel level, BlockPos pos, BlockState state, int radius, Random rand) {
for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
BlockPos goal = pos.offset(x, y, z);
if (pos.distSqr(goal) <= radius * radius + rand.nextInt(3) - 1) {
if (!level.isStateAtPosition(goal, s -> s.getMaterial() == Material.LEAVES)) {
if (level.isStateAtPosition(goal, st -> st.getMaterial() != Material.WOOD && st.getBlock() != Blocks.DIRT && st.getBlock() != Blocks.GRASS))
this.setBlock(level, goal, state);
}
}
}
}
}
}
private int getHighestCoord(BlockPos pos) {
return Math.max(Mth.abs(pos.getX()), Math.max(Mth.abs(pos.getY()), Mth.abs(pos.getZ())));
}
private Axis getLogAxis(BlockPos pos, BlockPos goal) {
Axis axis = Axis.Y;
int x = Math.abs(goal.getX() - pos.getX());
int y = Math.abs(goal.getZ() - pos.getZ());
int highest = Math.max(x, y);
if (highest > 0) {
if (x == highest) {
axis = Axis.X;
} else if (y == highest) {
axis = Axis.Z;
}
}
return axis;
}
}

View file

@ -2,35 +2,36 @@ package de.ellpeck.naturesaura.gen;
import com.mojang.serialization.Codec;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.ISeedReader;
import net.minecraft.level.gen.ChunkGenerator;
import net.minecraft.level.gen.Heightmap;
import net.minecraft.level.gen.feature.Feature;
import net.minecraft.level.gen.feature.IFeatureConfig;
import net.minecraft.level.gen.feature.NoFeatureConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import java.util.Random;
public class LevelGenAuraBloom extends Feature<NoFeatureConfig> {
public class LevelGenAuraBloom extends Feature<NoneFeatureConfiguration> {
private final Block block;
private final int chance;
private final boolean nether;
public LevelGenAuraBloom(Block block, int chance, boolean nether) {
super(Codec.unit(IFeatureConfig.NO_FEATURE_CONFIG));
super(Codec.unit(FeatureConfiguration.NONE));
this.block = block;
this.chance = chance;
this.nether = nether;
}
@Override
public boolean func_241855_a(ISeedReader levelIn, ChunkGenerator gen, Random rand, BlockPos pos, NoFeatureConfig config) {
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
var levelIn = ctx.level();
var pos = ctx.origin();
var rand = ctx.random();
if (rand.nextInt(this.chance) != 0)
return false;
int startX = pos.getX() + rand.nextInt(16);
@ -49,7 +50,7 @@ public class LevelGenAuraBloom extends Feature<NoFeatureConfig> {
}
}
} else {
BlockPos placePos = new BlockPos(offX, levelIn.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, offX, offZ), offZ);
BlockPos placePos = new BlockPos(offX, levelIn.getHeight(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, offX, offZ), offZ);
if (this.tryPlace(levelIn, placePos))
any = true;
}
@ -57,13 +58,13 @@ public class LevelGenAuraBloom extends Feature<NoFeatureConfig> {
return any;
}
private boolean tryPlace(ISeedReader level, BlockPos pos) {
BlockState state = this.block.getDefaultState();
if (this.block.isValidPosition(state, level, pos)) {
level.setBlockState(pos, state, 3);
private boolean tryPlace(WorldGenLevel level, BlockPos pos) {
BlockState state = this.block.defaultBlockState();
if (this.block.canSurvive(state, level, pos)) {
level.setBlock(pos, state, 3);
BlockEntity tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityAuraBloom)
((BlockEntityAuraBloom) tile).justGenerated = true;
if (tile instanceof BlockEntityAuraBloom bloom)
bloom.justGenerated = true;
return true;
}
return false;

View file

@ -0,0 +1,64 @@
package de.ellpeck.naturesaura.gen;
import com.mojang.serialization.Codec;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.TreeFeature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
public class LevelGenNetherWartMushroom extends Feature<NoneFeatureConfiguration> {
public LevelGenNetherWartMushroom() {
super(Codec.unit(FeatureConfiguration.NONE));
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
var levelIn = ctx.level();
var pos = ctx.origin();
var rand = ctx.random();
int height = rand.nextInt(5) + 4;
if (rand.nextInt(10) == 0)
height += 5;
// Check if the stem has space
for (int i = 1; i < height; i++) {
BlockPos offset = pos.above(i);
if (levelIn.isStateAtPosition(offset, s -> !TreeFeature.validTreePos(levelIn, offset)))
return false;
}
// Place stem
this.setBlock(levelIn, pos, Blocks.AIR.defaultBlockState());
for (int i = 0; i < height; i++)
this.placeIfPossible(levelIn, pos.above(i), Blocks.NETHER_WART_BLOCK);
// Place hat
int rad = 3;
for (int x = -rad; x <= rad; x++) {
for (int z = -rad; z <= rad; z++) {
int absX = Math.abs(x);
int absZ = Math.abs(z);
if (absX <= 1 && absZ <= 1) {
this.placeIfPossible(levelIn, pos.offset(x, height, z), ModBlocks.NETHER_WART_MUSHROOM);
} else if (absX <= 2 && absZ <= 2 && absX != absZ) {
this.placeIfPossible(levelIn, pos.offset(x, height - 1, z), ModBlocks.NETHER_WART_MUSHROOM);
} else if (absX < rad - 1 || absZ < rad - 1 || absX == rad - 1 && absZ == rad - 1) {
this.placeIfPossible(levelIn, pos.offset(x, height - 2, z), ModBlocks.NETHER_WART_MUSHROOM);
}
}
}
return true;
}
private void placeIfPossible(WorldGenLevel level, BlockPos pos, Block block) {
if (level.isStateAtPosition(pos, s -> TreeFeature.validTreePos(level, pos)))
level.setBlock(pos, block.defaultBlockState(), 19);
}
}

View file

@ -1,27 +1,31 @@
package de.ellpeck.naturesaura.gen;
import net.minecraft.level.gen.feature.*;
import net.minecraft.level.gen.placement.IPlacementConfig;
import net.minecraft.level.gen.placement.Placement;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
@SuppressWarnings("FieldNamingConvention")
public final class ModFeatures {
public static Feature<BaseTreeFeatureConfig> ANCIENT_TREE;
public static Feature<NoFeatureConfig> NETHER_WART_MUSHROOM;
public static Feature<NoFeatureConfig> AURA_BLOOM;
public static Feature<NoFeatureConfig> AURA_CACTUS;
public static Feature<NoFeatureConfig> WARPED_AURA_MUSHROOM;
public static Feature<NoFeatureConfig> CRIMSON_AURA_MUSHROOM;
public static Feature<NoFeatureConfig> AURA_MUSHROOM;
public static Feature<TreeConfiguration> ANCIENT_TREE;
public static Feature<NoneFeatureConfiguration> NETHER_WART_MUSHROOM;
public static Feature<NoneFeatureConfiguration> AURA_BLOOM;
public static Feature<NoneFeatureConfiguration> AURA_CACTUS;
public static Feature<NoneFeatureConfiguration> WARPED_AURA_MUSHROOM;
public static Feature<NoneFeatureConfiguration> CRIMSON_AURA_MUSHROOM;
public static Feature<NoneFeatureConfiguration> AURA_MUSHROOM;
public static final class Configured {
public static final ConfiguredFeature AURA_BLOOM = ModFeatures.AURA_BLOOM.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
public static final ConfiguredFeature AURA_CACTUS = ModFeatures.AURA_CACTUS.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
public static final ConfiguredFeature CRIMSON_AURA_MUSHROOM = ModFeatures.CRIMSON_AURA_MUSHROOM.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
public static final ConfiguredFeature WARPED_AURA_MUSHROOM = ModFeatures.WARPED_AURA_MUSHROOM.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
public static final ConfiguredFeature AURA_MUSHROOM = ModFeatures.AURA_MUSHROOM.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG));
public static final ConfiguredFeature<TreeConfiguration, ?> ANCIENT_TREE = ModFeatures.ANCIENT_TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(null, null, null, null, null).build());
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> NETHER_WART_MUSHROOM = ModFeatures.NETHER_WART_MUSHROOM.configured(FeatureConfiguration.NONE);
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> AURA_BLOOM = ModFeatures.AURA_BLOOM.configured(FeatureConfiguration.NONE);
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> AURA_CACTUS = ModFeatures.AURA_CACTUS.configured(FeatureConfiguration.NONE);
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> WARPED_AURA_MUSHROOM = ModFeatures.WARPED_AURA_MUSHROOM.configured(FeatureConfiguration.NONE);
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> CRIMSON_AURA_MUSHROOM = ModFeatures.CRIMSON_AURA_MUSHROOM.configured(FeatureConfiguration.NONE);
public static final ConfiguredFeature<NoneFeatureConfiguration, ?> AURA_MUSHROOM = ModFeatures.AURA_MUSHROOM.configured(FeatureConfiguration.NONE);
}
}

View file

@ -1,140 +0,0 @@
package de.ellpeck.naturesaura.gen;
import com.mojang.serialization.Codec;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.block.material.Material;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.ISeedReader;
import net.minecraft.level.gen.ChunkGenerator;
import net.minecraft.level.gen.ILevelGenerationReader;
import net.minecraft.level.gen.feature.BaseTreeFeatureConfig;
import net.minecraft.level.gen.feature.Feature;
import java.util.Random;
public class LevelGenAncientTree extends Feature<BaseTreeFeatureConfig> {
// what the heck even is this
public static final BaseTreeFeatureConfig CONFIG = new BaseTreeFeatureConfig.Builder(null, null, null, null, null).build();
public LevelGenAncientTree() {
super(Codec.unit(CONFIG));
}
@Override
public boolean func_241855_a(ISeedReader level, ChunkGenerator generator, Random rand, BlockPos pos, BaseTreeFeatureConfig p_241855_5_) {
int height = rand.nextInt(3) + 5;
BlockPos trunkTop = pos.up(height);
this.func_230367_a_(level, pos, Blocks.AIR.getDefaultState());
//Roots
int rootsAmount = rand.nextInt(4) + 5;
for (int i = 0; i < rootsAmount; i++) {
int length = rand.nextInt(3) + 3;
float angle = 2F * (float) Math.PI * (i / (float) rootsAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = pos.add(x, 0, z);
while (level.hasBlockState(goal, state -> state.getMaterial().isReplaceable())) {
goal = goal.down();
if (goal.distanceSq(pos) >= 10 * 10)
break;
}
this.makeBranch(level, pos.up(rand.nextInt(1)), goal, ModBlocks.ANCIENT_BARK.getDefaultState(), false);
}
//Trunk
for (int x = 0; x <= 1; x++) {
for (int z = 0; z <= 1; z++) {
for (int i = height - (x + z) * (rand.nextInt(2) + 2); i >= 0; i--) {
BlockPos goal = pos.add(x, i, z);
if (!level.hasBlockState(goal, s -> !s.canBeReplacedByLogs(level, goal))) {
this.func_230367_a_(level, goal, ModBlocks.ANCIENT_LOG.getDefaultState().with(RotatedPillarBlock.AXIS, Axis.Y));
}
}
}
}
this.makeLeaves(level, trunkTop.up(rand.nextInt(2) - 1), ModBlocks.ANCIENT_LEAVES.getDefaultState(), rand.nextInt(2) + 3, rand);
//Branches
int branchAmount = rand.nextInt(3) + 4;
for (int i = 0; i < branchAmount; i++) {
int length = rand.nextInt(2) + 3;
float angle = 2F * (float) Math.PI * (i / (float) branchAmount);
float x = (float) Math.sin(angle) * length;
float z = (float) Math.cos(angle) * length;
BlockPos goal = trunkTop.add(x, rand.nextInt(3) + 1, z);
this.makeBranch(level, trunkTop, goal, ModBlocks.ANCIENT_LOG.getDefaultState(), true);
this.makeLeaves(level, goal, ModBlocks.ANCIENT_LEAVES.getDefaultState(), rand.nextInt(2) + 2, rand);
}
return true;
}
private void makeBranch(ISeedReader level, BlockPos first, BlockPos second, BlockState state, boolean hasAxis) {
BlockPos pos = second.add(-first.getX(), -first.getY(), -first.getZ());
int length = this.getHighestCoord(pos);
float stepX = (float) pos.getX() / (float) length;
float stepY = (float) pos.getY() / (float) length;
float stepZ = (float) pos.getZ() / (float) length;
for (int i = 0; i <= length; i++) {
BlockPos goal = first.add(0.5F + i * stepX, 0.5F + i * stepY, 0.5F + i * stepZ);
if (!level.hasBlockState(goal, s -> !s.canBeReplacedByLogs(level, goal))) {
if (hasAxis) {
Axis axis = this.getLogAxis(first, goal);
this.func_230367_a_(level, goal, state.with(RotatedPillarBlock.AXIS, axis));
} else {
this.func_230367_a_(level, goal, state);
}
}
}
}
private void makeLeaves(ILevelGenerationReader level, BlockPos pos, BlockState state, int radius, Random rand) {
for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
BlockPos goal = pos.add(x, y, z);
if (pos.distanceSq(goal) <= radius * radius + rand.nextInt(3) - 1) {
if (!level.hasBlockState(goal, s -> s.getMaterial() == Material.LEAVES)) {
if (level.hasBlockState(goal, st -> {
Block block = st.getBlock();
return st.getMaterial() != Material.WOOD && block != Blocks.DIRT && block != Blocks.GRASS;
})) {
this.func_230367_a_(level, goal, state);
}
}
}
}
}
}
}
private int getHighestCoord(BlockPos pos) {
return Math.max(Mth.abs(pos.getX()), Math.max(Mth.abs(pos.getY()), Mth.abs(pos.getZ())));
}
private Axis getLogAxis(BlockPos pos, BlockPos goal) {
Axis axis = Axis.Y;
int x = Math.abs(goal.getX() - pos.getX());
int y = Math.abs(goal.getZ() - pos.getZ());
int highest = Math.max(x, y);
if (highest > 0) {
if (x == highest) {
axis = Axis.X;
} else if (y == highest) {
axis = Axis.Z;
}
}
return axis;
}
}

View file

@ -1,63 +0,0 @@
package de.ellpeck.naturesaura.gen;
import com.mojang.serialization.Codec;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ISeedReader;
import net.minecraft.level.ILevel;
import net.minecraft.level.gen.ChunkGenerator;
import net.minecraft.level.gen.feature.Feature;
import net.minecraft.level.gen.feature.IFeatureConfig;
import net.minecraft.level.gen.feature.NoFeatureConfig;
import java.util.Random;
public class LevelGenNetherWartMushroom extends Feature<NoFeatureConfig> {
public LevelGenNetherWartMushroom() {
super(Codec.unit(IFeatureConfig.NO_FEATURE_CONFIG));
}
@Override
public boolean func_241855_a(ISeedReader levelIn, ChunkGenerator gen, Random rand, BlockPos pos, NoFeatureConfig p_241855_5_) {
int height = rand.nextInt(5) + 4;
if (rand.nextInt(10) == 0)
height += 5;
// Check if the stem has space
for (int i = 1; i < height; i++) {
BlockPos offset = pos.up(i);
if (levelIn.hasBlockState(offset, s -> !s.canBeReplacedByLogs(levelIn, offset)))
return false;
}
// Place stem
this.func_230367_a_(levelIn, pos, Blocks.AIR.getDefaultState());
for (int i = 0; i < height; i++)
this.placeIfPossible(levelIn, pos.up(i), Blocks.NETHER_WART_BLOCK);
// Place hat
int rad = 3;
for (int x = -rad; x <= rad; x++) {
for (int z = -rad; z <= rad; z++) {
int absX = Math.abs(x);
int absZ = Math.abs(z);
if (absX <= 1 && absZ <= 1) {
this.placeIfPossible(levelIn, pos.add(x, height, z), ModBlocks.NETHER_WART_MUSHROOM);
} else if (absX <= 2 && absZ <= 2 && absX != absZ) {
this.placeIfPossible(levelIn, pos.add(x, height - 1, z), ModBlocks.NETHER_WART_MUSHROOM);
} else if (absX < rad - 1 || absZ < rad - 1 || absX == rad - 1 && absZ == rad - 1) {
this.placeIfPossible(levelIn, pos.add(x, height - 2, z), ModBlocks.NETHER_WART_MUSHROOM);
}
}
}
return true;
}
private void placeIfPossible(ILevel level, BlockPos pos, Block block) {
if (level.hasBlockState(pos, s -> s.canBeReplacedByLogs(level, pos)))
level.setBlockState(pos, block.getDefaultState(), 19);
}
}

View file

@ -1,51 +1,51 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.gen.ModFeatures;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.NetherWartBlock;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.gen.feature.IFeatureConfig;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.NetherWartBlock;
import net.minecraft.world.level.block.state.BlockState;
public class ItemCrimsonMeal extends ItemImpl {
public ItemCrimsonMeal() {
super("crimson_meal");
}
@Override
public InteractionResult onItemUse(ItemUseContext context) {
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos pos = context.getPos();
BlockPos pos = context.getClickedPos();
BlockState state = level.getBlockState(pos);
if (state.getBlock() == Blocks.NETHER_WART) {
if (!level.isClientSide) {
if (level.rand.nextInt(5) == 0) {
int age = state.get(NetherWartBlock.AGE);
if (level.random.nextInt(5) == 0) {
int age = state.getValue(NetherWartBlock.AGE);
if (age >= 3) {
ModFeatures.NETHER_WART_MUSHROOM.func_241855_a((ServerLevel) level, ((ServerLevel) level).getChunkProvider().getChunkGenerator(), level.rand, pos, IFeatureConfig.NO_FEATURE_CONFIG);
ModFeatures.Configured.CRIMSON_AURA_MUSHROOM.place((ServerLevel) level, ((ServerLevel) level).getChunkSource().getGenerator(), level.random, pos);
} else {
level.setBlockState(pos, state.with(NetherWartBlock.AGE, age + 1));
level.setBlockAndUpdate(pos, state.setValue(NetherWartBlock.AGE, age + 1));
}
}
level.playEvent(2005, pos, 0);
context.getItem().shrink(1);
level.levelEvent(2005, pos, 0);
context.getItemInHand().shrink(1);
}
return InteractionResult.SUCCESS;
} else if (level.getBlockState(pos.up()).isAir(level, pos.up()) && level.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) {
} else if (level.getBlockState(pos.above()).isAir() && level.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) {
if (!level.isClientSide) {
for (int i = level.rand.nextInt(5); i >= 0; i--) {
BlockPos offset = pos.add(Mth.nextInt(level.rand, -3, 3), 1, Mth.nextInt(level.rand, -3, 3));
if (level.getBlockState(offset.down()).getBlock() == Blocks.SOUL_SAND && level.getBlockState(offset).isAir(level, offset)) {
level.setBlockState(offset, Blocks.NETHER_WART.getDefaultState());
for (int i = level.random.nextInt(5); i >= 0; i--) {
BlockPos offset = pos.offset(Mth.nextInt(level.random, -3, 3), 1, Mth.nextInt(level.random, -3, 3));
if (level.getBlockState(offset.below()).getBlock() == Blocks.SOUL_SAND && level.getBlockState(offset).isAir()) {
level.setBlockAndUpdate(offset, Blocks.NETHER_WART.defaultBlockState());
}
}
level.playEvent(2005, pos, 0);
context.getItem().shrink(1);
level.levelEvent(2005, pos, 0);
context.getItemInHand().shrink(1);
}
return InteractionResult.SUCCESS;
}

View file

@ -10,7 +10,7 @@ import net.minecraft.tileentity.MobSpawnerBlockEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraftforge.items.CapabilityItemHandler;
@ -40,7 +40,7 @@ public class ItemLootFinder extends ItemImpl {
}
return false;
});
for (Entity entity : levelIn.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(pos).grow(64))) {
for (Entity entity : levelIn.getEntitiesWithinAABB(Entity.class, new AABB(pos).grow(64))) {
if (!(entity instanceof LivingEntity) && entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()) {
inst.spawnMagicParticle(
entity.getPosX(), entity.getPosYEye(), entity.getPosZ(),

View file

@ -24,7 +24,7 @@ import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.level.Level;
@ -77,7 +77,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
boolean infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED);
int range = 5;
List<LivingEntity> mobs = levelIn.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB(
List<LivingEntity> mobs = levelIn.getEntitiesWithinAABB(LivingEntity.class, new AABB(
living.getPosX() - range, living.getPosY() - 0.5, living.getPosZ() - range,
living.getPosX() + range, living.getPosY() + 0.5, living.getPosZ() + range));
for (LivingEntity mob : mobs) {

View file

@ -12,6 +12,5 @@ import java.util.function.Supplier;
public interface ITESRProvider<T extends BlockEntity> {
@OnlyIn(Dist.CLIENT)
Tuple<BlockEntityType<BlockEntity>, Supplier<BlockEntityRendererProvider<BlockEntity>>> getTESR();
Tuple<BlockEntityType<? extends T>, Supplier<BlockEntityRendererProvider<T>>> getTESR();
}

View file

@ -25,17 +25,12 @@ import de.ellpeck.naturesaura.potion.ModPotions;
import de.ellpeck.naturesaura.potion.PotionBreathless;
import de.ellpeck.naturesaura.recipes.EnabledCondition;
import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.SpriteRenderer;
import net.minecraft.entity.EntityClassification;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.level.gen.feature.Feature;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.LevelGenRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
@ -43,20 +38,21 @@ import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.enchantment.Enchantment;
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.FlowerPotBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.items.IItemHandler;
@ -79,8 +75,8 @@ public final class ModRegistry {
event.getRegistry().registerAll(
new BlockAncientLog("ancient_log"),
new BlockAncientLog("ancient_bark"),
temp = new BlockImpl("ancient_planks", Block.Properties.of(Material.WOOD).sound(SoundType.WOOD).hardnessAndResistance(2F)),
new BlockStairsNA("ancient_stairs", "ancient_planks", temp::defaultBlockState, Block.Properties.from(temp)),
temp = new BlockImpl("ancient_planks", Block.Properties.of(Material.WOOD).sound(SoundType.WOOD).strength(2F)),
new BlockStairsNA("ancient_stairs", "ancient_planks", temp::defaultBlockState, Block.Properties.copy(temp)),
new Slab("ancient_slab", "ancient_planks", Block.Properties.copy(temp)),
new BlockAncientLeaves(),
new BlockAncientSapling(),
@ -89,23 +85,23 @@ public final class ModRegistry {
new BlockGoldenLeaves(),
new BlockGoldPowder(),
new BlockWoodStand(),
temp = new BlockImpl("infused_stone", Block.Properties.of(Material.STONE).sound(SoundType.STONE).hardnessAndResistance(1.75F)),
new BlockStairsNA("infused_stairs", "infused_stone", temp::defaultBlockState, Block.Properties.from(temp)),
new Slab("infused_slab", "infused_stone", Block.Properties.from(temp)),
temp = new BlockImpl("infused_brick", Block.Properties.of(Material.STONE).sound(SoundType.STONE).hardnessAndResistance(1.5F)),
new BlockStairsNA("infused_brick_stairs", "infused_brick", temp::defaultBlockState, Block.Properties.from(temp)),
new Slab("infused_brick_slab", "infused_brick", Block.Properties.from(temp)),
temp = new BlockImpl("infused_stone", Block.Properties.of(Material.STONE).sound(SoundType.STONE).strength(1.75F)),
new BlockStairsNA("infused_stairs", "infused_stone", temp::defaultBlockState, Block.Properties.copy(temp)),
new Slab("infused_slab", "infused_stone", Block.Properties.copy(temp)),
temp = new BlockImpl("infused_brick", Block.Properties.of(Material.STONE).sound(SoundType.STONE).strength(1.5F)),
new BlockStairsNA("infused_brick_stairs", "infused_brick", temp::defaultBlockState, Block.Properties.copy(temp)),
new Slab("infused_brick_slab", "infused_brick", Block.Properties.copy(temp)),
new BlockFurnaceHeater(),
new BlockPotionGenerator(),
new BlockAuraDetector(),
new BlockCatalyst("conversion_catalyst", Block.Properties.of(Material.STONE).sound(SoundType.STONE).hardnessAndResistance(2.5F)),
new BlockCatalyst("crushing_catalyst", Block.Properties.of(Material.STONE).sound(SoundType.STONE).hardnessAndResistance(2.5F)),
new BlockCatalyst("conversion_catalyst", Block.Properties.of(Material.STONE).sound(SoundType.STONE).strength(2.5F)),
new BlockCatalyst("crushing_catalyst", Block.Properties.of(Material.STONE).sound(SoundType.STONE).strength(2.5F)),
new BlockFlowerGenerator(),
new BlockPlacer(),
new BlockHopperUpgrade(),
new BlockFieldCreator(),
new BlockOakGenerator(),
new BlockImpl("infused_iron_block", Block.Properties.of(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(3F)),
new BlockImpl("infused_iron_block", Block.Properties.of(Material.METAL).sound(SoundType.METAL).strength(3F)),
new BlockOfferingTable(),
new BlockPickupStopper(),
new BlockSpawnLamp(),
@ -157,9 +153,9 @@ public final class ModRegistry {
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event) {
for (IModItem block : ALL_ITEMS) {
for (var block : ALL_ITEMS) {
if (block instanceof Block && !(block instanceof INoItemBlock)) {
BlockItem item = new BlockItem((Block) block, new Item.Properties().tab(NaturesAura.CREATIVE_TAB));
var item = new BlockItem((Block) block, new Item.Properties().tab(NaturesAura.CREATIVE_TAB));
item.setRegistryName(block.getBaseName());
event.getRegistry().register(item);
}
@ -236,7 +232,7 @@ public final class ModRegistry {
// add tile entities that support multiple blocks
add(new ModTileType<>(BlockEntityAuraBloom::new, "aura_bloom", ALL_ITEMS.stream().filter(i -> i instanceof BlockAuraBloom).toArray(IModItem[]::new)));
for (IModItem item : ALL_ITEMS) {
for (var item : ALL_ITEMS) {
if (item instanceof ModTileType type)
event.getRegistry().register(type.type);
}
@ -255,7 +251,7 @@ public final class ModRegistry {
public static void registerContainers(RegistryEvent.Register<MenuType<?>> event) {
event.getRegistry().registerAll(
IForgeMenuType.create((windowId, inv, data) -> {
BlockEntity tile = inv.player.level.getBlockEntity(data.readBlockPos());
var tile = inv.player.level.getBlockEntity(data.readBlockPos());
if (tile instanceof BlockEntityEnderCrate crate)
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, windowId, inv.player, crate.getItemHandler());
return null;
@ -303,10 +299,10 @@ public final class ModRegistry {
NaturesAura.proxy.registerEntityRenderer(ModEntities.EFFECT_INHIBITOR, () -> RenderEffectInhibitor::new);
NaturesAura.proxy.registerEntityRenderer(ModEntities.LIGHT_PROJECTILE, () -> RenderStub::new);
// for some reason, only this one causes classloading issues if shortened to a lambda, what
NaturesAura.proxy.registerEntityRenderer(ModEntities.STRUCTURE_FINDER, () -> new IRenderFactory<EntityStructureFinder>() {
NaturesAura.proxy.registerEntityRenderer(ModEntities.STRUCTURE_FINDER, () -> new EntityRendererProvider<>() {
@Override
public EntityRenderer<? super EntityStructureFinder> createRenderFor(EntityRendererManager m) {
return new SpriteRenderer<>(m, Minecraft.getInstance().getItemRenderer());
public EntityRenderer<EntityStructureFinder> create(Context context) {
return new ThrownItemRenderer<>(context, 1, true);
}
});
}
@ -326,32 +322,32 @@ public final class ModRegistry {
}
@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipeSerializer<?>> event) {
public static void registerRecipes(RegistryEvent.Register<RecipeSerializer<?>> event) {
ModRecipes.register(event.getRegistry());
CraftingHelper.register(new EnabledCondition.Serializer());
}
public static void init() {
for (IModItem item : ALL_ITEMS) {
for (var item : ALL_ITEMS) {
if (item instanceof IColorProvidingBlock)
NaturesAura.proxy.addColorProvidingBlock((IColorProvidingBlock) item);
if (item instanceof IColorProvidingItem)
NaturesAura.proxy.addColorProvidingItem((IColorProvidingItem) item);
if (item instanceof ITESRProvider)
NaturesAura.proxy.registerTESR((ITESRProvider) item);
if (item instanceof ITESRProvider provider)
NaturesAura.proxy.registerTESR(provider);
}
// register features again for some reason
Registry.register(LevelGenRegistries.field_243653_e, new ResourceLocation(NaturesAura.MOD_ID, "aura_bloom"), ModFeatures.Configured.AURA_BLOOM);
Registry.register(LevelGenRegistries.field_243653_e, new ResourceLocation(NaturesAura.MOD_ID, "aura_cactus"), ModFeatures.Configured.AURA_CACTUS);
Registry.register(LevelGenRegistries.field_243653_e, new ResourceLocation(NaturesAura.MOD_ID, "crimson_aura_mushroom"), ModFeatures.Configured.CRIMSON_AURA_MUSHROOM);
Registry.register(LevelGenRegistries.field_243653_e, new ResourceLocation(NaturesAura.MOD_ID, "warped_aura_mushroom"), ModFeatures.Configured.WARPED_AURA_MUSHROOM);
Registry.register(LevelGenRegistries.field_243653_e, new ResourceLocation(NaturesAura.MOD_ID, "aura_mushroom"), ModFeatures.Configured.AURA_MUSHROOM);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_bloom"), ModFeatures.Configured.AURA_BLOOM);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_cactus"), ModFeatures.Configured.AURA_CACTUS);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "crimson_aura_mushroom"), ModFeatures.Configured.CRIMSON_AURA_MUSHROOM);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "warped_aura_mushroom"), ModFeatures.Configured.WARPED_AURA_MUSHROOM);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_mushroom"), ModFeatures.Configured.AURA_MUSHROOM);
}
public static Block createFlowerPot(Block block) {
Block.Properties props = Block.Properties.of(Material.MISCELLANEOUS).hardnessAndResistance(0F);
Block potted = new BlockFlowerPot(() -> (FlowerPotBlock) Blocks.FLOWER_POT, block::getBlock, props);
var props = Block.Properties.of(Material.DECORATION).strength(0F);
Block potted = new BlockFlowerPot(() -> (FlowerPotBlock) Blocks.FLOWER_POT, () -> block, props);
((FlowerPotBlock) Blocks.FLOWER_POT).addPlant(block.getRegistryName(), () -> potted);
return potted;
}