IT C O M P I L E S

This commit is contained in:
Ell 2021-12-15 16:24:53 +01:00
parent 584514944b
commit 24cf4ae186
101 changed files with 1534 additions and 1555 deletions

View file

@ -23,6 +23,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
@ -51,7 +52,7 @@ import java.util.function.Predicate;
public final class Helper {
public static boolean getBlockEntitiesInArea(Level level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) {
public static boolean getBlockEntitiesInArea(LevelAccessor level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) {
for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
var chunk = getLoadedChunk(level, x, z);
@ -89,7 +90,7 @@ public final class Helper {
return frames;
}
public static LevelChunk getLoadedChunk(Level level, int x, int z) {
public static LevelChunk getLoadedChunk(LevelAccessor level, int x, int z) {
// DO NOT EDIT PLEASE FOR THE LOVE OF GOD
// This is very finicky and easily causes the game to hang for some reason
var provider = level.getChunkSource();

View file

@ -2,10 +2,6 @@ package de.ellpeck.naturesaura;
import com.google.common.base.Strings;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.chunk.effect.DrainSpotEffects;
import de.ellpeck.naturesaura.compat.Compat;
@ -61,11 +57,6 @@ public final class NaturesAura {
}
private void preInit(FMLCommonSetupEvent event) {
Helper.registerCap(IAuraContainer.class);
Helper.registerCap(IAuraRecharge.class);
Helper.registerCap(IAuraChunk.class);
Helper.registerCap(ILevelData.class);
Compat.setup(event);
PacketHandler.init();
new Multiblocks();

View file

@ -51,7 +51,7 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || !(entity instanceof Animal) || entity instanceof Mob || entity instanceof Npc)
return;
BlockPos pos = entity.getOnPos();
BlockPos pos = entity.blockPosition();
Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator gen))
return false;

View file

@ -84,6 +84,6 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
@org.jetbrains.annotations.Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAuraBloom();
return new BlockEntityAuraBloom(pos, state);
}
}

View file

@ -9,11 +9,10 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Tuple;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
@ -21,7 +20,6 @@ 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;
@ -51,11 +49,6 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
return SHAPE;
}
@Override
public Tuple<BlockEntityType<? extends BlockEntityAuraTimer>, Supplier<BlockEntityRendererProvider<BlockEntityAuraTimer>>> getTESR() {
return new Tuple<>(ModTileEntities.AURA_TIMER, () -> RenderAuraTimer::new);
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::cutout;
@ -88,4 +81,8 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
levelIn.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.POWERED, false));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.AURA_TIMER, RenderAuraTimer::new);
}
}

View file

@ -10,15 +10,13 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Tuple;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
@ -29,7 +27,6 @@ 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.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
@ -43,8 +40,6 @@ import net.minecraftforge.network.NetworkHooks;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Random;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, ICustomBlockState {
@ -127,11 +122,6 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
}
}
@Override
public Tuple<BlockEntityType<BlockEntityEnderCrate>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityEnderCrate>>>> getTESR() {
return new Tuple<>(ModTileEntities.ENDER_CRATE, () -> RenderEnderCrate::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
@ -139,4 +129,9 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.ENDER_CRATE, RenderEnderCrate::new);
}
}

View file

@ -6,25 +6,16 @@ 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.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.util.Tuple;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
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.Supplier;
public class BlockGeneratorLimitRemover extends BlockContainerImpl implements ITESRProvider<BlockEntityGeneratorLimitRemover>, ICustomBlockState {
public BlockGeneratorLimitRemover() {
super("generator_limit_remover", BlockEntityGeneratorLimitRemover::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
}
@Override
public Tuple<BlockEntityType<? extends BlockEntityGeneratorLimitRemover>, Supplier<BlockEntityRendererProvider<BlockEntityGeneratorLimitRemover>>> getTESR() {
return new Tuple<>(ModTileEntities.GENERATOR_LIMIT_REMOVER, () -> RenderGeneratorLimitRemover::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
@ -32,4 +23,9 @@ public class BlockGeneratorLimitRemover extends BlockContainerImpl implements IT
generator.modLoc("block/" + this.getBaseName() + "_top"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.GENERATOR_LIMIT_REMOVER, RenderGeneratorLimitRemover::new);
}
}

View file

@ -3,25 +3,25 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor;
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.entity.player.Player;
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.level.Level;
import net.minecraft.core.BlockPos;
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.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
public BlockItemDistributor() {
super("item_distributor", BlockEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS));
super("item_distributor", BlockEntityItemDistributor::new, Properties.copy(Blocks.STONE_BRICKS));
}
@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 BlockEntityItemDistributor))

View file

@ -5,15 +5,15 @@ import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ICustomRenderType;
import de.ellpeck.naturesaura.reg.INoItemBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderType;
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.BlockGetter;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
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.state.BlockState;
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;
@ -22,10 +22,10 @@ import java.util.function.Supplier;
public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemBlock, ICustomRenderType {
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 BlockLight() {
super("light", Properties.create(Material.WOOL).doesNotBlockMovement().setLightLevel(s -> 15));
super("light", Properties.of(Material.WOOL).noCollission().lightLevel(s -> 15));
}
@Override
@ -39,12 +39,12 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) {
public boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) {
return true;
}
@ -56,6 +56,6 @@ public class BlockLight extends BlockImpl implements ICustomBlockState, INoItemB
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -2,23 +2,24 @@ package de.ellpeck.naturesaura.blocks;
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.AABB;
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 BlockMossGenerator extends BlockContainerImpl implements IVisualizable {
public BlockMossGenerator() {
super("moss_generator", BlockEntityMossGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
super("moss_generator", BlockEntityMossGenerator::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
}
@Override
@OnlyIn(Dist.CLIENT)
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(2);
return new AABB(pos).inflate(2);
}
@Override

View file

@ -9,32 +9,25 @@ import de.ellpeck.naturesaura.blocks.tiles.render.RenderNatureAltar;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.tileentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.Player;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.Hand;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
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;
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.ToolType;
import javax.annotation.Nullable;
import java.util.function.Function;
import java.util.function.Supplier;
public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvider<BlockEntityNatureAltar>, ICustomBlockState {
@ -42,8 +35,8 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
public static final BooleanProperty NETHER = BooleanProperty.create("nether");
public BlockNatureAltar() {
super("nature_altar", BlockEntityNatureAltar::new, Block.Properties.create(Material.ROCK).hardnessAndResistance(4F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
this.setDefaultState(this.getDefaultState().with(NETHER, false));
super("nature_altar", BlockEntityNatureAltar::new, Block.Properties.of(Material.STONE).strength(4F));
this.registerDefaultState(this.defaultBlockState().setValue(NETHER, false));
}
@Override
@ -58,30 +51,30 @@ public class BlockNatureAltar extends BlockContainerImpl implements ITESRProvide
@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<BlockEntityNatureAltar>, Supplier<Function<? super BlockEntityRenderDispatcher, ? extends BlockEntityRenderer<? super BlockEntityNatureAltar>>>> getTESR() {
return new Tuple<>(ModTileEntities.NATURE_ALTAR, () -> RenderNatureAltar::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
// noop
}
@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);
}
@Nullable
@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
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.NATURE_ALTAR, RenderNatureAltar::new);
}
}

View file

@ -2,29 +2,29 @@ package de.ellpeck.naturesaura.blocks;
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.block.IGrowable;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.BlockGetter;
import net.minecraft.level.Level;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Random;
public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IGrowable {
public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, BonemealableBlock {
public BlockNetherGrass() {
super("nether_grass", Properties.from(Blocks.NETHERRACK).tickRandomly());
super("nether_grass", Properties.copy(Blocks.NETHERRACK).randomTicks());
}
@Override
public void randomTick(BlockState state, ServerLevel levelIn, BlockPos pos, Random random) {
BlockPos up = pos.up();
BlockPos up = pos.above();
BlockState upState = levelIn.getBlockState(up);
if (upState.isSolidSide(levelIn, up, Direction.DOWN))
levelIn.setBlockState(pos, Blocks.NETHERRACK.getDefaultState());
if (upState.isFaceSturdy(levelIn, up, Direction.DOWN))
levelIn.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());
}
@Override
@ -36,19 +36,19 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
}
@Override
public boolean canGrow(BlockGetter levelIn, BlockPos pos, BlockState state, boolean isClient) {
return levelIn.getBlockState(pos.up()).isAir(levelIn, pos.up());
public boolean isValidBonemealTarget(BlockGetter levelIn, BlockPos pos, BlockState state, boolean isClient) {
return levelIn.getBlockState(pos.above()).isAir();
}
@Override
public boolean canUseBonemeal(Level levelIn, Random rand, BlockPos pos, BlockState state) {
public boolean isBonemealSuccess(Level levelIn, Random rand, BlockPos pos, BlockState state) {
return true;
}
@Override
public void grow(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
BlockPos blockpos = pos.up();
BlockState blockstate = Blocks.GRASS.getDefaultState();
public void performBonemeal(ServerLevel level, Random rand, BlockPos pos, BlockState state) {
BlockPos blockpos = pos.above();
BlockState blockstate = Blocks.GRASS.defaultBlockState();
for (int i = 0; i < 128; ++i) {
BlockPos blockpos1 = blockpos;
@ -58,21 +58,21 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, IG
if (j >= i / 16) {
BlockState blockstate2 = level.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
((IGrowable) blockstate.getBlock()).grow(level, rand, blockpos1, blockstate2);
((BonemealableBlock) blockstate.getBlock()).performBonemeal(level, rand, blockpos1, blockstate2);
}
if (!blockstate2.isAir()) {
break;
}
if (blockstate.isValidPosition(level, blockpos1)) {
level.setBlockState(blockpos1, blockstate, 3);
if (blockstate.canSurvive(level, blockpos1)) {
level.setBlock(blockpos1, blockstate, 3);
}
break;
}
blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (level.getBlockState(blockpos1.down()).getBlock() != this || level.getBlockState(blockpos1).hasOpaqueCollisionShape(level, blockpos1)) {
blockpos1 = blockpos1.offset(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (level.getBlockState(blockpos1.below()).getBlock() != this || level.getBlockState(blockpos1).isCollisionShapeFullBlock(level, blockpos1)) {
break;
}

View file

@ -7,17 +7,16 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOakGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ILevel;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SaplingBlock;
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;
import net.minecraftforge.event.level.SaplingGrowTreeEvent;
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.Random;
@ -25,16 +24,16 @@ import java.util.Random;
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockOakGenerator() {
super("oak_generator", BlockEntityOakGenerator::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
super("oak_generator", BlockEntityOakGenerator::new, Properties.of(Material.WOOD).strength(2F).sound(SoundType.WOOD));
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onTreeGrow(SaplingGrowTreeEvent event) {
ILevel level = event.getLevel();
var level = event.getWorld();
BlockPos pos = event.getPos();
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel((Level) level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
&& level.getBlockState(pos).getBlock() instanceof SaplingBlock) {
Helper.getBlockEntitiesInArea(level, pos, 10, tile -> {
if (!(tile instanceof BlockEntityOakGenerator))
@ -60,7 +59,7 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
@Override
@OnlyIn(Dist.CLIENT)
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(10);
return new AABB(pos).inflate(10);
}
@Override

View file

@ -1,39 +1,33 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityOfferingTable;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderOfferingTable;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
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.tileentity.BlockEntityType;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
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.BlockGetter;
import net.minecraft.level.Level;
import java.util.function.Function;
import java.util.function.Supplier;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
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.SoundType;
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;
public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvider<BlockEntityOfferingTable>, ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(2 / 16F, 0F, 2 / 16F, 14 / 16F, 1F, 14 / 16F);
public BlockOfferingTable() {
super("offering_table", BlockEntityOfferingTable::new, Properties.create(Material.WOOD).hardnessAndResistance(2F).sound(SoundType.WOOD));
super("offering_table", BlockEntityOfferingTable::new, Properties.of(Material.WOOD).strength(2F).sound(SoundType.WOOD));
}
@Override
@ -42,22 +36,22 @@ public class BlockOfferingTable extends BlockContainerImpl implements ITESRProvi
}
@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 VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@Override
public Tuple<BlockEntityType<BlockEntityOfferingTable>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityOfferingTable>>>> getTESR() {
return new Tuple<>(ModTileEntities.OFFERING_TABLE, () -> RenderOfferingTable::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.OFFERING_TABLE, RenderOfferingTable::new);
}
}

View file

@ -7,14 +7,14 @@ 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.item.ItemEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
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.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;
@ -22,8 +22,9 @@ import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPickupStopper() {
super("pickup_stopper", BlockEntityPickupStopper::new, Properties.create(Material.ROCK).hardnessAndResistance(2F).sound(SoundType.STONE));
super("pickup_stopper", BlockEntityPickupStopper::new, Properties.of(Material.STONE).strength(2F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this);
}
@ -31,25 +32,24 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
@SubscribeEvent
public void onPickup(EntityItemPickupEvent event) {
Player player = event.getPlayer();
if (player != null && !player.isSneaking()) {
if (player != null && !player.isCrouching()) {
ItemEntity item = event.getItem();
BlockPos pos = item.getPosition();
BlockPos pos = item.blockPosition();
Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
if (!(tile instanceof BlockEntityPickupStopper))
if (!(tile instanceof BlockEntityPickupStopper stopper))
return false;
BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) tile;
float radius = stopper.getRadius();
if (radius <= 0F)
return false;
BlockPos stopperPos = stopper.getPos();
if (!new AABB(stopperPos).grow(radius).intersects(item.getBoundingBox()))
BlockPos stopperPos = stopper.getBlockPos();
if (!new AABB(stopperPos).inflate(radius).intersects(item.getBoundingBox()))
return false;
event.setCanceled(true);
if (item.level.getGameTime() % 3 == 0)
PacketHandler.sendToAllAround(item.level, pos, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.PICKUP_STOPPER));
new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.PICKUP_STOPPER));
return true;
});
}
@ -62,7 +62,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
if (tile instanceof BlockEntityPickupStopper) {
double radius = ((BlockEntityPickupStopper) tile).getRadius();
if (radius > 0)
return new AABB(pos).grow(radius);
return new AABB(pos).inflate(radius);
}
return null;
}

View file

@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPlacer;
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.AABB;
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 BlockPlacer extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockPlacer() {
super("placer", BlockEntityPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
super("placer", BlockEntityPlacer::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
}
@Override
@OnlyIn(Dist.CLIENT)
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(5);
return new AABB(pos).inflate(5);
}
@Override

View file

@ -3,12 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPotionGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ToolType;
import net.minecraft.world.level.material.Material;
public class BlockPotionGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockPotionGenerator() {
super("potion_generator", BlockEntityPotionGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(5F).harvestTool(ToolType.PICKAXE).harvestLevel(1));
super("potion_generator", BlockEntityPotionGenerator::new, Properties.of(Material.STONE).strength(5F));
}
@Override

View file

@ -3,21 +3,21 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityPowderPlacer;
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.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.BlockGetter;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBlockState {
private static final VoxelShape SHAPE = Shapes.create(0F, 0F, 0F, 1F, 4 / 16F, 1F);
public BlockPowderPlacer() {
super("powder_placer", BlockEntityPowderPlacer::new, Properties.create(Material.ROCK).hardnessAndResistance(2, 5F).sound(SoundType.STONE));
super("powder_placer", BlockEntityPowderPlacer::new, Properties.of(Material.STONE).strength(2, 5F).sound(SoundType.STONE));
}
@Override
@ -26,7 +26,7 @@ public class BlockPowderPlacer extends BlockContainerImpl implements ICustomBloc
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}

View file

@ -1,69 +1,62 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator;
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 de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.block.DispenserBlock;
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.dispenser.IPosition;
import net.minecraft.dispenser.ProjectileDispenseBehavior;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.entity.projectile.AbstractArrowEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.TridentEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.level.Level;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.util.function.Function;
import java.util.function.Supplier;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider<BlockEntityProjectileGenerator>, ICustomBlockState {
public BlockProjectileGenerator() {
super("projectile_generator", BlockEntityProjectileGenerator::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
super("projectile_generator", BlockEntityProjectileGenerator::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
MinecraftForge.EVENT_BUS.register(this);
DispenserBlock.registerDispenseBehavior(Items.ENDER_PEARL, new ProjectileDispenseBehavior() {
DispenserBlock.registerBehavior(Items.ENDER_PEARL, new AbstractProjectileDispenseBehavior() {
@Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) {
EnderPearlEntity ret = new EnderPearlEntity(EntityType.ENDER_PEARL, levelIn);
ret.setPosition(position.getX(), position.getY(), position.getZ());
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
ThrownEnderpearl ret = new ThrownEnderpearl(EntityType.ENDER_PEARL, levelIn);
ret.setPos(position.x(), position.y(), position.z());
return ret;
}
});
DispenserBlock.registerDispenseBehavior(Items.TRIDENT, new ProjectileDispenseBehavior() {
DispenserBlock.registerBehavior(Items.TRIDENT, new AbstractProjectileDispenseBehavior() {
@Override
protected ProjectileEntity getProjectileEntity(Level levelIn, IPosition position, ItemStack stackIn) {
TridentEntity ret = new TridentEntity(EntityType.TRIDENT, levelIn);
ret.setPosition(position.getX(), position.getY(), position.getZ());
// set thrownStack
ObfuscationReflectionHelper.setPrivateValue(TridentEntity.class, ret, stackIn.copy(), "field_203054_h");
ret.pickupStatus = AbstractArrowEntity.PickupStatus.ALLOWED;
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
ThrownTrident ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
ret.setPos(position.x(), position.y(), position.z());
ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "tridentItem");
ret.pickup = AbstractArrow.Pickup.ALLOWED;
return ret;
}
});
@ -74,18 +67,16 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
Entity entity = event.getEntity();
if (entity.level.isClientSide)
return;
RayTraceResult ray = event.getRayTraceResult();
if (!(ray instanceof BlockRayTraceResult))
HitResult ray = event.getRayTraceResult();
if (!(ray instanceof BlockHitResult blockRay))
return;
BlockRayTraceResult blockRay = (BlockRayTraceResult) ray;
BlockPos pos = blockRay.getPos();
BlockPos pos = blockRay.getBlockPos();
if (pos == null)
return;
BlockEntity tile = entity.level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityProjectileGenerator))
if (!(tile instanceof BlockEntityProjectileGenerator generator))
return;
BlockEntityProjectileGenerator generator = (BlockEntityProjectileGenerator) tile;
if (generator.nextSide != blockRay.getFace())
if (generator.nextSide != blockRay.getDirection())
return;
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
if (amount == null || amount <= 0)
@ -95,21 +86,16 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
generator.generateAura(amount);
PacketHandler.sendToAllAround(entity.level, pos, 32,
new PacketParticles((float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ()));
entity.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F);
new PacketParticles((float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.PROJECTILE_GEN, pos.getX(), pos.getY(), pos.getZ()));
entity.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENDER_EYE_LAUNCH, SoundSource.BLOCKS, 0.8F, 1F);
generator.nextSide = generator.nextSide.rotateY();
generator.nextSide = generator.nextSide.getClockWise();
generator.sendToClients();
entity.remove();
entity.kill();
event.setCanceled(true);
}
@Override
public Tuple<BlockEntityType<BlockEntityProjectileGenerator>, Supplier<Function<? super BlockEntityRendererDispatcher, ? extends BlockEntityRenderer<? super BlockEntityProjectileGenerator>>>> getTESR() {
return new Tuple<>(ModTileEntities.PROJECTILE_GENERATOR, () -> RenderProjectileGenerator::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
@ -117,4 +103,9 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
generator.modLoc("block/" + this.getBaseName() + "_top"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.PROJECTILE_GENERATOR, RenderProjectileGenerator::new);
}
}

View file

@ -3,17 +3,17 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityRFConverter;
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 BlockRFConverter extends BlockContainerImpl {
public BlockRFConverter() {
super("rf_converter", BlockEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3));
super("rf_converter", BlockEntityRFConverter::new, Properties.of(Material.STONE).sound(SoundType.STONE).strength(3));
}
@Override
public String getTranslationKey() {
return ModConfig.instance.rfConverter.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
public String getDescriptionId() {
return ModConfig.instance.rfConverter.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
}
}

View file

@ -5,12 +5,12 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySlimeSplitGenerator;
import de.ellpeck.naturesaura.data.BlockStateGenerator;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Slime;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
@ -18,8 +18,9 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSlimeSplitGenerator() {
super("slime_split_generator", BlockEntitySlimeSplitGenerator::new, Properties.from(Blocks.SLIME_BLOCK).hardnessAndResistance(2));
super("slime_split_generator", BlockEntitySlimeSplitGenerator::new, Properties.copy(Blocks.SLIME_BLOCK).strength(2));
MinecraftForge.EVENT_BUS.register(new Events());
}
@ -34,7 +35,7 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@Override
@OnlyIn(Dist.CLIENT)
public AABB getVisualizationBounds(Level level, BlockPos pos) {
return new AABB(pos).grow(8);
return new AABB(pos).inflate(8);
}
@Override
@ -48,16 +49,14 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving();
if (!(entity instanceof SlimeEntity) || entity.level.isClientSide)
if (!(entity instanceof Slime slime) || entity.level.isClientSide)
return;
SlimeEntity slime = (SlimeEntity) entity;
int size = slime.getSlimeSize();
int size = slime.getSize();
if (size <= 1)
return;
Helper.getBlockEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> {
if (!(tile instanceof BlockEntitySlimeSplitGenerator))
Helper.getBlockEntitiesInArea(entity.level, entity.blockPosition(), 8, tile -> {
if (!(tile instanceof BlockEntitySlimeSplitGenerator gen))
return false;
BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) tile;
if (gen.isBusy())
return false;
gen.startGenerating(slime);

View file

@ -4,17 +4,18 @@ import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySnowCreator;
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.AABB;
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.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSnowCreator() {
super("snow_creator", BlockEntitySnowCreator::new, Properties.from(Blocks.STONE_BRICKS));
super("snow_creator", BlockEntitySnowCreator::new, Properties.copy(Blocks.STONE_BRICKS));
}
@Override
@ -24,7 +25,7 @@ public class BlockSnowCreator extends BlockContainerImpl implements IVisualizabl
if (tile instanceof BlockEntitySnowCreator) {
int radius = ((BlockEntitySnowCreator) tile).getRange();
if (radius > 0)
return new AABB(pos).grow(radius);
return new AABB(pos).inflate(radius);
}
return null;
}

View file

@ -10,22 +10,22 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
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.MobEntity;
import net.minecraft.tileentity.BlockEntity;
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.BlockGetter;
import net.minecraft.level.ILevel;
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.entity.Mob;
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.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
@ -40,7 +40,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
private static final VoxelShape SHAPE = Shapes.create(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);
public BlockSpawnLamp() {
super("spawn_lamp", BlockEntitySpawnLamp::new, Properties.create(Material.IRON).hardnessAndResistance(3F).setLightLevel(s -> 15).sound(SoundType.METAL));
super("spawn_lamp", BlockEntitySpawnLamp::new, Properties.of(Material.METAL).strength(3F).lightLevel(s -> 15).sound(SoundType.METAL));
MinecraftForge.EVENT_BUS.register(this);
}
@ -53,7 +53,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
public void onSpawn(LivingSpawnEvent.CheckSpawn event) {
if (event.getSpawner() != null)
return;
ILevel level = event.getLevel();
LevelAccessor level = event.getWorld();
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
if (!(level instanceof Level))
return;
@ -66,14 +66,14 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
if (range <= 0)
continue;
BlockPos lampPos = lamp.getPos();
if (!new AABB(lampPos).grow(range).contains(new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)))
BlockPos lampPos = lamp.getBlockPos();
if (!new AABB(lampPos).inflate(range).contains(new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)))
continue;
MobEntity entity = (MobEntity) event.getEntityLiving();
if (entity.canSpawn(level, event.getSpawnReason()) && entity.isNotColliding(level)) {
BlockPos spot = IAuraChunk.getHighestSpot(level, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 200);
Mob entity = (Mob) event.getEntityLiving();
if (entity.checkSpawnRules(level, event.getSpawnReason()) && entity.checkSpawnObstruction(level)) {
BlockPos spot = IAuraChunk.getHighestSpot((Level) level, lampPos, 32, lampPos);
IAuraChunk.getAuraChunk((Level) level, spot).drainAura(spot, 200);
PacketHandler.sendToAllAround((ServerLevel) level, lampPos, 32,
new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), PacketParticles.Type.SPAWN_LAMP));
@ -85,7 +85,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, ISelectionContext context) {
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
return SHAPE;
}
@ -96,7 +96,7 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
if (tile instanceof BlockEntitySpawnLamp) {
int radius = ((BlockEntitySpawnLamp) tile).getRadius();
if (radius > 0)
return new AABB(pos).grow(radius);
return new AABB(pos).inflate(radius);
}
return null;
}
@ -114,6 +114,6 @@ public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable,
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getCutoutMipped;
return RenderType::cutoutMipped;
}
}

View file

@ -6,46 +6,49 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
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.IBucketPickupHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.Player;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.ILevel;
import net.minecraft.level.biome.BiomeColors;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BucketPickup;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.Optional;
import java.util.function.Supplier;
public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, IBucketPickupHandler, ICustomRenderType {
public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, BucketPickup, ICustomRenderType {
public BlockSpring() {
super("spring", BlockEntitySpring::new, Properties.from(Blocks.STONE_BRICKS));
super("spring", BlockEntitySpring::new, Properties.copy(Blocks.STONE_BRICKS));
}
@Override
@OnlyIn(Dist.CLIENT)
public IBlockColor getBlockColor() {
return (state, level, pos, i) -> BiomeColors.getWaterColor(level, pos);
public BlockColor getBlockColor() {
return (state, level, pos, i) -> BiomeColors.getAverageWaterColor(level, pos);
}
@Override
@OnlyIn(Dist.CLIENT)
@SuppressWarnings("Convert2Lambda")
public IItemColor getItemColor() {
return new IItemColor() {
public ItemColor getItemColor() {
return new ItemColor() {
@Override
public int getColor(ItemStack stack, int i) {
Player player = Minecraft.getInstance().player;
return BiomeColors.getWaterColor(player.level, player.getPosition());
return BiomeColors.getAverageWaterColor(player.level, player.blockPosition());
}
};
}
@ -55,16 +58,21 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
public Fluid pickupFluid(ILevel levelIn, BlockPos pos, BlockState state) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500);
return Fluids.WATER;
}
@Override
public Supplier<RenderType> getRenderType() {
return RenderType::getTranslucent;
return RenderType::translucent;
}
@Override
public ItemStack pickupBlock(LevelAccessor levelIn, BlockPos pos, BlockState state) {
BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntitySpring)
((BlockEntitySpring) tile).consumeAura(2500);
return new ItemStack(Items.WATER_BUCKET); }
@Override
public Optional<SoundEvent> getPickupSound() {
return Fluids.WATER.getPickupSound();
}
}

View file

@ -3,12 +3,13 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityTimeChanger;
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.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
public class BlockTimeChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockTimeChanger() {
super("time_changer", BlockEntityTimeChanger::new, Properties.create(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
super("time_changer", BlockEntityTimeChanger::new, Properties.of(Material.STONE).strength(2.5F).sound(SoundType.STONE));
}
@Override

View file

@ -3,11 +3,12 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWeatherChanger;
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 BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockWeatherChanger() {
super("weather_changer", BlockEntityWeatherChanger::new, Properties.from(Blocks.STONE_BRICKS));
super("weather_changer", BlockEntityWeatherChanger::new, Properties.copy(Blocks.STONE_BRICKS));
}
@Override

View file

@ -10,9 +10,8 @@ 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.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Tuple;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
@ -23,7 +22,6 @@ 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;
@ -38,7 +36,6 @@ import org.apache.commons.lang3.mutable.MutableObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState {
@ -111,14 +108,13 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
return Helper.putStackOnTile(player, handIn, pos, 0, true);
}
@Override
public Tuple<BlockEntityType<? extends BlockEntityWoodStand>, Supplier<BlockEntityRendererProvider<BlockEntityWoodStand>>> getTESR() {
return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new);
}
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
@Override
public void registerTESR() {
BlockEntityRenderers.register(ModTileEntities.WOOD_STAND, RenderWoodStand::new);
}
}

View file

@ -96,7 +96,7 @@ public class Multiblock implements IMultiblock {
Matcher matcher = matchers.get(this.rawPattern[x][y][z]);
if (matcher == null)
throw new IllegalStateException();
if (matcher.getCheck() != null)
if (matcher.check() != null)
this.matchers.put(new BlockPos(x, y, z), matcher);
}
@ -109,7 +109,7 @@ public class Multiblock implements IMultiblock {
BlockPos start = this.getStart(center);
return this.forEach(center, (char) 0, (pos, matcher) -> {
BlockPos offset = pos.subtract(start);
return matcher.getCheck().matches(level, start, offset, pos, level.getBlockState(pos), this.getChar(offset));
return matcher.check().matches(level, start, offset, pos, level.getBlockState(pos), this.getChar(offset));
});
}

View file

@ -25,8 +25,6 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler;
import java.util.Random;
public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickableBlockEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
@ -49,7 +47,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
@Override
protected boolean canExtract(ItemStack stack, int slot, int amount) {
IAuraContainer cap = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
var cap = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (cap != null)
return cap.storeAura(1, true) <= 0;
else
@ -72,14 +70,14 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
@Override
public void tick() {
Random rand = this.level.random;
var rand = this.level.random;
if (this.level.getGameTime() % 40 == 0) {
int index = 0;
for (int x = -2; x <= 2; x += 4) {
for (int z = -2; z <= 2; z += 4) {
BlockPos offset = this.worldPosition.offset(x, 1, z);
BlockState state = this.level.getBlockState(offset);
var index = 0;
for (var x = -2; x <= 2; x += 4) {
for (var z = -2; z <= 2; z += 4) {
var offset = this.worldPosition.offset(x, 1, z);
var state = this.level.getBlockState(offset);
this.catalysts[index] = state.getBlock().getCloneItemStack(this.level, offset, state);
index++;
}
@ -88,7 +86,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
if (!this.level.isClientSide) {
if (this.level.getGameTime() % 40 == 0 || this.firstTick) {
StructureState newState = this.getNewState();
var newState = this.getNewState();
if (newState != this.structureState) {
this.structureState = newState;
this.sendToClients();
@ -97,13 +95,13 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
}
if (this.structureState != StructureState.INVALID) {
int space = this.container.storeAura(300, true);
var space = this.container.storeAura(300, true);
IAuraType expectedType = this.structureState == StructureState.NETHER ? NaturesAuraAPI.TYPE_NETHER : NaturesAuraAPI.TYPE_OVERWORLD;
if (space > 0 && IAuraType.forLevel(this.level).isSimilar(expectedType)) {
int toStore = Math.min(IAuraChunk.getAuraInArea(this.level, this.worldPosition, 20), space);
var toStore = Math.min(IAuraChunk.getAuraInArea(this.level, this.worldPosition, 20), space);
if (toStore > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot);
var spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
var chunk = IAuraChunk.getAuraChunk(this.level, spot);
chunk.drainAura(spot, toStore);
this.container.storeAura(toStore, false);
@ -114,17 +112,17 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.worldPosition.getY() + rand.nextFloat() * 10F,
this.worldPosition.getZ() + (float) rand.nextGaussian() * 10F,
this.worldPosition.getX() + 0.5F, this.worldPosition.getY() + 0.5F, this.worldPosition.getZ() + 0.5F,
rand.nextFloat() * 0.1F + 0.1F, this.container.getAuraColor(), rand.nextFloat() * 1F + 1F
rand.nextFloat() * 0.1F + 0.1F, this.container.getAuraColor(), rand.nextFloat() + 1F
));
}
}
ItemStack stack = this.items.getStackInSlot(0);
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
var stack = this.items.getStackInSlot(0);
var container = stack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (!stack.isEmpty() && container != null) {
int theoreticalDrain = this.container.drainAura(1000, true);
var theoreticalDrain = this.container.drainAura(1000, true);
if (theoreticalDrain > 0) {
int stored = container.storeAura(theoreticalDrain, false);
var stored = container.storeAura(theoreticalDrain, false);
if (stored > 0) {
this.container.drainAura(stored, false);
@ -142,7 +140,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.currentRecipe = null;
this.timer = 0;
} else {
int req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time);
var req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time);
if (this.container.getStoredAura() >= req) {
this.container.drainAura(req, false);
@ -170,7 +168,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} else {
if (this.structureState != StructureState.INVALID) {
if (rand.nextFloat() >= 0.7F) {
int fourths = this.container.getMaxAura() / 4;
var fourths = this.container.getMaxAura() / 4;
if (this.container.getStoredAura() > 0) {
NaturesAuraAPI.instance().spawnMagicParticle(
this.worldPosition.getX() - 4F + rand.nextFloat(), this.worldPosition.getY() + 3F, this.worldPosition.getZ() + rand.nextFloat(),
@ -200,12 +198,12 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
}
private AltarRecipe getRecipeForInput(ItemStack input) {
IAuraType type = IAuraType.forLevel(this.level);
for (AltarRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, null)) {
var type = IAuraType.forLevel(this.level);
for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, null)) {
if (recipe.input.test(input) && (recipe.requiredType == null || type.isSimilar(recipe.requiredType))) {
if (recipe.catalyst == Ingredient.EMPTY)
return recipe;
for (ItemStack stack : this.catalysts)
for (var stack : this.catalysts)
if (recipe.catalyst.test(stack))
return recipe;
}

View file

@ -7,12 +7,17 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RenderEnderCrate implements BlockEntityRenderer<BlockEntityEnderCrate> {
public RenderEnderCrate(BlockEntityRendererProvider.Context context) {
}
@Override
public void render(BlockEntityEnderCrate tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
Matrix4f matrix4f = matrixStackIn.last().pose();

View file

@ -7,10 +7,15 @@ import net.minecraft.client.Minecraft;
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.ItemStack;
public class RenderNatureAltar implements BlockEntityRenderer<BlockEntityNatureAltar> {
public RenderNatureAltar(BlockEntityRendererProvider.Context context) {
}
@Override
public void render(BlockEntityNatureAltar tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityIn.items.getStackInSlot(0);

View file

@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft;
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.util.Mth;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
@ -18,6 +19,10 @@ public class RenderOfferingTable implements BlockEntityRenderer<BlockEntityOffer
private final Random rand = new Random();
public RenderOfferingTable(BlockEntityRendererProvider.Context context) {
}
@Override
public void render(BlockEntityOfferingTable tileEntityOfferingTable, float v, PoseStack matrixStack, MultiBufferSource iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
ItemStack stack = tileEntityOfferingTable.items.getStackInSlot(0);

View file

@ -6,6 +6,7 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityProjectileGenerator;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
@ -17,6 +18,10 @@ public class RenderProjectileGenerator implements BlockEntityRenderer<BlockEntit
private static final ResourceLocation RES = new ResourceLocation(NaturesAura.MOD_ID, "textures/models/projectile_generator_overlay.png");
//private final ModelOverlay model = new ModelOverlay();
public RenderProjectileGenerator(BlockEntityRendererProvider.Context context) {
}
@Override
public void render(BlockEntityProjectileGenerator te, float partialTicks, PoseStack stack, MultiBufferSource buffer, int combinedLightIn, int combinedOverlayIn) {
stack.pushPose();

View file

@ -3,9 +3,9 @@ package de.ellpeck.naturesaura.chunk;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Direction;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;
@ -16,11 +16,11 @@ import javax.annotation.Nullable;
public class AuraChunkProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> {
private final Chunk chunk;
private final LevelChunk chunk;
private final LazyOptional<IAuraChunk> lazyChunk = LazyOptional.of(this::getAuraChunk);
private IAuraChunk auraChunk;
public AuraChunkProvider(Chunk chunk) {
public AuraChunkProvider(LevelChunk chunk) {
this.chunk = chunk;
}

View file

@ -5,16 +5,16 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.entity.IAngerable;
import net.minecraft.entity.LivingEntity;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.NeutralMob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import java.util.List;
@ -33,43 +33,44 @@ public class AngerEffect implements IDrainSpotEffect {
int dist = Math.min(Math.abs(aura) / 50000, 75);
if (dist < 10)
return false;
this.bb = new AABB(pos).grow(dist);
this.bb = new AABB(pos).inflate(dist);
return true;
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (!this.bb.contains(player.getPositionVec()))
if (!this.bb.contains(player.getEyePosition()))
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@Override
public ItemStack getDisplayIcon() {
return new ItemStack(Items.FIRE_CHARGE);
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 100 != 0)
return;
if (!this.calcValues(level, pos, spot))
return;
List<LivingEntity> entities = level.getEntitiesWithinAABB(LivingEntity.class, this.bb);
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
for (LivingEntity entity : entities) {
if (!(entity instanceof IAngerable))
if (!(entity instanceof NeutralMob))
continue;
Player player = level.getClosestPlayer(entity, 25);
Player player = level.getNearestPlayer(entity, 25);
if (player == null)
continue;
((IAngerable) entity).setAttackTarget(player);
((NeutralMob) entity).setTarget(player);
}
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.angerEffect.get();
}

View file

@ -6,22 +6,21 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.ChickenEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.item.EggItem;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Chicken;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.EggItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Comparator;
@ -46,17 +45,17 @@ public class AnimalEffect implements IDrainSpotEffect {
if (this.chance <= 0)
return false;
int dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
this.bb = new AABB(pos).grow(dist);
this.bb = new AABB(pos).inflate(dist);
return true;
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (!this.bb.contains(player.getPositionVec()))
if (!this.bb.contains(player.getEyePosition()))
return ActiveType.INACTIVE;
if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getPosition(), NAME))
if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), NAME))
return ActiveType.INHIBITED;
return ActiveType.ACTIVE;
}
@ -67,87 +66,85 @@ public class AnimalEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 200 != 0)
return;
if (!this.calcValues(level, pos, spot))
return;
List<AnimalEntity> animals = level.getEntitiesWithinAABB(AnimalEntity.class, this.bb);
List<Animal> animals = level.getEntitiesOfClass(Animal.class, this.bb);
if (animals.size() >= ModConfig.instance.maxAnimalsAroundPowder.get())
return;
List<ItemEntity> items = level.getEntitiesWithinAABB(ItemEntity.class, this.bb);
List<ItemEntity> items = level.getEntitiesOfClass(ItemEntity.class, this.bb);
for (ItemEntity item : items) {
if (!item.isAlive())
continue;
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, item.getPosition(), NAME))
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, item.blockPosition(), NAME))
continue;
ItemStack stack = item.getItem();
if (!(stack.getItem() instanceof EggItem))
continue;
// The getAge() method is client-side only for absolutely no reason but I want it so I don't care
int age = ObfuscationReflectionHelper.getPrivateValue(ItemEntity.class, item, "field_70292_b");
if (age < item.lifespan / 2)
if (item.getAge() < item.lifespan / 2)
continue;
if (stack.getCount() <= 1)
item.remove();
item.kill();
else {
stack.shrink(1);
item.setItem(stack);
}
ChickenEntity chicken = new ChickenEntity(EntityType.CHICKEN, level);
chicken.setGrowingAge(-24000);
chicken.setPosition(item.getPosX(), item.getPosY(), item.getPosZ());
level.addEntity(chicken);
Chicken chicken = new Chicken(EntityType.CHICKEN, level);
chicken.setAge(-24000);
chicken.setPos(item.getX(), item.getY(), item.getZ());
level.addFreshEntity(chicken);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, item.getPosition(), 35, pos);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, item.blockPosition(), 35, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 2000);
}
if (level.rand.nextInt(20) <= this.chance) {
if (level.random.nextInt(20) <= this.chance) {
if (animals.size() < 2)
return;
AnimalEntity first = animals.get(level.rand.nextInt(animals.size()));
if (first.isChild() || first.isInLove())
Animal first = animals.get(level.random.nextInt(animals.size()));
if (first.isBaby() || first.isInLove())
return;
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, first.getPosition(), NAME))
if (!NaturesAuraAPI.instance().isEffectPowderActive(level, first.blockPosition(), NAME))
return;
Optional<AnimalEntity> secondOptional = animals.stream()
.filter(e -> e != first && !e.isInLove() && !e.isChild())
.min(Comparator.comparingDouble(e -> e.getDistanceSq(first)));
if (!secondOptional.isPresent())
Optional<Animal> secondOptional = animals.stream()
.filter(e -> e != first && !e.isInLove() && !e.isBaby())
.min(Comparator.comparingDouble(e -> e.distanceToSqr(first)));
if (secondOptional.isEmpty())
return;
AnimalEntity second = secondOptional.get();
if (second.getDistanceSq(first) > 5 * 5)
Animal second = secondOptional.get();
if (second.distanceToSqr(first) > 5 * 5)
return;
this.setInLove(first);
this.setInLove(second);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, first.getPosition(), 35, pos);
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, first.blockPosition(), 35, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 3500);
}
}
private void setInLove(AnimalEntity animal) {
private void setInLove(Animal animal) {
animal.setInLove(null);
for (int j = 0; j < 7; j++)
animal.level.addParticle(ParticleTypes.HEART,
animal.getPosX() + (double) (animal.level.rand.nextFloat() * animal.getWidth() * 2.0F) - animal.getWidth(),
animal.getPosY() + 0.5D + (double) (animal.level.rand.nextFloat() * animal.getHeight()),
animal.getPosZ() + (double) (animal.level.rand.nextFloat() * animal.getWidth() * 2.0F) - animal.getWidth(),
animal.level.rand.nextGaussian() * 0.02D,
animal.level.rand.nextGaussian() * 0.02D,
animal.level.rand.nextGaussian() * 0.02D);
animal.getX() + (double) (animal.level.random.nextFloat() * animal.getBbWidth() * 2.0F) - animal.getBbWidth(),
animal.getY() + 0.5D + (double) (animal.level.random.nextFloat() * animal.getBbHeight()),
animal.getZ() + (double) (animal.level.random.nextFloat() * animal.getBbWidth() * 2.0F) - animal.getBbWidth(),
animal.level.random.nextGaussian() * 0.02D,
animal.level.random.nextGaussian() * 0.02D,
animal.level.random.nextGaussian() * 0.02D);
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.animalEffect.get();
}

View file

@ -4,10 +4,10 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import org.apache.commons.lang3.mutable.MutableInt;
public class BalanceEffect implements IDrainSpotEffect {
@ -15,7 +15,7 @@ public class BalanceEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "balance");
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (spot < 100000)
return;
if (level.getGameTime() % 200 != 0)
@ -35,7 +35,7 @@ public class BalanceEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return true;
}

View file

@ -6,17 +6,17 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.potion.ModPotions;
import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import java.util.List;
@ -37,15 +37,15 @@ public class BreathlessEffect implements IDrainSpotEffect {
if (dist < 10)
return false;
this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3);
this.bb = new AABB(pos).grow(dist);
this.bb = new AABB(pos).inflate(dist);
return true;
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (!this.bb.contains(player.getPositionVec()))
if (!this.bb.contains(player.getEyePosition()))
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@ -56,18 +56,18 @@ public class BreathlessEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 100 != 0)
return;
if (!this.calcValues(level, pos, spot))
return;
List<LivingEntity> entities = level.getEntitiesWithinAABB(LivingEntity.class, this.bb);
List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, this.bb);
for (LivingEntity entity : entities)
entity.addPotionEffect(new EffectInstance(ModPotions.BREATHLESS, 300, this.amp));
entity.addEffect(new MobEffectInstance(ModPotions.BREATHLESS, 300, this.amp));
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.breathlessEffect.get();
}

View file

@ -7,14 +7,14 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
@ -34,18 +34,18 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
if (aura < 1500000)
return false;
int dist = Mth.clamp(aura / 3500, 3, 15);
this.bb = new AABB(pos).grow(dist);
this.bb = new AABB(pos).inflate(dist);
this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight());
return true;
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (!this.bb.contains(player.getPositionVec()))
if (!this.bb.contains(player.getEyePosition()))
return ActiveType.INACTIVE;
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getPosition(), NAME))
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), NAME))
return ActiveType.INHIBITED;
return ActiveType.ACTIVE;
}
@ -56,12 +56,12 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot))
return;
List<Player> players = level.getEntitiesWithinAABB(Player.class, this.bb);
List<Player> players = level.getEntitiesOfClass(Player.class, this.bb);
for (Player player : players) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, player.getPosition(), NAME))
if (NaturesAuraAPI.instance().isEffectPowderActive(level, player.blockPosition(), NAME))
continue;
if (NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, true)) {
NaturesAuraAPI.instance().insertAuraIntoPlayer(player, this.amount, false);
@ -71,7 +71,7 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.cacheRechargeEffect.get();
}

View file

@ -5,16 +5,16 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Explosion;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.level.gen.Heightmap;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.levelgen.Heightmap;
public class ExplosionEffect implements IDrainSpotEffect {
@ -30,7 +30,7 @@ public class ExplosionEffect implements IDrainSpotEffect {
if (aura > -5000000)
return false;
int chance = 140 - Math.abs(aura) / 200000;
if (chance > 1 && level.rand.nextInt(chance) != 0)
if (chance > 1 && level.random.nextInt(chance) != 0)
return false;
this.strength = Math.min(Math.abs(aura) / 5000000F, 5F);
if (this.strength <= 0)
@ -40,10 +40,10 @@ public class ExplosionEffect implements IDrainSpotEffect {
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@ -54,24 +54,24 @@ public class ExplosionEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 40 != 0)
return;
if (!this.calcValues(level, pos, spot))
return;
int x = Mth.floor(pos.getX() + level.rand.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.rand.nextGaussian() * this.dist);
BlockPos chosenPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
if (chosenPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(chosenPos)) {
level.createExplosion(null,
int x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist);
BlockPos chosenPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z);
if (chosenPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(chosenPos)) {
level.explode(null,
chosenPos.getX() + 0.5, chosenPos.getY() + 0.5, chosenPos.getZ() + 0.5,
this.strength, false, Explosion.Mode.DESTROY);
this.strength, false, Explosion.BlockInteraction.DESTROY);
}
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.explosionEffect.get();
}

View file

@ -7,14 +7,15 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.*;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import org.apache.commons.lang3.tuple.Pair;
public class GrassDieEffect implements IDrainSpotEffect {
@ -40,10 +41,10 @@ public class GrassDieEffect implements IDrainSpotEffect {
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@ -54,37 +55,37 @@ public class GrassDieEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot))
return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
BlockPos grassPos = new BlockPos(
pos.getX() + level.rand.nextGaussian() * this.dist,
pos.getY() + level.rand.nextGaussian() * this.dist,
pos.getZ() + level.rand.nextGaussian() * this.dist
pos.getX() + level.random.nextGaussian() * this.dist,
pos.getY() + level.random.nextGaussian() * this.dist,
pos.getZ() + level.random.nextGaussian() * this.dist
);
if (grassPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(grassPos)) {
if (grassPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(grassPos)) {
BlockState state = level.getBlockState(grassPos);
Block block = state.getBlock();
BlockState newState = null;
if (block instanceof LeavesBlock) {
newState = ModBlocks.DECAYED_LEAVES.getDefaultState();
newState = ModBlocks.DECAYED_LEAVES.defaultBlockState();
} else if (block instanceof GrassBlock) {
newState = Blocks.COARSE_DIRT.getDefaultState();
newState = Blocks.COARSE_DIRT.defaultBlockState();
} else if (block instanceof BushBlock) {
newState = Blocks.AIR.getDefaultState();
newState = Blocks.AIR.defaultBlockState();
} else if (block == ModBlocks.NETHER_GRASS) {
newState = Blocks.NETHERRACK.getDefaultState();
newState = Blocks.NETHERRACK.defaultBlockState();
}
if (newState != null)
level.setBlockState(grassPos, newState);
level.setBlockAndUpdate(grassPos, newState);
}
}
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.grassDieEffect.get() && (type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) || type.isSimilar(NaturesAuraAPI.TYPE_NETHER));
}

View file

@ -6,20 +6,20 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import org.apache.commons.lang3.tuple.Pair;
public class NetherDecayEffect implements IDrainSpotEffect {
@ -44,10 +44,10 @@ public class NetherDecayEffect implements IDrainSpotEffect {
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
return ActiveType.ACTIVE;
}
@ -58,15 +58,15 @@ public class NetherDecayEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot))
return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
BlockPos offset = new BlockPos(
pos.getX() + level.rand.nextGaussian() * this.dist,
pos.getY() + level.rand.nextGaussian() * this.dist,
pos.getZ() + level.rand.nextGaussian() * this.dist);
if (offset.distanceSq(pos) > this.dist * this.dist || !level.isBlockLoaded(offset))
pos.getX() + level.random.nextGaussian() * this.dist,
pos.getY() + level.random.nextGaussian() * this.dist,
pos.getZ() + level.random.nextGaussian() * this.dist);
if (offset.distSqr(pos) > this.dist * this.dist || !level.isLoaded(offset))
continue;
// degrade blocks
@ -74,27 +74,27 @@ public class NetherDecayEffect implements IDrainSpotEffect {
BlockState state = level.getBlockState(offset);
if (state.getBlock() == Blocks.GLOWSTONE) {
degraded = Blocks.NETHERRACK;
} else if (state.getBlock().isIn(BlockTags.NYLIUM) || state.getBlock() == Blocks.NETHERRACK) {
} else if (state.is(BlockTags.NYLIUM) || state.getBlock() == Blocks.NETHERRACK) {
degraded = Blocks.SOUL_SOIL;
} else if (state.getBlock() == Blocks.SOUL_SOIL) {
degraded = Blocks.SOUL_SAND;
}
if (degraded != null) {
level.playEvent(2001, offset, Block.getStateId(state));
level.setBlockState(offset, degraded.getDefaultState());
level.levelEvent(2001, offset, Block.getId(state));
level.setBlockAndUpdate(offset, degraded.defaultBlockState());
}
// ignite blocks
if (AbstractFireBlock.canLightBlock(level, offset, Direction.NORTH)) {
BlockState fire = AbstractFireBlock.getFireForPlacement(level, offset);
level.setBlockState(offset, fire);
level.playEvent(1009, offset, 0);
if (BaseFireBlock.canBePlacedAt(level, offset, Direction.NORTH)) {
BlockState fire = BaseFireBlock.getState(level, offset);
level.setBlockAndUpdate(offset, fire);
level.levelEvent(1009, offset, 0);
}
}
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.netherDecayEffect.get() && type.isSimilar(NaturesAuraAPI.TYPE_NETHER);
}

View file

@ -9,16 +9,16 @@ import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.Tags;
import org.apache.commons.lang3.tuple.Pair;
@ -44,12 +44,12 @@ public class NetherGrassEffect implements IDrainSpotEffect {
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getPosition(), NAME))
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), NAME))
return ActiveType.INHIBITED;
return ActiveType.ACTIVE;
}
@ -60,29 +60,29 @@ public class NetherGrassEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (level.getGameTime() % 40 != 0)
return;
if (!this.calcValues(level, pos, spot))
return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + level.rand.nextGaussian() * this.dist);
int y = Mth.floor(pos.getY() + level.rand.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.rand.nextGaussian() * this.dist);
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + level.random.nextGaussian() * this.dist);
int y = Mth.floor(pos.getY() + level.random.nextGaussian() * this.dist);
int z = Mth.floor(pos.getZ() + level.random.nextGaussian() * this.dist);
for (int yOff = -5; yOff <= 5; yOff++) {
BlockPos goalPos = new BlockPos(x, y + yOff, z);
if (goalPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(goalPos)) {
if (goalPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(goalPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, goalPos, NAME))
continue;
BlockPos up = goalPos.up();
if (level.getBlockState(up).isSolidSide(level, up, Direction.DOWN))
BlockPos up = goalPos.above();
if (level.getBlockState(up).isFaceSturdy(level, up, Direction.DOWN))
continue;
BlockState state = level.getBlockState(goalPos);
Block block = state.getBlock();
if (Tags.Blocks.NETHERRACK.contains(block)) {
level.setBlockState(goalPos, ModBlocks.NETHER_GRASS.getDefaultState());
level.setBlockAndUpdate(goalPos, ModBlocks.NETHER_GRASS.defaultBlockState());
BlockPos closestSpot = IAuraChunk.getHighestSpot(level, goalPos, 25, pos);
IAuraChunk.getAuraChunk(level, closestSpot).drainAura(closestSpot, 500);
@ -97,7 +97,7 @@ public class NetherGrassEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.netherGrassEffect.get() && type.isSimilar(NaturesAuraAPI.TYPE_NETHER);
}

View file

@ -65,7 +65,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
return ActiveType.INACTIVE;
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getOnPos(), NAME))
if (!NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), NAME))
return ActiveType.INHIBITED;
return ActiveType.ACTIVE;
}

View file

@ -8,17 +8,18 @@ import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.block.*;
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.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.level.gen.Heightmap;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.levelgen.Heightmap;
import org.apache.commons.lang3.tuple.Pair;
public class PlantBoostEffect implements IDrainSpotEffect {
@ -43,12 +44,12 @@ public class PlantBoostEffect implements IDrainSpotEffect {
}
@Override
public ActiveType isActiveHere(Player player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public ActiveType isActiveHere(Player player, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(player.level, pos, spot))
return ActiveType.INACTIVE;
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
if (player.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
return ActiveType.INACTIVE;
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.getPosition(), NAME))
if (NaturesAuraAPI.instance().isEffectPowderActive(player.level, player.blockPosition(), NAME))
return ActiveType.INHIBITED;
return ActiveType.ACTIVE;
}
@ -59,24 +60,23 @@ public class PlantBoostEffect implements IDrainSpotEffect {
}
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (!this.calcValues(level, pos, spot))
return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + (2 * level.rand.nextFloat() - 1) * this.dist);
int z = Mth.floor(pos.getZ() + (2 * level.rand.nextFloat() - 1) * this.dist);
BlockPos plantPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z).down();
if (plantPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(plantPos)) {
for (int i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
int x = Mth.floor(pos.getX() + (2 * level.random.nextFloat() - 1) * this.dist);
int z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist);
BlockPos plantPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z).below();
if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, NAME))
continue;
BlockState state = level.getBlockState(plantPos);
Block block = state.getBlock();
if (block instanceof IGrowable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) {
IGrowable growable = (IGrowable) block;
if (growable.canGrow(level, plantPos, state, false)) {
if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) {
if (growable.isValidBonemealTarget(level, plantPos, state, false)) {
try {
growable.grow((ServerLevel) level, level.rand, plantPos, state);
growable.performBonemeal((ServerLevel) level, level.random, plantPos, state);
} catch (Exception e) {
// a lot of stuff throws here (double plants where generation only caused half of it to exist, bamboo at level height...)
// so just catch all, bleh
@ -93,7 +93,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return ModConfig.instance.plantBoostEffect.get() && type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD);
}

View file

@ -8,10 +8,10 @@ import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.chunk.ISpotDrainable;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import java.util.ArrayList;
import java.util.List;
@ -21,7 +21,7 @@ public class ReplenishingEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "replenishing");
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (spot < 0) {
List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getBlockEntitiesInArea(level, pos, 25, tile -> {
@ -32,8 +32,8 @@ public class ReplenishingEffect implements IDrainSpotEffect {
});
if (!tiles.isEmpty()) {
IAuraType type = IAuraType.forLevel(level);
for (int i = level.rand.nextInt(6); i >= 0; i--) {
ISpotDrainable tile = tiles.get(level.rand.nextInt(tiles.size()));
for (int i = level.random.nextInt(6); i >= 0; i--) {
ISpotDrainable tile = tiles.get(level.random.nextInt(tiles.size()));
if (!tile.isAcceptableType(type))
continue;
int drained = tile.drainAuraPassively(-spot, false);
@ -50,7 +50,7 @@ public class ReplenishingEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return true;
}

View file

@ -4,19 +4,19 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Mth;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
public class SpreadEffect implements IDrainSpotEffect {
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "spread");
@Override
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
public void update(Level level, LevelChunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (Math.abs(spot) < 500000 || Math.abs(IAuraChunk.getAuraInArea(level, pos, 25)) < 2000000)
return;
boolean drain = spot > 0;
@ -26,8 +26,8 @@ public class SpreadEffect implements IDrainSpotEffect {
BlockPos bestOffset = null;
int bestAmount = drain ? Integer.MAX_VALUE : Integer.MIN_VALUE;
for (Direction facing : Direction.values()) {
BlockPos offset = pos.offset(facing, 15);
if (level.isBlockLoaded(offset) && offset.getY() >= 0 && offset.getY() <= level.getHeight()) {
BlockPos offset = pos.relative(facing, 15);
if (level.isLoaded(offset) && offset.getY() >= 0 && offset.getY() <= level.getHeight()) {
int amount = IAuraChunk.getAuraInArea(level, offset, 14);
if (drain ? amount < bestAmount : amount > bestAmount) {
bestAmount = amount;
@ -55,7 +55,7 @@ public class SpreadEffect implements IDrainSpotEffect {
}
@Override
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
return true;
}

View file

@ -3,40 +3,40 @@ package de.ellpeck.naturesaura.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.TextComponent;
public final class CommandAura {
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermissionLevel(2))
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("naaura").requires(s -> s.hasPermission(2))
.then(Commands.literal("add").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
while (amount > 0) {
BlockPos spot = IAuraChunk.getLowestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).storeAura(spot, amount);
}
source.sendFeedback(new StringTextComponent("Added aura to area"), true);
source.sendSuccess(new TextComponent("Added aura to area"), true);
return 0;
})))
.then(Commands.literal("remove").then(Commands.argument("amount", IntegerArgumentType.integer(1)).executes(context -> {
int amount = IntegerArgumentType.getInteger(context, "amount");
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
while (amount > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(source.getLevel(), pos, 35, pos);
amount -= IAuraChunk.getAuraChunk(source.getLevel(), spot).drainAura(spot, amount);
}
source.sendFeedback(new StringTextComponent("Removed aura from area"), true);
source.sendSuccess(new TextComponent("Removed aura from area"), true);
return 0;
})))
.then(Commands.literal("reset").executes(context -> {
CommandSource source = context.getSource();
BlockPos pos = new BlockPos(source.getPos());
CommandSourceStack source = context.getSource();
BlockPos pos = new BlockPos(source.getPosition());
IAuraChunk.getSpotsInArea(source.getLevel(), pos, 35, (spot, amount) -> {
IAuraChunk chunk = IAuraChunk.getAuraChunk(source.getLevel(), spot);
if (amount > 0)
@ -44,7 +44,7 @@ public final class CommandAura {
else
chunk.storeAura(spot, -amount);
});
source.sendFeedback(new StringTextComponent("Reset aura in area"), true);
source.sendSuccess(new TextComponent("Reset aura in area"), true);
return 0;
})));
}

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.compat;
import com.google.common.collect.ImmutableMap;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.compat.enchantibility.EnchantibilityCompat;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import de.ellpeck.naturesaura.data.ItemTagProvider;
import net.minecraftforge.fml.ModList;
@ -17,8 +16,8 @@ public final class Compat {
private static final Map<String, Supplier<ICompat>> MODULE_TYPES = ImmutableMap.<String, Supplier<ICompat>>builder()
.put("patchouli", PatchouliCompat::new)
.put("curios", CuriosCompat::new)
.put("enchantability", EnchantibilityCompat::new)
/* .put("curios", CuriosCompat::new)
.put("enchantability", EnchantibilityCompat::new)*/
.build();
private static final Map<String, ICompat> MODULES = new HashMap<>();

View file

@ -1,3 +1,5 @@
// TODO Curios
/*
package de.ellpeck.naturesaura.compat;
import com.google.common.collect.ImmutableMap;
@ -96,3 +98,4 @@ public class CuriosCompat implements ICompat {
}
}
}
*/

View file

@ -1,3 +1,5 @@
// TODO Enchantability
/*
package de.ellpeck.naturesaura.compat.enchantibility;
import de.ellpeck.naturesaura.NaturesAura;
@ -34,3 +36,4 @@ public class EnchantibilityAuraMending extends AbstractEnchantEffect {
return RES;
}
}
*/

View file

@ -1,3 +1,5 @@
// TODO Enchantability
/*
package de.ellpeck.naturesaura.compat.enchantibility;
import de.ellpeck.naturesaura.compat.ICompat;
@ -30,3 +32,4 @@ public class EnchantibilityCompat implements ICompat {
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.jei;
import com.google.common.collect.ImmutableList;
@ -80,3 +81,4 @@ public class AltarCategory implements IRecipeCategory<AltarRecipe> {
group.set(3, recipe.getDimensionBottle());
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.jei;
import com.google.common.collect.ImmutableList;
@ -140,3 +141,4 @@ public class AnimalSpawnerCategory implements IRecipeCategory<AnimalSpawnerRecip
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.jei;
import de.ellpeck.naturesaura.NaturesAura;
@ -78,3 +79,4 @@ public class JEINaturesAuraPlugin implements IModPlugin {
registration.addRecipes(manager.getRecipes(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null), SPAWNER);
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.jei;
import com.google.common.collect.ImmutableList;
@ -68,3 +69,4 @@ public class OfferingCategory implements IRecipeCategory<OfferingRecipe> {
group.set(2, Arrays.asList(recipe.startItem.getMatchingStacks()));
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.jei;
import com.google.common.collect.ImmutableList;
@ -77,3 +78,4 @@ public class TreeRitualCategory implements IRecipeCategory<TreeRitualRecipe> {
}
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.recipes.AltarRecipe;
@ -46,3 +47,4 @@ public class ProcessorAltar implements IComponentProcessor {
return group.isEmpty() || group.equals(this.recipe.catalyst == Ingredient.EMPTY ? "altar" : "catalyst");
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe;
@ -46,3 +47,4 @@ public class ProcessorAnimalSpawner implements IComponentProcessor {
return !"seekrit".equals(group);
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.recipes.OfferingRecipe;
@ -32,3 +33,4 @@ public class ProcessorOffering implements IComponentProcessor {
}
}
}
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
@ -38,3 +39,4 @@ public class ProcessorTreeRitual implements IComponentProcessor {
}
}
}
*/

View file

@ -9,20 +9,28 @@ import de.ellpeck.naturesaura.blocks.Slab;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.advancements.criterion.StatePropertiesPredicate;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowerPotBlock;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IDataProvider;
import net.minecraft.data.loot.BlockLootTables;
import net.minecraft.item.Items;
import net.minecraft.loot.*;
import net.minecraft.loot.conditions.BlockStateProperty;
import net.minecraft.loot.conditions.RandomChance;
import net.minecraft.loot.functions.SetCount;
import net.minecraft.util.ResourceLocation;
import net.minecraft.data.DataProvider;
import net.minecraft.data.HashCache;
import net.minecraft.data.loot.BlockLoot;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTables;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.predicates.ConditionUserBuilder;
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
import javax.annotation.Nonnull;
import java.io.IOException;
@ -31,7 +39,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class BlockLootProvider implements IDataProvider {
public class BlockLootProvider implements DataProvider {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final DataGenerator generator;
private final Map<Block, Function<Block, LootTable.Builder>> lootFunctions = new HashMap<>();
@ -40,9 +49,8 @@ public class BlockLootProvider implements IDataProvider {
this.generator = generator;
for (IModItem item : ModRegistry.ALL_ITEMS) {
if (!(item instanceof Block))
if (!(item instanceof Block block))
continue;
Block block = (Block) item;
if (block instanceof Slab) {
this.lootFunctions.put(block, LootTableHooks::genSlab);
} else if (block instanceof BlockFlowerPot) {
@ -54,9 +62,9 @@ public class BlockLootProvider implements IDataProvider {
this.lootFunctions.put(ModBlocks.ANCIENT_LEAVES, LootTableHooks::genSilkOnly);
this.lootFunctions.put(ModBlocks.DECAYED_LEAVES, LootTableHooks::genSilkOnly);
this.lootFunctions.put(ModBlocks.GOLDEN_LEAVES, b -> LootTable.builder().addLootPool(LootPool.builder().rolls(ConstantRange.of(1)).addEntry(LootTableHooks.survivesExplosion(b, ItemLootEntry.builder(ModItems.GOLD_LEAF)).acceptCondition(BlockStateProperty.builder(b).fromProperties(StatePropertiesPredicate.Builder.newBuilder().withIntProp(BlockGoldenLeaves.STAGE, BlockGoldenLeaves.HIGHEST_STAGE)))).acceptCondition(RandomChance.builder(0.75F))));
this.lootFunctions.put(ModBlocks.NETHER_WART_MUSHROOM, b -> LootTableHooks.genSilkOr(b, ItemLootEntry.builder(Items.NETHER_WART).acceptFunction(SetCount.builder(RandomValueRange.of(1, 2)))));
this.lootFunctions.put(ModBlocks.NETHER_GRASS, b -> LootTableHooks.genSilkOr(b, ItemLootEntry.builder(Blocks.NETHERRACK)));
this.lootFunctions.put(ModBlocks.GOLDEN_LEAVES, b -> LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(LootTableHooks.survivesExplosion(b, LootItem.lootTableItem(ModItems.GOLD_LEAF)).when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(b).setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(BlockGoldenLeaves.STAGE, BlockGoldenLeaves.HIGHEST_STAGE)))).when(LootItemRandomChanceCondition.randomChance(0.75F))));
this.lootFunctions.put(ModBlocks.NETHER_WART_MUSHROOM, b -> LootTableHooks.genSilkOr(b, LootItem.lootTableItem(Items.NETHER_WART).apply(SetItemCountFunction.setCount(UniformGenerator.between(1, 2)))));
this.lootFunctions.put(ModBlocks.NETHER_GRASS, b -> LootTableHooks.genSilkOr(b, LootItem.lootTableItem(Blocks.NETHERRACK)));
}
private static Path getPath(Path root, ResourceLocation res) {
@ -64,13 +72,13 @@ public class BlockLootProvider implements IDataProvider {
}
@Override
public void act(DirectoryCache cache) throws IOException {
public void run(HashCache cache) throws IOException {
for (Map.Entry<Block, Function<Block, LootTable.Builder>> function : this.lootFunctions.entrySet()) {
Block block = function.getKey();
Function<Block, LootTable.Builder> func = function.getValue();
LootTable table = func.apply(block).setParameterSet(LootParameterSets.BLOCK).build();
LootTable table = func.apply(block).setParamSet(LootContextParamSets.BLOCK).build();
Path path = getPath(this.generator.getOutputFolder(), block.getRegistryName());
IDataProvider.save(GSON, cache, LootTableManager.toJson(table), path);
DataProvider.save(GSON, cache, LootTables.serialize(table), path);
}
}
@ -81,33 +89,34 @@ public class BlockLootProvider implements IDataProvider {
}
// What a mess
private static class LootTableHooks extends BlockLootTables {
private static class LootTableHooks extends BlockLoot {
public static LootTable.Builder genLeaves(Block block, Block drop) {
return droppingWithChancesAndSticks(block, drop, 0.05F, 0.0625F, 0.083333336F, 0.1F);
return createLeavesDrops(block, drop, 0.05F, 0.0625F, 0.083333336F, 0.1F);
}
public static LootTable.Builder genSlab(Block block) {
return droppingSlab(block);
return createSlabItemTable(block);
}
public static LootTable.Builder genRegular(Block block) {
return dropping(block);
return createSingleItemTable(block);
}
public static LootTable.Builder genSilkOnly(Block block) {
return onlyWithSilkTouch(block);
return createSilkTouchOnlyTable(block);
}
public static LootTable.Builder genSilkOr(Block block, LootEntry.Builder<?> builder) {
return droppingWithSilkTouch(block, builder);
public static LootTable.Builder genSilkOr(Block block, LootPoolEntryContainer.Builder<?> builder) {
return createSilkTouchOrShearsDispatchTable(block, builder);
}
public static LootTable.Builder genFlowerPot(Block block) {
return droppingAndFlowerPot(((FlowerPotBlock) block).getFlower());
return createPotFlowerItemTable(((FlowerPotBlock) block).getContent());
}
public static <T> T survivesExplosion(Block block, ILootConditionConsumer<T> then) {
return withSurvivesExplosion(block, then);
public static <T> T survivesExplosion(Block block, ConditionUserBuilder<T> then) {
return applyExplosionCondition(block, then);
}
}
}

View file

@ -2,12 +2,12 @@ package de.ellpeck.naturesaura.data;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.data.BlockTagsProvider;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.tags.BlockTagsProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.Tags;
public class BlockTagProvider extends BlockTagsProvider {
@ -19,15 +19,15 @@ public class BlockTagProvider extends BlockTagsProvider {
}
@Override
protected void registerTags() {
this.getOrCreateBuilder(BlockTags.LOGS).add(ModBlocks.ANCIENT_LOG, ModBlocks.ANCIENT_BARK);
this.getOrCreateBuilder(BlockTags.PLANKS).add(ModBlocks.ANCIENT_PLANKS);
this.getOrCreateBuilder(BlockTags.STAIRS).add(ModBlocks.ANCIENT_STAIRS, ModBlocks.INFUSED_BRICK_STAIRS, ModBlocks.INFUSED_STAIRS);
this.getOrCreateBuilder(BlockTags.LEAVES).add(ModBlocks.GOLDEN_LEAVES, ModBlocks.ANCIENT_LEAVES, ModBlocks.DECAYED_LEAVES);
this.getOrCreateBuilder(BlockTags.RAILS).add(ModBlocks.DIMENSION_RAIL_END, ModBlocks.DIMENSION_RAIL_NETHER, ModBlocks.DIMENSION_RAIL_OVERWORLD);
this.getOrCreateBuilder(BlockTags.SLABS).add(ModBlocks.ANCIENT_SLAB, ModBlocks.INFUSED_SLAB, ModBlocks.INFUSED_BRICK_SLAB);
this.getOrCreateBuilder(Tags.Blocks.DIRT).add(ModBlocks.NETHER_GRASS);
this.getOrCreateBuilder(BlockTags.SMALL_FLOWERS).add(ModBlocks.END_FLOWER, ModBlocks.AURA_BLOOM);
this.getOrCreateBuilder(NETHER_ALTAR_WOOD).add(Blocks.CRIMSON_PLANKS, Blocks.WARPED_PLANKS);
protected void addTags() {
this.tag(BlockTags.LOGS).add(ModBlocks.ANCIENT_LOG, ModBlocks.ANCIENT_BARK);
this.tag(BlockTags.PLANKS).add(ModBlocks.ANCIENT_PLANKS);
this.tag(BlockTags.STAIRS).add(ModBlocks.ANCIENT_STAIRS, ModBlocks.INFUSED_BRICK_STAIRS, ModBlocks.INFUSED_STAIRS);
this.tag(BlockTags.LEAVES).add(ModBlocks.GOLDEN_LEAVES, ModBlocks.ANCIENT_LEAVES, ModBlocks.DECAYED_LEAVES);
this.tag(BlockTags.RAILS).add(ModBlocks.DIMENSION_RAIL_END, ModBlocks.DIMENSION_RAIL_NETHER, ModBlocks.DIMENSION_RAIL_OVERWORLD);
this.tag(BlockTags.SLABS).add(ModBlocks.ANCIENT_SLAB, ModBlocks.INFUSED_SLAB, ModBlocks.INFUSED_BRICK_SLAB);
this.tag(Tags.Blocks.DIRT).add(ModBlocks.NETHER_GRASS);
this.tag(BlockTags.SMALL_FLOWERS).add(ModBlocks.END_FLOWER, ModBlocks.AURA_BLOOM);
this.tag(NETHER_ALTAR_WOOD).add(Blocks.CRIMSON_PLANKS, Blocks.WARPED_PLANKS);
}
}

View file

@ -4,21 +4,21 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.ItemTagsProvider;
import net.minecraft.item.Item;
import net.minecraft.data.tags.BlockTagsProvider;
import net.minecraft.data.tags.ItemTagsProvider;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ITag;
import net.minecraft.tags.ItemTags;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.data.ExistingFileHelper;
public class ItemTagProvider extends ItemTagsProvider {
public ItemTagProvider(DataGenerator generatorIn, BlockTagProvider blockTagProvider, ExistingFileHelper helper) {
public ItemTagProvider(DataGenerator generatorIn, BlockTagsProvider blockTagProvider, ExistingFileHelper helper) {
super(generatorIn, blockTagProvider, NaturesAura.MOD_ID, helper);
}
@Override
protected void registerTags() {
protected void addTags() {
this.copy(BlockTags.LOGS, ItemTags.LOGS);
this.copy(BlockTags.PLANKS, ItemTags.PLANKS);
this.copy(BlockTags.STAIRS, ItemTags.STAIRS);
@ -26,13 +26,9 @@ public class ItemTagProvider extends ItemTagsProvider {
this.copy(BlockTags.RAILS, ItemTags.RAILS);
this.copy(BlockTags.SLABS, ItemTags.SLABS);
this.getOrCreateBuilder(Tags.Items.RODS_WOODEN).add(ModItems.ANCIENT_STICK);
this.tag(Tags.Items.RODS_WOODEN).add(ModItems.ANCIENT_STICK);
Compat.addItemTags(this);
}
@Override
public Builder<Item> getOrCreateBuilder(ITag.INamedTag<Item> tag) {
return super.getOrCreateBuilder(tag);
}
}

View file

@ -4,7 +4,7 @@ import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public final class ModData {

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.enchant;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantment;
@SuppressWarnings("FieldNamingConvention")
public final class ModEnchantments {

View file

@ -49,7 +49,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
super.moveMinecartOnRail(railPos);
if (!this.isActive)
return;
BlockPos pos = this.getOnPos();
BlockPos pos = this.blockPosition();
if (!this.spotOffsets.isEmpty() && this.level.getGameTime() % 10 == 0)
PacketHandler.sendToAllAround(this.level, pos, 32, new PacketParticles(
@ -85,7 +85,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
if (this.isActive != receivingPower) {
this.isActive = receivingPower;
BlockPos pos = this.getOnPos();
BlockPos pos = this.blockPosition();
if (!this.isActive) {
this.moveAura(this.level, this.lastPosition, this.level, pos);
this.spotOffsets.clear();
@ -138,7 +138,7 @@ public class EntityMoverMinecart extends AbstractMinecart {
public Entity changeDimension(ServerLevel destination, ITeleporter teleporter) {
Entity entity = super.changeDimension(destination, teleporter);
if (entity instanceof EntityMoverMinecart) {
BlockPos pos = entity.getOnPos();
BlockPos pos = entity.blockPosition();
this.moveAura(this.level, this.lastPosition, entity.level, pos);
((EntityMoverMinecart) entity).lastPosition = pos;
}

View file

@ -125,7 +125,7 @@ public class EntityStructureFinder extends EyeOfEnder {
if (this.shatterOrDrop) {
this.level.addFreshEntity(new ItemEntity(this.level, this.getX(), this.getY(), this.getZ(), this.getItem()));
} else {
PacketHandler.sendToAllAround(this.level, this.getOnPos(), 32, new PacketParticles((float) this.getX(), (float) this.getY(), (float) this.getZ(), PacketParticles.Type.STRUCTURE_FINDER, this.getId()));
PacketHandler.sendToAllAround(this.level, this.blockPosition(), 32, new PacketParticles((float) this.getX(), (float) this.getY(), (float) this.getZ(), PacketParticles.Type.STRUCTURE_FINDER, this.getId()));
}
}
} else {

View file

@ -1,55 +1,35 @@
package de.ellpeck.naturesaura.events;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.*;
import de.ellpeck.naturesaura.items.ItemAuraCache;
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.packet.PacketAuraChunk;
import net.minecraft.block.*;
import net.minecraft.client.MainWindow;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.level.Level;
import net.minecraft.level.biome.BiomeColors;
import net.minecraft.level.gen.Heightmap;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderLevelLastEvent;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.commons.lang3.mutable.MutableInt;
import org.lwjgl.opengl.GL11;
import java.text.NumberFormat;
import java.util.ArrayList;
@ -73,19 +53,19 @@ public class ClientEvents {
@SubscribeEvent
public void onDebugRender(RenderGameOverlayEvent.Text event) {
Minecraft mc = Minecraft.getInstance();
if (mc.gameSettings.showDebugInfo && ModConfig.instance.debugText.get()) {
String prefix = TextFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + TextFormatting.RESET + " ";
if (mc.options.renderDebug && ModConfig.instance.debugText.get()) {
String prefix = ChatFormatting.GREEN + "[" + NaturesAura.MOD_NAME + "]" + ChatFormatting.RESET + " ";
List<String> left = event.getLeft();
if (mc.player.isCreative()) {
left.add("");
MutableInt amount = new MutableInt(IAuraChunk.DEFAULT_AURA);
MutableInt spots = new MutableInt();
MutableInt chunks = new MutableInt();
IAuraChunk.getSpotsInArea(mc.level, mc.player.getPosition(), 35, (blockPos, drainSpot) -> {
IAuraChunk.getSpotsInArea(mc.level, mc.player.blockPosition(), 35, (blockPos, drainSpot) -> {
spots.increment();
amount.add(drainSpot);
});
Helper.getAuraChunksWithSpotsInArea(mc.level, mc.player.getPosition(), 35, c -> chunks.increment());
Helper.getAuraChunksWithSpotsInArea(mc.level, mc.player.blockPosition(), 35, c -> chunks.increment());
NumberFormat format = NumberFormat.getInstance();
left.add(prefix + "A: " + format.format(amount.intValue()) + " (S: " + spots.intValue() + ", C: " + chunks.intValue() + ")");
left.add(prefix + "AT: " + IAuraType.forLevel(mc.level).getName());
@ -107,30 +87,30 @@ public class ClientEvents {
} else {
PENDING_AURA_CHUNKS.removeIf(next -> next.tryHandle(mc.level));
if (!mc.isGamePaused()) {
if (!mc.isPaused()) {
if (mc.level.getGameTime() % 20 == 0) {
int amount = Mth.floor(190 * ModConfig.instance.excessParticleAmount.get());
for (int i = 0; i < amount; i++) {
int x = Mth.floor(mc.player.getPosX()) + mc.level.rand.nextInt(64) - 32;
int z = Mth.floor(mc.player.getPosZ()) + mc.level.rand.nextInt(64) - 32;
BlockPos pos = new BlockPos(x, mc.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z) - 1, z);
int x = Mth.floor(mc.player.getX()) + mc.level.random.nextInt(64) - 32;
int z = Mth.floor(mc.player.getZ()) + mc.level.random.nextInt(64) - 32;
BlockPos pos = new BlockPos(x, mc.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) - 1, z);
BlockState state = mc.level.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof IGrowable || block instanceof IPlantable || block instanceof LeavesBlock || block instanceof MyceliumBlock) {
if (block instanceof BonemealableBlock || block instanceof IPlantable || block instanceof LeavesBlock || block instanceof MyceliumBlock) {
int excess = IAuraChunk.triangulateAuraInArea(mc.level, pos, 45) - IAuraChunk.DEFAULT_AURA;
if (excess > 0) {
int chance = Math.max(10, 50 - excess / 25000);
if (mc.level.rand.nextInt(chance) <= 0)
if (mc.level.random.nextInt(chance) <= 0)
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + mc.level.rand.nextFloat(),
pos.getX() + mc.level.random.nextFloat(),
pos.getY() + 0.5F,
pos.getZ() + mc.level.rand.nextFloat(),
mc.level.rand.nextGaussian() * 0.01F,
mc.level.rand.nextFloat() * 0.025F,
mc.level.rand.nextGaussian() * 0.01F,
block instanceof MyceliumBlock ? 0x875ca1 : BiomeColors.getGrassColor(mc.level, pos),
Math.min(2F, 1F + mc.level.rand.nextFloat() * (excess / 30000F)),
Math.min(300, 100 + mc.level.rand.nextInt(excess / 3000 + 1)),
pos.getZ() + mc.level.random.nextFloat(),
mc.level.random.nextGaussian() * 0.01F,
mc.level.random.nextFloat() * 0.025F,
mc.level.random.nextGaussian() * 0.01F,
block instanceof MyceliumBlock ? 0x875ca1 : BiomeColors.getAverageGrassColor(mc.level, pos),
Math.min(2F, 1F + mc.level.random.nextFloat() * (excess / 30000F)),
Math.min(300, 100 + mc.level.random.nextInt(excess / 3000 + 1)),
0F, false, true);
}
}
@ -141,12 +121,12 @@ public class ClientEvents {
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
inst.setParticleSpawnRange(512);
inst.setParticleDepth(false);
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_RAILS.get(mc.level.func_234923_W_().func_240901_a_())) {
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_RAILS.get(mc.level.dimension().location())) {
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + mc.level.rand.nextFloat(),
pos.getY() + mc.level.rand.nextFloat(),
pos.getZ() + mc.level.rand.nextFloat(),
0F, 0F, 0F, 0xe0faff, mc.level.rand.nextFloat() * 5 + 1, 100, 0F, false, true);
pos.getX() + mc.level.random.nextFloat(),
pos.getY() + mc.level.random.nextFloat(),
pos.getZ() + mc.level.random.nextFloat(),
0F, 0F, 0F, 0xe0faff, mc.level.random.nextFloat() * 5 + 1, 100, 0F, false, true);
}
inst.setParticleDepth(true);
inst.setParticleSpawnRange(32);
@ -158,7 +138,7 @@ public class ClientEvents {
if (!heldOcular.isEmpty() && mc.level.getGameTime() % 20 == 0) {
SHOWING_EFFECTS.clear();
Helper.getAuraChunksWithSpotsInArea(mc.level, mc.player.getPosition(), 100,
Helper.getAuraChunksWithSpotsInArea(mc.level, mc.player.blockPosition(), 100,
chunk -> chunk.getActiveEffectIcons(mc.player, SHOWING_EFFECTS));
}
}
@ -168,7 +148,8 @@ public class ClientEvents {
@SubscribeEvent
public void onLevelRender(RenderLevelLastEvent event) {
Minecraft mc = Minecraft.getInstance();
// TODO GL-based in-world rendering
/* Minecraft mc = Minecraft.getInstance();
RenderSystem.pushMatrix();
RenderSystem.multMatrix(event.getMatrixStack().getLast().getMatrix());
@ -239,10 +220,10 @@ public class ClientEvents {
GL11.glPopMatrix();
}
GL11.glPopMatrix();
GL11.glPopMatrix();*/
}
private void renderVisualize(IVisualizable visualize, Level
/* private void renderVisualize(IVisualizable visualize, Level
level, BlockPos pos) {
AABB box = visualize.getVisualizationBounds(level, pos);
if (box == null)
@ -251,22 +232,23 @@ public class ClientEvents {
int color = visualize.getVisualizationColor(level, pos);
RenderSystem.color4f((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F, 0.5F);
Helper.renderWeirdBox(box.minX, box.minY, box.minZ, box.maxX - box.minX, box.maxY - box.minY, box.maxZ - box.minZ);
}
}*/
@SubscribeEvent
public void onOverlayRender(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getInstance();
MatrixStack stack = event.getMatrixStack();
// TODO raw rendering bleh, should be easy enough to convert to PoseStack stuff
/*Minecraft mc = Minecraft.getInstance();
PoseStack stack = event.getMatrixStack();
if (event.getType() == ElementType.ALL) {
MainWindow res = event.getWindow();
var res = event.getWindow();
if (mc.player != null) {
if (!heldCache.isEmpty()) {
IAuraContainer container = heldCache.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
int width = Mth.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
int conf = ModConfig.instance.cacheBarLocation.get();
int x = res.getScaledWidth() / 2 + (conf == 0 ? -173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29) : 93);
int y = res.getScaledHeight() - 8;
int x = res.getGuiScaledWidth() / 2 + (conf == 0 ? -173 - (mc.player.getOffhandItem().isEmpty() ? 0 : 29) : 93);
int y = res.getScreenHeight() - 8;
RenderSystem.pushMatrix();
@ -431,7 +413,7 @@ public class ClientEvents {
RenderSystem.popMatrix();
}
}
}
}*/
}
private String createTimeString(int totalTicks) {
@ -442,7 +424,7 @@ public class ClientEvents {
return String.format("%02d:%02d:%02d.%02d", hours, minutes, seconds, ticks);
}
private void drawContainerInfo(MatrixStack stack, int stored, int max, int color, Minecraft mc, MainWindow res, int yOffset, String name, String textBelow) {
/* private void drawContainerInfo(PoseStack stack, int stored, int max, int color, Minecraft mc, MainWindow res, int yOffset, String name, String textBelow) {
RenderSystem.color3f((color >> 16 & 255) / 255F, (color >> 8 & 255) / 255F, (color & 255) / 255F);
int x = res.getScaledWidth() / 2 - 40;
@ -459,5 +441,5 @@ public class ClientEvents {
if (textBelow != null)
mc.fontRenderer.drawStringWithShadow(stack, textBelow, x + 40 - mc.fontRenderer.getStringWidth(textBelow) / 2F, y + 7, color);
}
}*/
}

View file

@ -14,60 +14,58 @@ import de.ellpeck.naturesaura.commands.CommandAura;
import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.level.chunk.IChunk;
import net.minecraft.level.gen.GenerationStage.Decoration;
import net.minecraft.level.server.ChunkHolder;
import net.minecraft.level.server.ChunkManager;
import net.minecraft.level.server.ServerChunkProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.level.BiomeLoadingEvent;
import net.minecraftforge.event.level.ChunkEvent;
import net.minecraftforge.event.level.ChunkWatchEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;
import static net.minecraft.world.level.levelgen.GenerationStep.Decoration;
public class CommonEvents {
private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkManager.class, "func_223491_f");
private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "getChunks");
private static final ListMultimap<UUID, ChunkPos> PENDING_AURA_CHUNKS = ArrayListMultimap.create();
@SubscribeEvent
public void onBiomeLoad(BiomeLoadingEvent event) {
if (ModConfig.instance.auraBlooms.get()) {
event.getGeneration().func_242513_a(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_BLOOM);
// TODO features might have to be registered *AGAIN* now because .placed() is another thing again oh my God
event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_BLOOM.placed());
switch (event.getCategory()) {
case DESERT:
event.getGeneration().func_242513_a(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_CACTUS);
break;
case NETHER:
event.getGeneration().func_242513_a(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.CRIMSON_AURA_MUSHROOM);
event.getGeneration().func_242513_a(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.WARPED_AURA_MUSHROOM);
break;
case MUSHROOM:
event.getGeneration().func_242513_a(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_MUSHROOM);
break;
case DESERT -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_CACTUS.placed());
case NETHER -> {
event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.CRIMSON_AURA_MUSHROOM.placed());
event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.WARPED_AURA_MUSHROOM.placed());
}
case MUSHROOM -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_MUSHROOM.placed());
}
}
}
@SubscribeEvent
public void onChunkCapsAttach(AttachCapabilitiesEvent<Chunk> event) {
Chunk chunk = event.getObject();
public void onChunkCapsAttach(AttachCapabilitiesEvent<LevelChunk> event) {
LevelChunk chunk = event.getObject();
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "aura"), new AuraChunkProvider(chunk));
}
@ -78,13 +76,12 @@ public class CommonEvents {
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) {
IChunk iChunk = event.getChunk();
if (iChunk instanceof Chunk) {
Chunk chunk = (Chunk) iChunk;
ChunkAccess iChunk = event.getChunk();
if (iChunk instanceof LevelChunk chunk) {
IAuraChunk auraChunk = chunk.getCapability(NaturesAuraAPI.capAuraChunk).orElse(null);
if (auraChunk instanceof AuraChunk) {
LevelData data = (LevelData) ILevelData.getLevelData(chunk.getLevel());
data.auraChunksWithSpots.remove(chunk.getPos().asLong());
data.auraChunksWithSpots.remove(chunk.getPos().toLong());
}
}
}
@ -105,15 +102,16 @@ public class CommonEvents {
}
@SubscribeEvent
public void onLevelTick(TickEvent.LevelTickEvent event) {
if (!event.level.isClientSide && event.phase == TickEvent.Phase.END) {
if (event.level.getGameTime() % 20 == 0) {
event.level.getProfiler().startSection(NaturesAura.MOD_ID + ":onLevelTick");
@SuppressWarnings("unchecked")
public void onLevelTick(TickEvent.WorldTickEvent event) {
if (!event.world.isClientSide && event.phase == TickEvent.Phase.END) {
if (event.world.getGameTime() % 20 == 0) {
event.world.getProfiler().push(NaturesAura.MOD_ID + ":onLevelTick");
try {
ChunkManager manager = ((ServerChunkProvider) event.level.getChunkProvider()).chunkManager;
ChunkMap manager = ((ServerChunkCache) event.world.getChunkSource()).chunkMap;
Iterable<ChunkHolder> chunks = (Iterable<ChunkHolder>) GET_LOADED_CHUNKS_METHOD.invoke(manager);
for (ChunkHolder holder : chunks) {
Chunk chunk = holder.getChunkIfComplete();
LevelChunk chunk = holder.getTickingChunk();
if (chunk == null)
continue;
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
@ -123,7 +121,7 @@ public class CommonEvents {
} catch (IllegalAccessException | InvocationTargetException e) {
NaturesAura.LOGGER.fatal(e);
}
event.level.getProfiler().endSection();
event.world.getProfiler().pop();
}
}
}
@ -132,14 +130,14 @@ public class CommonEvents {
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (!event.player.level.isClientSide && event.phase == TickEvent.Phase.END) {
if (event.player.level.getGameTime() % 10 == 0) {
List<ChunkPos> pending = PENDING_AURA_CHUNKS.get(event.player.getUniqueID());
List<ChunkPos> pending = PENDING_AURA_CHUNKS.get(event.player.getUUID());
pending.removeIf(p -> this.handleChunkWatchDeferred(event.player, p));
}
if (event.player.level.getGameTime() % 200 != 0)
return;
int aura = IAuraChunk.triangulateAuraInArea(event.player.level, event.player.getPosition(), 25);
int aura = IAuraChunk.triangulateAuraInArea(event.player.level, event.player.blockPosition(), 25);
if (aura <= 0)
Helper.addAdvancement(event.player, new ResourceLocation(NaturesAura.MOD_ID, "negative_imbalance"), "triggered_in_code");
else if (aura >= 1500000)
@ -149,11 +147,11 @@ public class CommonEvents {
@SubscribeEvent
public void onChunkWatch(ChunkWatchEvent.Watch event) {
PENDING_AURA_CHUNKS.put(event.getPlayer().getUniqueID(), event.getPos());
PENDING_AURA_CHUNKS.put(event.getPlayer().getUUID(), event.getPos());
}
private boolean handleChunkWatchDeferred(Player player, ChunkPos pos) {
Chunk chunk = Helper.getLoadedChunk(player.level, pos.x, pos.z);
LevelChunk chunk = Helper.getLoadedChunk(player.level, pos.x, pos.z);
if (chunk == null)
return false;
AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null);
@ -164,7 +162,7 @@ public class CommonEvents {
}
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
CommandAura.register(event.getServer().getCommandManager().getDispatcher());
public void onServerStarting(ServerStartingEvent event) {
CommandAura.register(event.getServer().getCommands().getDispatcher());
}
}

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.items;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
@ -9,20 +10,19 @@ import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.render.ITrinketItem;
import de.ellpeck.naturesaura.enchant.ModEnchantments;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.Player;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.level.Level;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
@ -37,29 +37,28 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
private final int capacity;
public ItemAuraCache(String name, int capacity) {
super(name, new Properties().maxStackSize(1));
super(name, new Properties().stacksTo(1));
this.capacity = capacity;
}
@Override
public void inventoryTick(ItemStack stackIn, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (!levelIn.isClientSide && entityIn instanceof Player) {
Player player = (Player) entityIn;
if (player.isSneaking() && stackIn.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) {
if (!levelIn.isClientSide && entityIn instanceof Player player) {
if (player.isCrouching() && stackIn.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) {
IAuraContainer container = stackIn.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null);
if (container.getStoredAura() <= 0) {
return;
}
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stack = player.inventory.getStackInSlot(i);
for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack stack = player.getInventory().getItem(i);
IAuraRecharge recharge = stack.getCapability(NaturesAuraAPI.capAuraRecharge).orElse(null);
if (recharge != null) {
if (recharge.rechargeFromContainer(container, itemSlot, i, player.inventory.currentItem == i))
if (recharge.rechargeFromContainer(container, itemSlot, i, player.getInventory().selected == i))
break;
} else if (EnchantmentHelper.getEnchantmentLevel(ModEnchantments.AURA_MENDING, stack) > 0) {
int mainSize = player.inventory.mainInventory.size();
boolean isArmor = i >= mainSize && i < mainSize + player.inventory.armorInventory.size();
if ((isArmor || player.inventory.currentItem == i) && Helper.rechargeAuraItem(stack, container, 1000))
} else if (EnchantmentHelper.getItemEnchantmentLevel(ModEnchantments.AURA_MENDING, stack) > 0) {
int mainSize = player.getInventory().items.size();
boolean isArmor = i >= mainSize && i < mainSize + player.getInventory().armor.size();
if ((isArmor || player.getInventory().selected == i) && Helper.rechargeAuraItem(stack, container, 1000))
break;
}
}
@ -68,8 +67,8 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
}
@Override
public void fillItemGroup(ItemGroup tab, NonNullList<ItemStack> items) {
if (this.isInGroup(tab)) {
public void fillItemCategory(CreativeModeTab tab, NonNullList<ItemStack> items) {
if (this.allowdedIn(tab)) {
items.add(new ItemStack(this));
ItemStack stack = new ItemStack(this);
@ -81,15 +80,15 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
public boolean isBarVisible(ItemStack stack) {
return true;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
public int getBarColor(ItemStack stack) {
if (stack.getCapability(NaturesAuraAPI.capAuraContainer).isPresent()) {
IAuraContainer container = stack.getCapability(NaturesAuraAPI.capAuraContainer).orElse(null);
return 1 - container.getStoredAura() / (double) container.getMaxAura();
return (int) (1 - container.getStoredAura() / (double) container.getMaxAura());
}
return 0;
}
@ -114,14 +113,14 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem {
@Override
@OnlyIn(Dist.CLIENT)
public void render(ItemStack stack, Player player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding) {
public void render(ItemStack stack, Player player, RenderType type, PoseStack matrices, MultiBufferSource buffer, int packedLight, boolean isHolding) {
if (type == RenderType.BODY && !isHolding) {
boolean chest = !player.inventory.armorInventory.get(EquipmentSlotType.CHEST.getIndex()).isEmpty();
boolean legs = !player.inventory.armorInventory.get(EquipmentSlotType.LEGS.getIndex()).isEmpty();
boolean chest = !player.getInventory().armor.get(EquipmentSlot.CHEST.getIndex()).isEmpty();
boolean legs = !player.getInventory().armor.get(EquipmentSlot.LEGS.getIndex()).isEmpty();
matrices.translate(-0.15F, 0.65F, chest ? -0.195F : legs ? -0.165F : -0.1475F);
matrices.scale(0.5F, 0.5F, 0.5F);
matrices.rotate(Vector3f.XP.rotationDegrees(180F));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer);
matrices.mulPose(Vector3f.XP.rotationDegrees(180F));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer, 0);
}
}
}

View file

@ -1,34 +1,35 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ItemBirthSpirit extends ItemGlowing {
public ItemBirthSpirit() {
super("birth_spirit");
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
private static class EventHandler {
@SubscribeEvent
public void onBabyBorn(BabyEntitySpawnEvent event) {
LivingEntity parent = event.getParentA();
if (!parent.level.isClientSide && event.getCausedByPlayer() != null) {
BlockPos pos = parent.getPosition();
BlockPos pos = parent.blockPosition();
int aura = IAuraChunk.getAuraInArea(parent.level, pos, 30);
if (aura < 1200000)
return;
int amount = parent.level.rand.nextInt(3) + 1;
ItemEntity item = new ItemEntity(parent.level, parent.getPosX(), parent.getPosY(), parent.getPosZ(),
new ItemStack(ModItems.BIRTH_SPIRIT, amount));
parent.level.addEntity(item);
int amount = parent.level.random.nextInt(3) + 1;
ItemEntity item = new ItemEntity(parent.level, parent.getX(), parent.getY(), parent.getZ(), new ItemStack(ModItems.BIRTH_SPIRIT, amount));
parent.level.addFreshEntity(item);
BlockPos spot = IAuraChunk.getHighestSpot(parent.level, pos, 30, pos);
IAuraChunk.getAuraChunk(parent.level, spot).drainAura(spot, 800 * amount);

View file

@ -1,10 +1,14 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ElytraItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.*;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ElytraItem;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
@ -16,16 +20,18 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.List;
public class ItemBreakPrevention extends ItemImpl {
public ItemBreakPrevention() {
super("break_prevention");
MinecraftForge.EVENT_BUS.register(new Events());
}
public static class Events {
@SubscribeEvent
public void onAnvilUpdate(AnvilUpdateEvent event) {
ItemStack stack = event.getLeft();
if (stack.getToolTypes().isEmpty() || !stack.isDamageable())
if (!stack.isDamageableItem())
return;
ItemStack second = event.getRight();
if (second.getItem() != ModItems.BREAK_PREVENTION)
@ -42,10 +48,10 @@ public class ItemBreakPrevention extends ItemImpl {
Player player = event.getPlayer();
if (player == null)
return;
ItemStack stack = player.getHeldItemMainhand();
ItemStack stack = player.getMainHandItem();
if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention"))
return;
if (ElytraItem.isUsable(stack))
if (ElytraItem.isFlyEnabled(stack))
return;
event.setNewSpeed(0);
}
@ -56,15 +62,15 @@ public class ItemBreakPrevention extends ItemImpl {
ItemStack stack = event.getItemStack();
if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention"))
return;
List<ITextComponent> tooltip = event.getToolTip();
tooltip.add(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".break_prevention").setStyle(Style.EMPTY.setFormatting(TextFormatting.GRAY)));
if (ElytraItem.isUsable(stack))
List<Component> tooltip = event.getToolTip();
tooltip.add(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".break_prevention").setStyle(Style.EMPTY.applyFormat(ChatFormatting.GRAY)));
if (ElytraItem.isFlyEnabled(stack))
return;
if (tooltip.size() < 1)
return;
ITextComponent head = tooltip.get(0);
if (head instanceof TextComponent)
((TextComponent) head).append(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".broken").setStyle(Style.EMPTY.setFormatting(TextFormatting.GRAY)));
Component head = tooltip.get(0);
if (head instanceof MutableComponent)
((MutableComponent) head).append(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".broken").setStyle(Style.EMPTY.applyFormat(ChatFormatting.GRAY)));
}
}
}

View file

@ -1,53 +1,54 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntitySpawnPlacementRegistry;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.LightType;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.state.BlockState;
public class ItemCaveFinder extends ItemImpl {
public ItemCaveFinder() {
super("cave_finder", new Properties().maxStackSize(1));
super("cave_finder", new Properties().stacksTo(1));
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 20000, levelIn.isClientSide))
return new ActionResult<>(InteractionResult.FAIL, stack);
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
if (levelIn.isClientSide) {
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition();
BlockPos pos = playerIn.blockPosition();
int range = 30;
for (int x = -range; x <= range; x++)
for (int y = -range; y <= range; y++)
for (int z = -range; z <= range; z++) {
BlockPos offset = pos.add(x, y, z);
BlockPos offset = pos.offset(x, y, z);
BlockState state = levelIn.getBlockState(offset);
try {
if (!state.getBlock().canCreatureSpawn(state, levelIn, offset, EntitySpawnPlacementRegistry.PlacementType.ON_GROUND, null))
if (!state.getBlock().isValidSpawn(state, levelIn, offset, SpawnPlacements.Type.ON_GROUND, null))
continue;
} catch (Exception e) {
continue;
}
BlockPos offUp = offset.up();
BlockPos offUp = offset.above();
BlockState stateUp = levelIn.getBlockState(offUp);
if (stateUp.isNormalCube(levelIn, offUp) || stateUp.getMaterial().isLiquid())
if (stateUp.isCollisionShapeFullBlock(levelIn, offUp) || stateUp.getMaterial().isLiquid())
continue;
int sky = levelIn.getLightFor(LightType.SKY, offUp);
int block = levelIn.getLightFor(LightType.BLOCK, offUp);
int sky = levelIn.getBrightness(LightLayer.SKY, offUp);
int block = levelIn.getBrightness(LightLayer.BLOCK, offUp);
if (sky > 7 || block > 7)
continue;
@ -59,9 +60,9 @@ public class ItemCaveFinder extends ItemImpl {
inst.setParticleSpawnRange(32);
inst.setParticleCulling(true);
playerIn.swingArm(handIn);
playerIn.swing(handIn);
}
playerIn.getCooldownTracker().setCooldown(this, 20 * 30);
return new ActionResult<>(InteractionResult.SUCCESS, stack);
playerIn.getCooldowns().addCooldown(this, 20 * 30);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -5,14 +5,20 @@ import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemUseContext;
import net.minecraft.level.Level;
import net.minecraft.util.math.BlockPos;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -21,7 +27,7 @@ import java.util.List;
public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, ICustomItemModel {
public ItemColorChanger() {
super("color_changer", new Properties().maxStackSize(1));
super("color_changer", new Properties().stacksTo(1));
}
private static boolean changeOrCopyColor(Player player, ItemStack stack, Level level, BlockPos pos, DyeColor firstColor) {
@ -32,10 +38,10 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
DyeColor color = DyeColor.byId(blocks.indexOf(block));
if (firstColor == null || color == firstColor) {
DyeColor stored = getStoredColor(stack);
if (player.isSneaking()) {
if (player.isCrouching()) {
if (stored != color) {
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ITEM_BUCKET_FILL, SoundCategory.PLAYERS, 0.65F, 1F);
SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F);
if (!level.isClientSide)
storeColor(stack, color);
return true;
@ -45,14 +51,14 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
if (NaturesAuraAPI.instance().extractAuraFromPlayer(player, 1000, level.isClientSide)) {
if (firstColor == null) {
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.PLAYERS, 0.65F, 1F);
SoundEvents.BUCKET_EMPTY, SoundSource.PLAYERS, 0.65F, 1F);
}
if (!level.isClientSide) {
level.setBlockState(pos, blocks.get(stored.getId()).getDefaultState());
level.setBlockAndUpdate(pos, blocks.get(stored.getId()).defaultBlockState());
if (isFillMode(stack)) {
for (Direction off : Direction.values()) {
changeOrCopyColor(player, stack, level, pos.offset(off), color);
changeOrCopyColor(player, stack, level, pos.relative(off), color);
}
}
}
@ -90,9 +96,9 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
}
@Override
public InteractionResult onItemUse(ItemUseContext context) {
ItemStack stack = context.getPlayer().getHeldItem(context.getHand());
if (changeOrCopyColor(context.getPlayer(), stack, context.getLevel(), context.getPos(), null)) {
public InteractionResult useOn(UseOnContext context) {
ItemStack stack = context.getPlayer().getItemInHand(context.getHand());
if (changeOrCopyColor(context.getPlayer(), stack, context.getLevel(), context.getClickedPos(), null)) {
return InteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
@ -100,27 +106,27 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
if (playerIn.isSneaking() && getStoredColor(stack) != null) {
levelIn.playSound(playerIn, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_BUCKET_FILL_LAVA, SoundCategory.PLAYERS, 0.65F, 1F);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (playerIn.isCrouching() && getStoredColor(stack) != null) {
levelIn.playSound(playerIn, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.BUCKET_FILL_LAVA, SoundSource.PLAYERS, 0.65F, 1F);
if (!levelIn.isClientSide) {
setFillMode(stack, !isFillMode(stack));
}
return new ActionResult<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
} else {
return new ActionResult<>(InteractionResult.PASS, stack);
return new InteractionResultHolder<>(InteractionResult.PASS, stack);
}
}
@Override
@OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() {
public ItemColor getItemColor() {
return (stack, tintIndex) -> {
if (tintIndex > 0) {
DyeColor color = getStoredColor(stack);
if (color != null) {
return color.getColorValue();
return color.getFireworkColor();
}
}
return 0xFFFFFF;

View file

@ -3,19 +3,20 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.packet.PacketClient;
import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ItemDeathRing extends ItemImpl {
public ItemDeathRing() {
super("death_ring", new Properties().maxStackSize(1));
super("death_ring", new Properties().stacksTo(1));
MinecraftForge.EVENT_BUS.register(new Events());
}
@ -28,12 +29,12 @@ public class ItemDeathRing extends ItemImpl {
ItemStack equipped = Helper.getEquippedItem(s -> s.getItem() == ModItems.DEATH_RING, (Player) entity);
if (!equipped.isEmpty()) {
entity.setHealth(entity.getMaxHealth() / 2);
entity.clearActivePotions();
entity.addPotionEffect(new EffectInstance(Effects.REGENERATION, 500, 1));
entity.removeAllEffects();
entity.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 500, 1));
CompoundTag data = new CompoundTag();
data.putInt("id", entity.getEntityId());
PacketHandler.sendToAllAround(entity.level, entity.getPosition(), 32, new PacketClient(1, data));
data.putInt("id", entity.getId());
PacketHandler.sendToAllAround(entity.level, entity.blockPosition(), 32, new PacketClient(1, data));
equipped.shrink(1);
event.setCanceled(true);

View file

@ -7,63 +7,64 @@ import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.BlockEnderCrate;
import de.ellpeck.naturesaura.gui.ContainerEnderCrate;
import de.ellpeck.naturesaura.gui.ModContainers;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.Player;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayer;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.level.Level;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.network.NetworkHooks;
import javax.annotation.Nullable;
import java.util.List;
public class ItemEnderAccess extends ItemImpl {
public ItemEnderAccess() {
super("ender_access");
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
if (handIn != Hand.MAIN_HAND)
return new ActionResult<>(InteractionResult.PASS, playerIn.getHeldItem(handIn));
ItemStack stack = playerIn.getHeldItemMainhand();
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
if (handIn != InteractionHand.MAIN_HAND)
return new InteractionResultHolder<>(InteractionResult.PASS, playerIn.getItemInHand(handIn));
ItemStack stack = playerIn.getMainHandItem();
String name = BlockEnderCrate.getEnderName(stack);
if (!Strings.isNullOrEmpty(name)) {
if (!levelIn.isClientSide && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 10000, false)) {
NetworkHooks.openGui((ServerPlayer) playerIn, new INamedContainerProvider() {
NetworkHooks.openGui((ServerPlayer) playerIn, new MenuProvider() {
@Override
public ITextComponent getDisplayName() {
return new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".ender_access", TextFormatting.ITALIC + name + TextFormatting.RESET);
public Component getDisplayName() {
return new TranslatableComponent("info." + NaturesAura.MOD_ID + ".ender_access", ChatFormatting.ITALIC + name + ChatFormatting.RESET);
}
@Nullable
@Override
public Container createMenu(int windowId, PlayerInventory inv, Player player) {
public AbstractContainerMenu createMenu(int windowId, Inventory inv, Player player) {
IItemHandler handler = ILevelData.getOverworldData(inv.player.level).getEnderStorage(name);
return new ContainerEnderCrate(ModContainers.ENDER_ACCESS, windowId, player, handler);
}
}, buffer -> buffer.writeString(name));
}, buffer -> buffer.writeUtf(name));
}
return new ActionResult<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
return new ActionResult<>(InteractionResult.FAIL, stack);
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
}
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable Level levelIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List<Component> tooltip, TooltipFlag flagIn) {
BlockEnderCrate.addEnderNameInfo(stack, tooltip);
}
}

View file

@ -1,33 +1,33 @@
package de.ellpeck.naturesaura.items;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.api.render.ITrinketItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.entity.player.Player;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class ItemEye extends ItemImpl implements ITrinketItem {
public ItemEye(String name) {
super(name, new Properties().maxStackSize(1));
super(name, new Properties().stacksTo(1));
}
@Override
@OnlyIn(Dist.CLIENT)
public void render(ItemStack stack, Player player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding) {
public void render(ItemStack stack, Player player, RenderType type, PoseStack matrices, MultiBufferSource buffer, int packedLight, boolean isHolding) {
if (type == RenderType.BODY && !isHolding) {
boolean armor = !player.inventory.armorInventory.get(EquipmentSlotType.CHEST.getIndex()).isEmpty();
boolean armor = !player.getInventory().armor.get(EquipmentSlot.CHEST.getIndex()).isEmpty();
matrices.translate(0.1F, 0.225F, armor ? -0.195F : -0.1475F);
matrices.scale(0.3F, 0.3F, 0.3F);
matrices.rotate(Vector3f.XP.rotationDegrees(180));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer);
matrices.mulPose(Vector3f.XP.rotationDegrees(180));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer, 0);
}
}
}

View file

@ -1,17 +1,15 @@
package de.ellpeck.naturesaura.items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraft.world.item.ItemStack;
public class ItemGlowing extends ItemImpl {
public ItemGlowing(String baseName) {
super(baseName);
}
@Override
@OnlyIn(Dist.CLIENT)
public boolean hasEffect(ItemStack stack) {
public boolean isFoil(ItemStack stack) {
return true;
}
}

View file

@ -2,10 +2,10 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.blocks.BlockGoldenLeaves;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.InteractionResult;
import net.minecraft.client.color.item.ItemColor;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
public class ItemGoldFiber extends ItemImpl implements IColorProvidingItem {
@ -14,14 +14,14 @@ public class ItemGoldFiber extends ItemImpl implements IColorProvidingItem {
}
@Override
public IItemColor getItemColor() {
public ItemColor getItemColor() {
return (stack, tintIndex) -> 0xF2FF00;
}
@Override
public InteractionResult onItemUse(ItemUseContext context) {
ItemStack stack = context.getPlayer().getHeldItem(context.getHand());
if (BlockGoldenLeaves.convert(context.getLevel(), context.getPos())) {
public InteractionResult useOn(UseOnContext context) {
ItemStack stack = context.getPlayer().getItemInHand(context.getHand());
if (BlockGoldenLeaves.convert(context.getLevel(), context.getClickedPos())) {
if (!context.getLevel().isClientSide) {
stack.shrink(1);
}

View file

@ -3,26 +3,27 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.entities.EntityLightProjectile;
import de.ellpeck.naturesaura.entities.ModEntities;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.level.Level;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
public class ItemLightStaff extends ItemImpl {
public ItemLightStaff() {
super("light_staff");
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (!levelIn.isClientSide && NaturesAuraAPI.instance().extractAuraFromPlayer(playerIn, 1000, false)) {
EntityLightProjectile projectile = new EntityLightProjectile(ModEntities.LIGHT_PROJECTILE, playerIn, levelIn);
projectile.func_234612_a_(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0, 1.5F, 0);
levelIn.addEntity(projectile);
projectile.shootFromRotation(playerIn, playerIn.getXRot(), playerIn.getYRot(), 0, 1.5F, 0);
levelIn.addFreshEntity(projectile);
}
return new ActionResult<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -2,48 +2,49 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.items.CapabilityItemHandler;
public class ItemLootFinder extends ItemImpl {
public ItemLootFinder() {
super("loot_finder");
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 100000, false))
return new ActionResult<>(InteractionResult.FAIL, stack);
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
if (levelIn.isClientSide) {
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition();
BlockPos pos = playerIn.blockPosition();
Helper.getBlockEntitiesInArea(levelIn, pos, 64, tile -> {
if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent() || tile instanceof MobSpawnerBlockEntity) {
if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent() || tile instanceof SpawnerBlockEntity) {
inst.spawnMagicParticle(
tile.getPos().getX() + 0.5F, tile.getPos().getY() + 0.5F, tile.getPos().getZ() + 0.5F,
tile.getBlockPos().getX() + 0.5F, tile.getBlockPos().getY() + 0.5F, tile.getBlockPos().getZ() + 0.5F,
0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true);
}
return false;
});
for (Entity entity : levelIn.getEntitiesWithinAABB(Entity.class, new AABB(pos).grow(64))) {
for (Entity entity : levelIn.getEntitiesOfClass(Entity.class, new AABB(pos).inflate(64))) {
if (!(entity instanceof LivingEntity) && entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent()) {
inst.spawnMagicParticle(
entity.getPosX(), entity.getPosYEye(), entity.getPosZ(),
entity.getX(), entity.getEyeY(), entity.getZ(),
0F, 0F, 0F, 0xf5f10a, 6F, 20 * 60, 0F, false, true);
}
}
@ -52,9 +53,9 @@ public class ItemLootFinder extends ItemImpl {
inst.setParticleSpawnRange(32);
inst.setParticleCulling(true);
playerIn.swingArm(handIn);
playerIn.swing(handIn);
}
playerIn.getCooldownTracker().setCooldown(this, 20 * 60);
return new ActionResult<>(InteractionResult.SUCCESS, stack);
playerIn.getCooldowns().addCooldown(this, 20 * 60);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -2,32 +2,32 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.entities.EntityMoverMinecart;
import de.ellpeck.naturesaura.entities.ModEntities;
import net.minecraft.block.AbstractRailBlock;
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseRailBlock;
import javax.annotation.Nonnull;
public class ItemMoverMinecart extends ItemImpl {
public ItemMoverMinecart() {
super("mover_cart", new Properties().maxStackSize(1));
super("mover_cart", new Properties().stacksTo(1));
}
@Nonnull
@Override
public InteractionResult onItemUse(ItemUseContext context) {
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos pos = context.getPos();
if (AbstractRailBlock.isRail(level.getBlockState(pos))) {
BlockPos pos = context.getClickedPos();
if (BaseRailBlock.isRail(level.getBlockState(pos))) {
if (!level.isClientSide) {
AbstractMinecartEntity cart = new EntityMoverMinecart(ModEntities.MOVER_CART, level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
level.addEntity(cart);
AbstractMinecart cart = new EntityMoverMinecart(ModEntities.MOVER_CART, level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
level.addFreshEntity(cart);
}
context.getPlayer().getHeldItem(context.getHand()).shrink(1);
context.getPlayer().getItemInHand(context.getHand()).shrink(1);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;

View file

@ -2,15 +2,15 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.level.Level;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import java.util.ArrayList;
import java.util.List;
@ -38,21 +38,21 @@ public class ItemMultiblockMaker extends ItemImpl {
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (!levelIn.isClientSide && playerIn.isCreative()) {
int curr = getMultiblock(stack);
int next = (curr + 1) % multiblocks().size();
stack.getOrCreateTag().putInt("multiblock", next);
}
return new ActionResult<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
@Override
public InteractionResult onItemUse(ItemUseContext context) {
public InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
if (player.isCreative()) {
int id = getMultiblock(player.getHeldItem(context.getHand()));
int id = getMultiblock(player.getItemInHand(context.getHand()));
if (id < 0)
return InteractionResult.PASS;
IMultiblock multi = multiblocks().get(id);
@ -60,8 +60,8 @@ public class ItemMultiblockMaker extends ItemImpl {
return InteractionResult.PASS;
if (!context.getLevel().isClientSide)
multi.forEach(context.getPos().up(), (char) 0, (blockPos, matcher) -> {
context.getLevel().setBlockState(blockPos, matcher.getDefaultState());
multi.forEach(context.getClickedPos().above(), (char) 0, (blockPos, matcher) -> {
context.getLevel().setBlockAndUpdate(blockPos, matcher.defaultState());
return true;
});
@ -71,12 +71,13 @@ public class ItemMultiblockMaker extends ItemImpl {
}
@Override
public ITextComponent getDisplayName(ItemStack stack) {
TextComponent name = (TextComponent) super.getDisplayName(stack);
public Component getName(ItemStack stack) {
MutableComponent name = (MutableComponent) super.getName(stack);
int id = getMultiblock(stack);
if (id < 0)
return name;
IMultiblock multi = multiblocks().get(id);
return multi == null ? name : name.appendString(" (" + multi.getName() + ")");
return multi == null ? name : name.append(" (" + multi.getName() + ")");
}
}

View file

@ -1,33 +1,34 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public class ItemNetheriteFinder extends ItemImpl {
public ItemNetheriteFinder() {
super("netherite_finder", new Properties().maxStackSize(1));
super("netherite_finder", new Properties().stacksTo(1));
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
NaturesAuraAPI.IInternalHooks inst = NaturesAuraAPI.instance();
if (!inst.extractAuraFromPlayer(playerIn, 200000, false))
return new ActionResult<>(InteractionResult.FAIL, stack);
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
if (levelIn.isClientSide) {
inst.setParticleDepth(false);
inst.setParticleSpawnRange(64);
inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition();
BlockPos pos = playerIn.blockPosition();
int range = 12;
for (int x = -range; x <= range; x++) {
for (int y = 0; y <= 128; y++) {
@ -46,9 +47,9 @@ public class ItemNetheriteFinder extends ItemImpl {
inst.setParticleDepth(true);
inst.setParticleSpawnRange(32);
inst.setParticleCulling(true);
playerIn.swingArm(handIn);
playerIn.swing(handIn);
}
playerIn.getCooldownTracker().setCooldown(this, 20 * 60);
return new ActionResult<>(InteractionResult.SUCCESS, stack);
playerIn.getCooldowns().addCooldown(this, 20 * 60);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -4,19 +4,19 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.entity.player.ServerPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.level.server.ServerLevel;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingEvent;
@ -28,6 +28,7 @@ import java.util.Optional;
import java.util.UUID;
public class ItemPetReviver extends ItemImpl {
public ItemPetReviver() {
super("pet_reviver");
MinecraftForge.EVENT_BUS.register(new Events());
@ -38,32 +39,31 @@ public class ItemPetReviver extends ItemImpl {
@SubscribeEvent
public void onEntityTick(LivingEvent.LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || entity.level.getGameTime() % 20 != 0 || !(entity instanceof TameableEntity))
if (entity.level.isClientSide || entity.level.getGameTime() % 20 != 0 || !(entity instanceof TamableAnimal tameable))
return;
TameableEntity tameable = (TameableEntity) entity;
if (!tameable.isTamed() || !tameable.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
if (!tameable.isTame() || !tameable.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
return;
LivingEntity owner = tameable.getOwner();
if (owner == null || owner.getDistanceSq(tameable) > 5 * 5)
if (owner == null || owner.distanceToSqr(tameable) > 5 * 5)
return;
if (entity.level.rand.nextFloat() >= 0.65F) {
((ServerLevel) entity.level).spawnParticle(ParticleTypes.HEART,
entity.getPosX() + entity.level.rand.nextGaussian() * 0.25F,
entity.getPosYEye() + entity.level.rand.nextGaussian() * 0.25F,
entity.getPosZ() + entity.level.rand.nextGaussian() * 0.25F,
entity.level.rand.nextInt(2) + 1, 0, 0, 0, 0);
if (entity.level.random.nextFloat() >= 0.65F) {
((ServerLevel) entity.level).sendParticles(ParticleTypes.HEART,
entity.getX() + entity.level.random.nextGaussian() * 0.25F,
entity.getEyeY() + entity.level.random.nextGaussian() * 0.25F,
entity.getZ() + entity.level.random.nextGaussian() * 0.25F,
entity.level.random.nextInt(2) + 1, 0, 0, 0, 0);
}
}
// we need to use the event since the item doesn't receive the interaction for tamed pets..
// we need to use the event since the item doesn't receive the interaction for tamed pets...
@SubscribeEvent
public void onEntityInteract(PlayerInteractEvent.EntityInteractSpecific event) {
Entity target = event.getTarget();
if (!(target instanceof TameableEntity) || !((TameableEntity) target).isTamed())
if (!(target instanceof TamableAnimal) || !((TamableAnimal) target).isTame())
return;
if (target.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
return;
ItemStack stack = event.getPlayer().getHeldItem(event.getHand());
ItemStack stack = event.getPlayer().getItemInHand(event.getHand());
if (stack.getItem() != ModItems.PET_REVIVER)
return;
target.getPersistentData().putBoolean(NaturesAura.MOD_ID + ":pet_reviver", true);
@ -77,26 +77,23 @@ public class ItemPetReviver extends ItemImpl {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onLivingDeath(LivingDeathEvent event) {
LivingEntity entity = event.getEntityLiving();
if (entity.level.isClientSide || !(entity instanceof TameableEntity))
if (entity.level.isClientSide || !(entity instanceof TamableAnimal tameable))
return;
TameableEntity tameable = (TameableEntity) entity;
if (!tameable.isTamed() || !tameable.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
if (!tameable.isTame() || !tameable.getPersistentData().getBoolean(NaturesAura.MOD_ID + ":pet_reviver"))
return;
// get the overworld, and the overworld's spawn point, by default
ServerLevel spawnLevel = tameable.level.getServer().func_241755_D_();
Vector3d spawn = Vector3d.copyCenteredHorizontally(spawnLevel.func_241135_u_());
ServerLevel spawnLevel = tameable.level.getServer().overworld();
Vec3 spawn = Vec3.atBottomCenterOf(spawnLevel.getSharedSpawnPos());
// check if the owner is online, and respawn at the bed if they are
LivingEntity owner = tameable.getOwner();
if (owner instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) owner;
// I'm not really sure what this means, but I got it from PlayerList.func_232644_a_ haha
BlockPos pos = player.func_241140_K_();
if (owner instanceof ServerPlayer player) {
BlockPos pos = player.getRespawnPosition();
if (pos != null) {
float f = player.func_242109_L();
boolean b = player.func_241142_M_();
Optional<Vector3d> bed = Player.func_242374_a((ServerLevel) player.level, pos, f, b, false);
float f = player.getRespawnAngle();
boolean b = player.isRespawnForced();
Optional<Vec3> bed = Player.findRespawnPositionAndUseSpawnBlock((ServerLevel) player.level, pos, f, b, false);
if (bed.isPresent()) {
spawnLevel = (ServerLevel) player.level;
spawn = bed.get();
@ -104,38 +101,38 @@ public class ItemPetReviver extends ItemImpl {
}
}
PacketHandler.sendToAllAround(tameable.level, tameable.getPosition(), 32, new PacketParticles((float) tameable.getPosX(), (float) tameable.getPosYEye(), (float) tameable.getPosZ(), PacketParticles.Type.PET_REVIVER, 0xc2461d));
PacketHandler.sendToAllAround(tameable.level, tameable.blockPosition(), 32, new PacketParticles((float) tameable.getX(), (float) tameable.getEyeY(), (float) tameable.getZ(), PacketParticles.Type.PET_REVIVER, 0xc2461d));
TameableEntity spawnedPet = tameable;
TamableAnimal spawnedPet = tameable;
if (tameable.level != spawnLevel) {
((ServerLevel) tameable.level).removeEntity(tameable, true);
spawnedPet = (TameableEntity) tameable.getType().create(spawnLevel);
spawnedPet = (TamableAnimal) tameable.getType().create(spawnLevel);
}
// respawn (a copy of) the pet
spawnedPet.copyDataFromOld(tameable);
spawnedPet.setMotion(0, 0, 0);
spawnedPet.setLocationAndAngles(spawn.x, spawn.y, spawn.z, tameable.rotationYaw, tameable.rotationPitch);
while (!spawnLevel.hasNoCollisions(spawnedPet))
spawnedPet.setPosition(spawnedPet.getPosX(), spawnedPet.getPosY() + 1, spawnedPet.getPosZ());
spawnedPet.restoreFrom(tameable);
spawnedPet.setDeltaMovement(0, 0, 0);
spawnedPet.moveTo(spawn.x, spawn.y, spawn.z, tameable.getYRot(), tameable.getXRot());
while (!spawnLevel.noCollision(spawnedPet))
spawnedPet.setPos(spawnedPet.getX(), spawnedPet.getY() + 1, spawnedPet.getZ());
spawnedPet.setHealth(spawnedPet.getMaxHealth());
spawnedPet.getNavigator().clearPath();
spawnedPet.getNavigation().stop();
// sit down (on the server side!)
spawnedPet.func_233687_w_(true);
spawnedPet.setInSittingPose(true);
spawnedPet.setJumping(false);
spawnedPet.setAttackTarget(null);
spawnedPet.setTarget(null);
if (tameable.level != spawnLevel) {
spawnLevel.addEntity(spawnedPet);
tameable.remove(false);
spawnLevel.addFreshEntity(spawnedPet);
tameable.remove(Entity.RemovalReason.DISCARDED);
}
// drain aura
BlockPos auraPos = IAuraChunk.getHighestSpot(spawnLevel, spawnedPet.getPosition(), 35, spawnedPet.getPosition());
BlockPos auraPos = IAuraChunk.getHighestSpot(spawnLevel, spawnedPet.blockPosition(), 35, spawnedPet.blockPosition());
IAuraChunk.getAuraChunk(spawnLevel, auraPos).drainAura(auraPos, 200000);
PacketHandler.sendToAllAround(spawnedPet.level, spawnedPet.getPosition(), 32, new PacketParticles((float) spawnedPet.getPosX(), (float) spawnedPet.getPosYEye(), (float) spawnedPet.getPosZ(), PacketParticles.Type.PET_REVIVER, 0x4dba2f));
PacketHandler.sendToAllAround(spawnedPet.level, spawnedPet.blockPosition(), 32, new PacketParticles((float) spawnedPet.getX(), (float) spawnedPet.getEyeY(), (float) spawnedPet.getZ(), PacketParticles.Type.PET_REVIVER, 0x4dba2f));
if (owner instanceof Player)
owner.sendMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".pet_reviver", spawnedPet.getDisplayName()).mergeStyle(TextFormatting.ITALIC, TextFormatting.GRAY), UUID.randomUUID());
owner.sendMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".pet_reviver", spawnedPet.getDisplayName()).withStyle(ChatFormatting.ITALIC, ChatFormatting.GRAY), UUID.randomUUID());
event.setCanceled(true);
}
}

View file

@ -4,19 +4,19 @@ import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.level.Level;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -28,7 +28,7 @@ public class ItemRangeVisualizer extends ItemImpl {
public static final ListMultimap<ResourceLocation, BlockPos> VISUALIZED_RAILS = ArrayListMultimap.create();
public ItemRangeVisualizer() {
super("range_visualizer", new Properties().maxStackSize(1));
super("range_visualizer", new Properties().stacksTo(1));
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
@ -44,33 +44,33 @@ public class ItemRangeVisualizer extends ItemImpl {
public static <T> void visualize(Player player, ListMultimap<ResourceLocation, T> map, ResourceLocation dim, T value) {
if (map.containsEntry(dim, value)) {
map.remove(dim, value);
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end"), true);
} else {
map.put(dim, value);
player.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.start"), true);
player.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.start"), true);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(Level levelIn, Player playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
if (playerIn.isSneaking()) {
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (playerIn.isCrouching()) {
clear();
playerIn.sendStatusMessage(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true);
return new ActionResult<>(InteractionResult.SUCCESS, stack);
playerIn.displayClientMessage(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".range_visualizer.end_all"), true);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
return new ActionResult<>(InteractionResult.PASS, stack);
return new InteractionResultHolder<>(InteractionResult.PASS, stack);
}
@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);
Block block = state.getBlock();
if (block instanceof IVisualizable) {
if (level.isClientSide)
visualize(context.getPlayer(), VISUALIZED_BLOCKS, level.func_234923_W_().func_240901_a_(), pos);
visualize(context.getPlayer(), VISUALIZED_BLOCKS, level.dimension().location(), pos);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
@ -86,10 +86,10 @@ public class ItemRangeVisualizer extends ItemImpl {
Entity entity = event.getTarget();
if (entity instanceof IVisualizable) {
if (entity.level.isClientSide) {
ResourceLocation dim = entity.level.func_234923_W_().func_240901_a_();
ResourceLocation dim = entity.level.dimension().location();
visualize(event.getPlayer(), VISUALIZED_ENTITIES, dim, entity);
}
event.getPlayer().swingArm(event.getHand());
event.getPlayer().swing(event.getHand());
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true);
}

View file

@ -1,33 +1,33 @@
package de.ellpeck.naturesaura.items;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.render.ITrinketItem;
import de.ellpeck.naturesaura.items.tools.ItemArmor;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.reg.ModArmorMaterial;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
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.AABB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.level.Level;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
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;
@ -36,23 +36,22 @@ import java.util.List;
public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
public ItemShockwaveCreator() {
super("shockwave_creator", new Properties().maxStackSize(1));
super("shockwave_creator", new Properties().stacksTo(1));
}
@Override
public void inventoryTick(ItemStack stack, Level levelIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (levelIn.isClientSide || !(entityIn instanceof LivingEntity))
if (levelIn.isClientSide || !(entityIn instanceof LivingEntity living))
return;
LivingEntity living = (LivingEntity) entityIn;
if (!living.isOnGround()) {
CompoundTag compound = stack.getOrCreateTag();
if (compound.getBoolean("air"))
return;
compound.putBoolean("air", true);
compound.putDouble("x", living.getPosX());
compound.putDouble("y", living.getPosY());
compound.putDouble("z", living.getPosZ());
compound.putDouble("x", living.getX());
compound.putDouble("y", living.getY());
compound.putDouble("z", living.getZ());
} else {
if (!stack.hasTag())
return;
@ -62,59 +61,59 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
compound.putBoolean("air", false);
if (!living.isSneaking())
if (!living.isCrouching())
return;
if (living.getDistanceSq(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
return;
if (living instanceof Player && !NaturesAuraAPI.instance().extractAuraFromPlayer((Player) living, 1000, false))
return;
DamageSource source;
if (living instanceof Player)
source = DamageSource.causePlayerDamage((Player) living);
source = DamageSource.playerAttack((Player) living);
else
source = DamageSource.MAGIC;
boolean infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED);
int range = 5;
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));
List<LivingEntity> mobs = levelIn.getEntitiesOfClass(LivingEntity.class, new AABB(
living.getX() - range, living.getY() - 0.5, living.getZ() - range,
living.getX() + range, living.getY() + 0.5, living.getZ() + range));
for (LivingEntity mob : mobs) {
if (!mob.isAlive() || mob == living)
continue;
if (living.getDistanceSq(mob) > range * range)
if (living.distanceToSqr(mob) > range * range)
continue;
if (living instanceof Player && !NaturesAuraAPI.instance().extractAuraFromPlayer((Player) living, 500, false))
break;
mob.attackEntityFrom(source, 4F);
mob.hurt(source, 4F);
if (infusedSet)
mob.addPotionEffect(new EffectInstance(Effects.WITHER, 120));
mob.addEffect(new MobEffectInstance(MobEffects.WITHER, 120));
}
BlockPos pos = living.getPosition();
BlockPos down = pos.down();
BlockPos pos = living.blockPosition();
BlockPos down = pos.below();
BlockState downState = levelIn.getBlockState(down);
if (downState.getMaterial() != Material.AIR) {
SoundType type = downState.getBlock().getSoundType(downState, levelIn, down, null);
levelIn.playSound(null, pos, type.getBreakSound(), SoundCategory.BLOCKS, type.getVolume() * 0.5F, type.getPitch() * 0.8F);
levelIn.playSound(null, pos, type.getBreakSound(), SoundSource.BLOCKS, type.getVolume() * 0.5F, type.getPitch() * 0.8F);
}
PacketHandler.sendToAllAround(levelIn, pos, 32, new PacketParticles((float) living.getPosX(), (float) living.getPosY(), (float) living.getPosZ(), PacketParticles.Type.SHOCKWAVE_CREATOR));
PacketHandler.sendToAllAround(levelIn, pos, 32, new PacketParticles((float) living.getX(), (float) living.getY(), (float) living.getZ(), PacketParticles.Type.SHOCKWAVE_CREATOR));
}
}
@Override
@OnlyIn(Dist.CLIENT)
public void render(ItemStack stack, Player player, RenderType type, MatrixStack matrices, IRenderTypeBuffer buffer, int packedLight, boolean isHolding) {
public void render(ItemStack stack, Player player, RenderType type, PoseStack matrices, MultiBufferSource buffer, int packedLight, boolean isHolding) {
if (type == RenderType.BODY && !isHolding) {
boolean armor = !player.inventory.armorInventory.get(EquipmentSlotType.CHEST.getIndex()).isEmpty();
boolean armor = !player.getInventory().armor.get(EquipmentSlot.CHEST.getIndex()).isEmpty();
matrices.translate(0, 0.125F, armor ? -0.195F : -0.1475F);
matrices.scale(0.3F, 0.3F, 0.3F);
matrices.rotate(Vector3f.XP.rotationDegrees(180));
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer);
matrices.mulPose(Vector3f.XP.rotationDegrees(180));
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer, 0);
}
}
}

View file

@ -4,9 +4,8 @@ import de.ellpeck.naturesaura.entities.EntityStructureFinder;
import de.ellpeck.naturesaura.entities.ModEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.ActionResult;
import net.minecraft.util.InteractionResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@ -30,18 +29,18 @@ public class ItemStructureFinder extends ItemImpl {
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
ItemStack stack = playerIn.getItemInHand(handIn);
if (!levelIn.isClientSide && ((ServerLevel) levelIn).structureFeatureManager().shouldGenerateFeatures()) {
BlockPos pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((ServerLevel) levelIn, this.structureName, playerIn.getPosition(), this.radius, false);
BlockPos pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((ServerLevel) levelIn, this.structureName, playerIn.blockPosition(), this.radius, false);
if (pos != null) {
EntityStructureFinder entity = new EntityStructureFinder(ModEntities.STRUCTURE_FINDER, levelIn);
entity.setPosition(playerIn.getPosX(), playerIn.getPosYHeight(0.5D), playerIn.getPosZ());
entity.func_213863_b(stack);
entity.getDataManager().set(EntityStructureFinder.COLOR, this.color);
entity.moveTowards(pos.up(64));
levelIn.addEntity(entity);
entity.setPos(playerIn.getX(), playerIn.getY(0.5D), playerIn.getZ());
entity.setItem(stack);
entity.getEntityData().set(EntityStructureFinder.COLOR, this.color);
entity.signalTo(pos.above(64));
levelIn.addFreshEntity(entity);
stack.shrink(1);
}
}
return new ActionResult<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -75,7 +75,7 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
return;
if (!isSelected || levelIn.isClientSide)
return;
AABB bounds = new AABB(entityIn.getOnPos()).inflate(3.5F);
AABB bounds = new AABB(entityIn.blockPosition()).inflate(3.5F);
for (ItemEntity item : levelIn.getEntitiesOfClass(ItemEntity.class, bounds)) {
// only pick up freshly dropped items
if (item.tickCount >= 5 || !item.isAlive())

View file

@ -1,8 +1,8 @@
package de.ellpeck.naturesaura.misc;
import net.minecraft.block.Block;
import net.minecraft.item.DyeColor;
import net.minecraft.util.ResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
@ -24,7 +24,7 @@ public final class ColoredBlockHelper {
private static List<Block> collectBlocks(String name) {
List<Block> blocks = new ArrayList<>();
for (DyeColor color : DyeColor.values())
blocks.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(color.getString() + '_' + name)));
blocks.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(color.getName() + '_' + name)));
return Collections.unmodifiableList(blocks);
}

View file

@ -5,7 +5,6 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.events.ClientEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.level.chunk.Chunk;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
@ -40,7 +39,7 @@ public class PacketAuraChunk {
int amount = buf.readInt();
for (int i = 0; i < amount; i++) {
packet.drainSpots.put(
BlockPos.fromLong(buf.readLong()),
BlockPos.of(buf.readLong()),
new MutableInt(buf.readInt())
);
}
@ -54,7 +53,7 @@ public class PacketAuraChunk {
buf.writeInt(packet.drainSpots.size());
for (Map.Entry<BlockPos, MutableInt> entry : packet.drainSpots.entrySet()) {
buf.writeLong(entry.getKey().toLong());
buf.writeLong(entry.getKey().asLong());
buf.writeInt(entry.getValue().intValue());
}
}

View file

@ -3,19 +3,20 @@ package de.ellpeck.naturesaura.packet;
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketBuffer;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class PacketClient {
private int type;
private CompoundTag data;
@ -28,16 +29,16 @@ public class PacketClient {
}
public static PacketClient fromBytes(PacketBuffer buf) {
public static PacketClient fromBytes(FriendlyByteBuf buf) {
PacketClient client = new PacketClient();
client.type = buf.readByte();
client.data = buf.readCompoundTag();
client.data = buf.readNbt();
return client;
}
public static void toBytes(PacketClient packet, PacketBuffer buf) {
public static void toBytes(PacketClient packet, FriendlyByteBuf buf) {
buf.writeByte(packet.type);
buf.writeCompoundTag(packet.data);
buf.writeNbt(packet.data);
}
// lambda causes classloading issues on a server here
@ -51,12 +52,12 @@ public class PacketClient {
switch (message.type) {
case 0: // dimension rail visualization
ResourceLocation goalDim = new ResourceLocation(message.data.getString("dim"));
BlockPos goalPos = BlockPos.fromLong(message.data.getLong("pos"));
BlockPos goalPos = BlockPos.of(message.data.getLong("pos"));
ItemRangeVisualizer.visualize(mc.player, ItemRangeVisualizer.VISUALIZED_RAILS, goalDim, goalPos);
case 1:
Entity entity = mc.level.getEntityByID(message.data.getInt("id"));
mc.particles.emitParticleAtEntity(entity, ParticleTypes.TOTEM_OF_UNDYING, 30);
mc.level.playSound(entity.getPosX(), entity.getPosY(), entity.getPosZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.0F, 1.0F, false);
Entity entity = mc.level.getEntity(message.data.getInt("id"));
mc.particleEngine.createTrackingEmitter(entity, ParticleTypes.TOTEM_OF_UNDYING, 30);
mc.level.playLocalSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.TOTEM_USE, entity.getSoundSource(), 1.0F, 1.0F, false);
if (entity == mc.player) {
mc.gameRenderer.displayItemActivation(new ItemStack(ModItems.DEATH_RING));
}

View file

@ -4,7 +4,6 @@ import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkRegistry;
@ -29,7 +28,7 @@ public final class PacketHandler {
}
public static void sendToAllAround(Level level, BlockPos pos, int range, Object message) {
network.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), range, level.func_234923_W_())), message);
network.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(pos.getX(), pos.getY(), pos.getZ(), range, level.dimension())), message);
}
public static void sendTo(Player player, Object message) {

View file

@ -6,15 +6,12 @@ import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
import de.ellpeck.naturesaura.entities.EntityStructureFinder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.core.BlockPos;
import net.minecraft.level.biome.BiomeColors;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.BiConsumer;
@ -40,7 +37,7 @@ public class PacketParticles {
}
public static PacketParticles fromBytes(FriendlyByteBuf buf) {
PacketParticles packet = new PacketParticles();
var packet = new PacketParticles();
packet.posX = buf.readFloat();
packet.posY = buf.readFloat();
@ -48,7 +45,7 @@ public class PacketParticles {
packet.type = Type.values()[buf.readByte()];
packet.data = new int[buf.readByte()];
for (int i = 0; i < packet.data.length; i++) {
for (var i = 0; i < packet.data.length; i++) {
packet.data[i] = buf.readInt();
}
@ -62,7 +59,7 @@ public class PacketParticles {
buf.writeByte(packet.type.ordinal());
buf.writeByte(packet.data.length);
for (int i : packet.data) {
for (var i : packet.data) {
buf.writeInt(i);
}
}
@ -83,136 +80,136 @@ public class PacketParticles {
public enum Type {
TR_GOLD_POWDER((message, level) -> {
BlockPos pos = new BlockPos(message.posX, message.posY, message.posZ);
var pos = new BlockPos(message.posX, message.posY, message.posZ);
Multiblocks.TREE_RITUAL.forEach(pos, 'G', (dustPos, matcher) -> {
BlockState state = level.getBlockState(dustPos);
AABB box = state.getShape(level, dustPos).getBoundingBox();
var state = level.getBlockState(dustPos);
var box = state.getShape(level, dustPos).bounds();
NaturesAuraAPI.instance().spawnMagicParticle(
dustPos.getX() + box.minX + (box.maxX - box.minX) * level.rand.nextFloat(),
dustPos.getX() + box.minX + (box.maxX - box.minX) * level.random.nextFloat(),
dustPos.getY() + 0.1F,
dustPos.getZ() + box.minZ + (box.maxZ - box.minZ) * level.rand.nextFloat(),
(float) level.rand.nextGaussian() * 0.02F,
level.rand.nextFloat() * 0.01F + 0.02F,
(float) level.rand.nextGaussian() * 0.02F,
dustPos.getZ() + box.minZ + (box.maxZ - box.minZ) * level.random.nextFloat(),
(float) level.random.nextGaussian() * 0.02F,
level.random.nextFloat() * 0.01F + 0.02F,
(float) level.random.nextGaussian() * 0.02F,
0xf4cb42, 2F, 50, 0F, false, true);
return true;
});
}),
TR_CONSUME_ITEM((message, level) -> {
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--) {
for (var i = level.random.nextInt(20) + 10; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.5F, message.posY + 0.9F, message.posZ + 0.5F,
(float) level.rand.nextGaussian() * 0.04F, level.rand.nextFloat() * 0.04F, (float) level.rand.nextGaussian() * 0.04F,
(float) level.random.nextGaussian() * 0.04F, level.random.nextFloat() * 0.04F, (float) level.random.nextGaussian() * 0.04F,
0x89cc37, 1.5F, 25, 0F, false, true);
}
}),
TR_DISAPPEAR((message, level) -> {
for (int i = level.rand.nextInt(5) + 3; i >= 0; i--) {
for (var i = level.random.nextInt(5) + 3; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat(), message.posY + level.rand.nextFloat(), message.posZ + level.rand.nextFloat(),
message.posX + level.random.nextFloat(), message.posY + level.random.nextFloat(), message.posZ + level.random.nextFloat(),
0F, 0F, 0F,
0x33FF33, 1F, 50, 0F, false, true);
}
}),
TR_SPAWN_RESULT((message, level) -> {
for (int i = level.rand.nextInt(10) + 10; i >= 0; i--) {
for (var i = level.random.nextInt(10) + 10; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY, message.posZ,
level.rand.nextGaussian() * 0.1F, level.rand.nextGaussian() * 0.1F, level.rand.nextGaussian() * 0.1F,
level.random.nextGaussian() * 0.1F, level.random.nextGaussian() * 0.1F, level.random.nextGaussian() * 0.1F,
0x89cc37, 2F, 100, 0F, true, true);
}
}),
ALTAR_CONVERSION((message, level) -> {
int color = message.data[0];
for (int i = level.rand.nextInt(5) + 2; i >= 0; i--) {
var color = message.data[0];
for (var i = level.random.nextInt(5) + 2; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posY + 0.9F + 0.25F * level.rand.nextFloat(),
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.02F, level.rand.nextFloat() * 0.02F, level.rand.nextGaussian() * 0.02F,
color, level.rand.nextFloat() * 1.5F + 0.75F, 20, 0F, false, true);
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 0.9F + 0.25F * level.random.nextFloat(),
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.02F, level.random.nextFloat() * 0.02F, level.random.nextGaussian() * 0.02F,
color, level.random.nextFloat() * 1.5F + 0.75F, 20, 0F, false, true);
}
}),
POTION_GEN((message, level) -> {
int color = message.data[0];
boolean releaseAura = message.data[1] > 0;
for (int i = level.rand.nextInt(5) + 5; i >= 0; i--) {
var color = message.data[0];
var releaseAura = message.data[1] > 0;
for (var i = level.random.nextInt(5) + 5; i >= 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat(),
message.posX + level.random.nextFloat(),
message.posY + 1.1F,
message.posZ + level.rand.nextFloat(),
level.rand.nextGaussian() * 0.01F, level.rand.nextFloat() * 0.1F, level.rand.nextGaussian() * 0.01F,
color, 2F + level.rand.nextFloat(), 40, 0F, true, true);
message.posZ + level.random.nextFloat(),
level.random.nextGaussian() * 0.01F, level.random.nextFloat() * 0.1F, level.random.nextGaussian() * 0.01F,
color, 2F + level.random.nextFloat(), 40, 0F, true, true);
if (releaseAura)
for (int x = -1; x <= 1; x += 2)
for (int z = -1; z <= 1; z += 2) {
for (var x = -1; x <= 1; x += 2)
for (var z = -1; z <= 1; z += 2) {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + x * 3 + 0.5F,
message.posY + 2.5,
message.posZ + z * 3 + 0.5F,
level.rand.nextGaussian() * 0.02F,
level.rand.nextFloat() * 0.04F,
level.rand.nextGaussian() * 0.02F,
0xd6340c, 1F + level.rand.nextFloat() * 2F, 75, 0F, true, true);
level.random.nextGaussian() * 0.02F,
level.random.nextFloat() * 0.04F,
level.random.nextGaussian() * 0.02F,
0xd6340c, 1F + level.random.nextFloat() * 2F, 75, 0F, true, true);
}
}
}),
PLANT_BOOST((message, level) -> {
for (int i = level.rand.nextInt(20) + 15; i >= 0; i--)
for (var i = level.random.nextInt(20) + 15; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat(),
message.posY + 0.25F + level.rand.nextFloat() * 0.5F,
message.posZ + level.rand.nextFloat(),
0F, level.rand.nextFloat() * 0.02F, 0F,
0x5ccc30, 1F + level.rand.nextFloat() * 2F, 50, 0F, false, true);
message.posX + level.random.nextFloat(),
message.posY + 0.25F + level.random.nextFloat() * 0.5F,
message.posZ + level.random.nextFloat(),
0F, level.random.nextFloat() * 0.02F, 0F,
0x5ccc30, 1F + level.random.nextFloat() * 2F, 50, 0F, false, true);
}),
FLOWER_GEN_CONSUME((message, level) -> {
int color = message.data[0];
for (int i = level.rand.nextInt(10) + 10; i >= 0; i--)
var color = message.data[0];
for (var i = level.random.nextInt(10) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posY + 0.25F + level.rand.nextFloat() * 0.5F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.02F,
level.rand.nextGaussian() * 0.02F,
level.rand.nextGaussian() * 0.02F,
color, level.rand.nextFloat() * 2F + 1F, 25, 0F, false, true);
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 0.25F + level.random.nextFloat() * 0.5F,
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.02F,
level.random.nextGaussian() * 0.02F,
level.random.nextGaussian() * 0.02F,
color, level.random.nextFloat() * 2F + 1F, 25, 0F, false, true);
}),
FLOWER_GEN_AURA_CREATION((message, level) -> {
for (int i = level.rand.nextInt(10) + 5; i >= 0; i--)
for (var i = level.random.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.rand.nextFloat() * 1.5F, 40, 0F, false, true);
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.random.nextFloat() * 1.5F, 40, 0F, false, true);
}),
PLACER_PLACING((message, level) -> {
for (int i = level.rand.nextInt(20) + 20; i >= 0; i--) {
boolean side = level.rand.nextBoolean();
float x = side ? level.rand.nextFloat() : level.rand.nextBoolean() ? 1.1F : -0.1F;
float z = !side ? level.rand.nextFloat() : level.rand.nextBoolean() ? 1.1F : -0.1F;
for (var i = level.random.nextInt(20) + 20; i >= 0; i--) {
var side = level.random.nextBoolean();
var x = side ? level.random.nextFloat() : level.random.nextBoolean() ? 1.1F : -0.1F;
var z = !side ? level.random.nextFloat() : level.random.nextBoolean() ? 1.1F : -0.1F;
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + x, message.posY + 0.1F + level.rand.nextFloat() * 0.98F, message.posZ + z,
message.posX + x, message.posY + 0.1F + level.random.nextFloat() * 0.98F, message.posZ + z,
0F, 0F, 0F,
0xad7a37, level.rand.nextFloat() + 1F, 50, 0F, true, true);
0xad7a37, level.random.nextFloat() + 1F, 50, 0F, true, true);
}
}),
HOPPER_UPGRADE((message, level) -> {
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.45F, message.posZ,
level.rand.nextGaussian() * 0.015F,
level.rand.nextGaussian() * 0.015F,
level.rand.nextGaussian() * 0.015F,
0xdde7ff, level.rand.nextFloat() + 1F, 30, -0.06F, true, true);
level.random.nextGaussian() * 0.015F,
level.random.nextGaussian() * 0.015F,
level.random.nextGaussian() * 0.015F,
0xdde7ff, level.random.nextFloat() + 1F, 30, -0.06F, true, true);
}),
SHOCKWAVE_CREATOR((message, level) -> {
for (int i = 0; i < 360; i += 2) {
double rad = Math.toRadians(i);
for (var i = 0; i < 360; i += 2) {
var rad = Math.toRadians(i);
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.01F, message.posZ,
(float) Math.sin(rad) * 0.65F,
@ -222,359 +219,359 @@ public class PacketParticles {
}
}),
OAK_GENERATOR((message, level) -> {
int sapX = message.data[0];
int sapY = message.data[1];
int sapZ = message.data[2];
boolean releaseAura = message.data[3] > 0;
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
var sapX = message.data[0];
var sapY = message.data[1];
var sapZ = message.data[2];
var releaseAura = message.data[3] > 0;
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
sapX + 0.5F + (float) level.rand.nextGaussian() * 3F,
sapY + 0.5F + level.rand.nextFloat() * 4F,
sapZ + 0.5F + (float) level.rand.nextGaussian() * 3F,
sapX + 0.5F + (float) level.random.nextGaussian() * 3F,
sapY + 0.5F + level.random.nextFloat() * 4F,
sapZ + 0.5F + (float) level.random.nextGaussian() * 3F,
message.posX + 0.5F,
message.posY + 0.5F,
message.posZ + 0.5F,
0.6F, BiomeColors.getGrassColor(level, new BlockPos(sapX, sapY, sapZ)), 1.5F);
0.6F, BiomeColors.getAverageGrassColor(level, new BlockPos(sapX, sapY, sapZ)), 1.5F);
if (releaseAura)
for (int i = level.rand.nextInt(10) + 10; i >= 0; i--)
for (var i = level.random.nextInt(10) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.03F,
level.rand.nextFloat() * 0.04F + 0.04F,
level.rand.nextGaussian() * 0.03F,
0x5ccc30, 1F + level.rand.nextFloat() * 1.5F, 60, 0F, false, true);
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.03F,
level.random.nextFloat() * 0.04F + 0.04F,
level.random.nextGaussian() * 0.03F,
0x5ccc30, 1F + level.random.nextFloat() * 1.5F, 60, 0F, false, true);
}),
OFFERING_TABLE((message, level) -> {
int genX = message.data[0];
int genY = message.data[1];
int genZ = message.data[2];
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
var genX = message.data[0];
var genY = message.data[1];
var genZ = message.data[2];
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.5F, message.posZ,
level.rand.nextGaussian() * 0.02F,
level.rand.nextFloat() * 0.25F,
level.rand.nextGaussian() * 0.02F,
level.random.nextGaussian() * 0.02F,
level.random.nextFloat() * 0.25F,
level.random.nextGaussian() * 0.02F,
0xffadfd, 1.5F, 40, 0F, false, true);
for (int i = level.rand.nextInt(50) + 30; i >= 0; i--)
for (var i = level.random.nextInt(50) + 30; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
genX + 0.5F + level.rand.nextGaussian() * 2.5F,
genX + 0.5F + level.random.nextGaussian() * 2.5F,
genY + 0.1F,
genZ + 0.5F + level.rand.nextGaussian() * 2.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.01F,
level.rand.nextGaussian() * 0.01F,
genZ + 0.5F + level.random.nextGaussian() * 2.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.01F,
level.random.nextGaussian() * 0.01F,
0xd3e4ff, 1.5F, 150, 0F, false, true);
}),
PICKUP_STOPPER((message, level) -> {
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.4F, message.posZ,
level.rand.nextGaussian() * 0.005F,
level.rand.nextFloat() * 0.005F,
level.rand.nextGaussian() * 0.005F,
level.random.nextGaussian() * 0.005F,
level.random.nextFloat() * 0.005F,
level.random.nextGaussian() * 0.005F,
0xcc3116, 1.5F, 40, 0F, false, true);
}),
SPAWN_LAMP((message, level) -> {
for (int i = level.rand.nextInt(5) + 5; i >= 0; i--)
for (var i = level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.3F + level.rand.nextFloat() * 0.4F,
message.posY + 0.15F + level.rand.nextFloat() * 0.5F,
message.posZ + 0.3F + level.rand.nextFloat() * 0.4F,
message.posX + 0.3F + level.random.nextFloat() * 0.4F,
message.posY + 0.15F + level.random.nextFloat() * 0.5F,
message.posZ + 0.3F + level.random.nextFloat() * 0.4F,
0F, 0F, 0F,
0xf4a142, 1F, 30, 0F, false, true);
}),
ANIMAL_GEN_CREATE((message, level) -> {
for (int i = level.rand.nextInt(5) + 5; i >= 0; i--)
for (var i = level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
0xd13308, 1F + level.rand.nextFloat() * 1.5F, 40, 0F, false, true);
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
0xd13308, 1F + level.random.nextFloat() * 1.5F, 40, 0F, false, true);
}),
ANIMAL_GEN_CONSUME((message, level) -> {
boolean child = message.data[0] > 0;
float height = message.data[1] / 10F;
int genX = message.data[2];
int genY = message.data[3];
int genZ = message.data[4];
for (int i = child ? level.rand.nextInt(10) + 10 : level.rand.nextInt(20) + 20; i >= 0; i--)
var child = message.data[0] > 0;
var height = message.data[1] / 10F;
var genX = message.data[2];
var genY = message.data[3];
var genZ = message.data[4];
for (var i = child ? level.random.nextInt(10) + 10 : level.random.nextInt(20) + 20; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextGaussian() * 0.25F,
message.posY + height * 0.75F + level.rand.nextGaussian() * 0.25F,
message.posZ + level.rand.nextGaussian() * 0.25F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.01F,
level.rand.nextGaussian() * 0.01F,
0x42f4c8, level.rand.nextFloat() * (child ? 0.5F : 2F) + 1F, level.rand.nextInt(30) + 40, 0F, true, true);
message.posX + level.random.nextGaussian() * 0.25F,
message.posY + height * 0.75F + level.random.nextGaussian() * 0.25F,
message.posZ + level.random.nextGaussian() * 0.25F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.01F,
level.random.nextGaussian() * 0.01F,
0x42f4c8, level.random.nextFloat() * (child ? 0.5F : 2F) + 1F, level.random.nextInt(30) + 40, 0F, true, true);
NaturesAuraAPI.instance().spawnParticleStream(
message.posX, message.posY + height * 0.75F, message.posZ,
genX + 0.5F, genY + 0.5F, genZ + 0.5F,
0.15F, 0x41c4f4, child ? 1.5F : 3F);
}),
END_FLOWER_DECAY((message, level) -> {
int color = message.data[0];
for (int i = level.rand.nextInt(10) + 20; i >= 0; i--)
var color = message.data[0];
for (var i = level.random.nextInt(10) + 20; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat(),
message.posY + level.rand.nextFloat(),
message.posZ + level.rand.nextFloat(),
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.01F,
level.rand.nextGaussian() * 0.01F,
message.posX + level.random.nextFloat(),
message.posY + level.random.nextFloat(),
message.posZ + level.random.nextFloat(),
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.01F,
level.random.nextGaussian() * 0.01F,
color, 1.5F, 80, 0F, true, true);
}),
ANIMAL_SPAWNER((message, level) -> {
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.5F, message.posZ,
level.rand.nextGaussian() * 0.02F,
level.rand.nextFloat() * 0.02F,
level.rand.nextGaussian() * 0.02F,
level.random.nextGaussian() * 0.02F,
level.random.nextFloat() * 0.02F,
level.random.nextGaussian() * 0.02F,
0x16b7b2, 1.5F, 40, 0F, false, true);
}),
RF_CONVERTER((message, level) -> {
for (int i = level.rand.nextInt(5) + 2; i >= 0; i--)
for (var i = level.random.nextInt(5) + 2; i >= 0; i--)
Multiblocks.RF_CONVERTER.forEach(new BlockPos(message.posX, message.posY, message.posZ), 'R', (blockPos, matcher) -> {
if (level.rand.nextFloat() < 0.35F) {
if (level.random.nextFloat() < 0.35F) {
NaturesAuraAPI.instance().spawnParticleStream(
blockPos.getX() + level.rand.nextFloat(),
blockPos.getY() + level.rand.nextFloat(),
blockPos.getZ() + level.rand.nextFloat(),
message.posX + level.rand.nextFloat(),
message.posY + level.rand.nextFloat(),
message.posZ + level.rand.nextFloat(),
blockPos.getX() + level.random.nextFloat(),
blockPos.getY() + level.random.nextFloat(),
blockPos.getZ() + level.random.nextFloat(),
message.posX + level.random.nextFloat(),
message.posY + level.random.nextFloat(),
message.posZ + level.random.nextFloat(),
0.05F, 0xff1a05, 1.5F);
}
return true;
});
}),
END_FLOWER_CONSUME((message, level) -> {
int color = message.data[0];
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
var color = message.data[0];
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX, message.posY + 0.5F, message.posZ,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.01F,
level.rand.nextGaussian() * 0.01F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.01F,
level.random.nextGaussian() * 0.01F,
color, 1.5F, 40, 0F, false, true);
}),
MOVER_CART((message, level) -> {
float motionX = message.data[0] / 100F;
float motionY = message.data[1] / 100F;
float motionZ = message.data[2] / 100F;
for (int i = level.rand.nextInt(60) + 30; i >= 0; i--)
var motionX = message.data[0] / 100F;
var motionY = message.data[1] / 100F;
var motionZ = message.data[2] / 100F;
for (var i = level.random.nextInt(60) + 30; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextGaussian() * 10F,
message.posY + level.rand.nextGaussian() * 10F,
message.posZ + level.rand.nextGaussian() * 10F,
message.posX + level.random.nextGaussian() * 10F,
message.posY + level.random.nextGaussian() * 10F,
message.posZ + level.random.nextGaussian() * 10F,
motionX * 0.2F, motionY * 0.2F, motionZ * 0.2F,
IAuraType.forLevel(level).getColor(), 2F, 30, 0F, false, true);
}),
MOSS_GENERATOR((message, level) -> {
for (int i = level.rand.nextInt(30) + 30; i >= 0; i--) {
int side = level.rand.nextInt(3);
float x = side != 0 ? level.rand.nextFloat() : level.rand.nextBoolean() ? 1.1F : -0.1F;
float y = side != 1 ? level.rand.nextFloat() : level.rand.nextBoolean() ? 1.1F : -0.1F;
float z = side != 2 ? level.rand.nextFloat() : level.rand.nextBoolean() ? 1.1F : -0.1F;
for (var i = level.random.nextInt(30) + 30; i >= 0; i--) {
var side = level.random.nextInt(3);
var x = side != 0 ? level.random.nextFloat() : level.random.nextBoolean() ? 1.1F : -0.1F;
var y = side != 1 ? level.random.nextFloat() : level.random.nextBoolean() ? 1.1F : -0.1F;
var z = side != 2 ? level.random.nextFloat() : level.random.nextBoolean() ? 1.1F : -0.1F;
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + x,
message.posY + y,
message.posZ + z,
0F, 0F, 0F,
0x184c0d, level.rand.nextFloat() + 1F, 30, 0F, true, true);
0x184c0d, level.random.nextFloat() + 1F, 30, 0F, true, true);
}
for (int i = level.rand.nextInt(20) + 10; i >= 0; i--)
for (var i = level.random.nextInt(20) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat(),
message.posX + level.random.nextFloat(),
message.posY + 1F,
message.posZ + level.rand.nextFloat(),
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.rand.nextFloat() * 1.5F, 40, 0F, true, true);
message.posZ + level.random.nextFloat(),
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.random.nextFloat() * 1.5F, 40, 0F, true, true);
}),
FIREWORK_GEN((message, level) -> {
int goalX = message.data[0];
int goalY = message.data[1];
int goalZ = message.data[2];
var goalX = message.data[0];
var goalY = message.data[1];
var goalZ = message.data[2];
NaturesAuraAPI.instance().setParticleSpawnRange(64);
for (int i = level.rand.nextInt(30) + 30; i >= 0; i--)
for (var i = level.random.nextInt(30) + 30; i >= 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
message.posX + (float) level.rand.nextGaussian(),
message.posY + (float) level.rand.nextGaussian(),
message.posZ + (float) level.rand.nextGaussian(),
goalX + 0.25F + level.rand.nextFloat() * 0.5F,
goalY + 0.25F + level.rand.nextFloat() * 0.5F,
goalZ + 0.25F + level.rand.nextFloat() * 0.5F,
0.65F, message.data[3 + level.rand.nextInt(message.data.length - 3)], 1F);
message.posX + (float) level.random.nextGaussian(),
message.posY + (float) level.random.nextGaussian(),
message.posZ + (float) level.random.nextGaussian(),
goalX + 0.25F + level.random.nextFloat() * 0.5F,
goalY + 0.25F + level.random.nextFloat() * 0.5F,
goalZ + 0.25F + level.random.nextFloat() * 0.5F,
0.65F, message.data[3 + level.random.nextInt(message.data.length - 3)], 1F);
NaturesAuraAPI.instance().setParticleSpawnRange(32);
}),
DIMENSION_RAIL((message, level) -> {
float width = message.data[0] / 100F;
float height = message.data[1] / 100F;
float depth = message.data[2] / 100F;
for (int i = level.rand.nextInt(100) + 50; i >= 0; i--)
var width = message.data[0] / 100F;
var height = message.data[1] / 100F;
var depth = message.data[2] / 100F;
for (var i = level.random.nextInt(100) + 50; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextFloat() * width,
message.posY + level.rand.nextFloat() * height,
message.posZ + level.rand.nextFloat() * depth,
0F, 0F, 0F, 0xd60cff, 1F + level.rand.nextFloat(), 60, 0F, false, true);
message.posX + level.random.nextFloat() * width,
message.posY + level.random.nextFloat() * height,
message.posZ + level.random.nextFloat() * depth,
0F, 0F, 0F, 0xd60cff, 1F + level.random.nextFloat(), 60, 0F, false, true);
}),
PROJECTILE_GEN((message, level) -> {
int x = message.data[0];
int y = message.data[1];
int z = message.data[2];
for (int i = level.rand.nextInt(10) + 5; i >= 0; i--)
var x = message.data[0];
var y = message.data[1];
var z = message.data[2];
for (var i = level.random.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
x + 0.25F + level.rand.nextFloat() * 0.5F,
x + 0.25F + level.random.nextFloat() * 0.5F,
y + 1.01F,
z + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.rand.nextFloat() * 1.5F, 40, 0F, false, true);
for (int i = level.rand.nextInt(10) + 10; i >= 0; i--)
z + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
0x5ccc30, 1F + level.random.nextFloat() * 1.5F, 40, 0F, false, true);
for (var i = level.random.nextInt(10) + 10; i >= 0; i--)
level.addParticle(ParticleTypes.FIREWORK,
message.posX, message.posY, message.posZ,
level.rand.nextGaussian() * 0.03F,
level.rand.nextGaussian() * 0.03F,
level.rand.nextGaussian() * 0.03F);
level.random.nextGaussian() * 0.03F,
level.random.nextGaussian() * 0.03F,
level.random.nextGaussian() * 0.03F);
}),
BLAST_FURNACE_BOOSTER((message, level) -> {
boolean worked = message.data[0] > 0;
for (int i = level.rand.nextInt(10) + 5; i >= 0; i--)
var worked = message.data[0] > 0;
for (var i = level.random.nextInt(10) + 5; i >= 0; i--)
level.addParticle(ParticleTypes.CAMPFIRE_COSY_SMOKE,
message.posX + 5 / 16F + level.rand.nextInt(6) / 16F,
message.posX + 5 / 16F + level.random.nextInt(6) / 16F,
message.posY + 0.6F,
message.posZ + 5 / 16F + level.rand.nextInt(6) / 16F,
level.rand.nextGaussian() * 0.005F,
level.rand.nextFloat() * 0.02F + 0.01F,
level.rand.nextGaussian() * 0.005F);
message.posZ + 5 / 16F + level.random.nextInt(6) / 16F,
level.random.nextGaussian() * 0.005F,
level.random.nextFloat() * 0.02F + 0.01F,
level.random.nextGaussian() * 0.005F);
if (worked) {
BlockPos pos = new BlockPos(message.posX, message.posY, message.posZ);
int color = IAuraChunk.getAuraChunk(level, pos).getType().getColor();
for (int i = level.rand.nextInt(10) + 10; i >= 0; i--)
var pos = new BlockPos(message.posX, message.posY, message.posZ);
var color = IAuraChunk.getAuraChunk(level, pos).getType().getColor();
for (var i = level.random.nextInt(10) + 10; i >= 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
message.posX + (float) level.rand.nextGaussian() * 5,
message.posY + level.rand.nextFloat() * 5,
message.posZ + (float) level.rand.nextGaussian() * 5,
message.posX + (float) level.random.nextGaussian() * 5,
message.posY + level.random.nextFloat() * 5,
message.posZ + (float) level.random.nextGaussian() * 5,
message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F,
0.25F, color, 0.5F + level.rand.nextFloat()
0.25F, color, 0.5F + level.random.nextFloat()
);
}
}),
ANIMAL_CONTAINER((message, level) -> {
for (int i = level.rand.nextInt(2) + 1; i > 0; i--)
for (var i = level.random.nextInt(2) + 1; i > 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + level.rand.nextGaussian() * 0.15F,
message.posY - level.rand.nextFloat() * 0.5F,
message.posZ + level.rand.nextGaussian() * 0.15F,
0, 0, 0, 0x42e9f5, 1 + level.rand.nextFloat() * 2, 40, 0, false, true
message.posX + level.random.nextGaussian() * 0.15F,
message.posY - level.random.nextFloat() * 0.5F,
message.posZ + level.random.nextGaussian() * 0.15F,
0, 0, 0, 0x42e9f5, 1 + level.random.nextFloat() * 2, 40, 0, false, true
);
}),
SNOW_CREATOR((message, level) -> {
BlockPos pos = new BlockPos(message.posX, message.posY, message.posZ);
int color = IAuraChunk.getAuraChunk(level, pos).getType().getColor();
for (int i = level.rand.nextInt(3) + 1; i > 0; i--)
var pos = new BlockPos(message.posX, message.posY, message.posZ);
var color = IAuraChunk.getAuraChunk(level, pos).getType().getColor();
for (var i = level.random.nextInt(3) + 1; i > 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
message.posX + (float) level.rand.nextGaussian() * 5,
message.posY + level.rand.nextFloat() * 5,
message.posZ + (float) level.rand.nextGaussian() * 5,
message.posX + (float) level.random.nextGaussian() * 5,
message.posY + level.random.nextFloat() * 5,
message.posZ + (float) level.random.nextGaussian() * 5,
message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F,
0.25F, color, 0.5F + level.rand.nextFloat()
0.25F, color, 0.5F + level.random.nextFloat()
);
}),
CHORUS_GENERATOR((message, level) -> {
int chorusX = message.data[0];
int chorusY = message.data[1];
int chorusZ = message.data[2];
for (int i = level.rand.nextInt(5) + 3; i >= 0; i--)
var chorusX = message.data[0];
var chorusY = message.data[1];
var chorusZ = message.data[2];
for (var i = level.random.nextInt(5) + 3; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
chorusX + level.rand.nextFloat(), chorusY + level.rand.nextFloat(), chorusZ + level.rand.nextFloat(),
chorusX + level.random.nextFloat(), chorusY + level.random.nextFloat(), chorusZ + level.random.nextFloat(),
0F, 0F, 0F,
0xbb0be3, 1F + level.rand.nextFloat(), 50, 0F, false, true);
for (int i = level.rand.nextInt(5) + 5; i >= 0; i--)
0xbb0be3, 1F + level.random.nextFloat(), 50, 0F, false, true);
for (var i = level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
IAuraType.forLevel(level).getColor(), 1F + level.rand.nextFloat() * 1.5F, 40, 0F, false, true);
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
IAuraType.forLevel(level).getColor(), 1F + level.random.nextFloat() * 1.5F, 40, 0F, false, true);
}),
TIMER_RESET((message, level) -> {
int color = message.data[0];
for (int i = level.rand.nextInt(10) + 15; i >= 0; i--)
var color = message.data[0];
for (var i = level.random.nextInt(10) + 15; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 5 / 16F + level.rand.nextFloat() * 6 / 16F,
message.posY + 2 / 16F + level.rand.nextFloat() * 8 / 16F,
message.posZ + 5 / 16F + level.rand.nextFloat() * 6 / 16F,
0, 0, 0, color, 2, 40 + level.rand.nextInt(20), 0, false, true);
message.posX + 5 / 16F + level.random.nextFloat() * 6 / 16F,
message.posY + 2 / 16F + level.random.nextFloat() * 8 / 16F,
message.posZ + 5 / 16F + level.random.nextFloat() * 6 / 16F,
0, 0, 0, color, 2, 40 + level.random.nextInt(20), 0, false, true);
}),
STRUCTURE_FINDER((message, level) -> {
EntityStructureFinder entity = (EntityStructureFinder) level.getEntityByID(message.data[0]);
LevelRenderer renderer = Minecraft.getInstance().levelRenderer;
var entity = (EntityStructureFinder) level.getEntity(message.data[0]);
var renderer = Minecraft.getInstance().levelRenderer;
double d0 = message.posX + 0.5D;
var d0 = message.posX + 0.5D;
double d13 = message.posY;
double d18 = message.posZ + 0.5D;
for (int j2 = 0; j2 < 8; ++j2)
renderer.addParticle(new ItemParticleData(ParticleTypes.ITEM, entity.getItem()), false, d0, d13, d18, level.rand.nextGaussian() * 0.15D, level.rand.nextDouble() * 0.2D, level.rand.nextGaussian() * 0.15D);
var d18 = message.posZ + 0.5D;
for (var j2 = 0; j2 < 8; ++j2)
renderer.addParticle(new ItemParticleOption(ParticleTypes.ITEM, entity.getItem()), false, d0, d13, d18, level.random.nextGaussian() * 0.15D, level.random.nextDouble() * 0.2D, level.random.nextGaussian() * 0.15D);
int color = entity.getDataManager().get(EntityStructureFinder.COLOR);
for (double d24 = 0.0D; d24 < (Math.PI * 2D); d24 += 0.15707963267948966D) {
int color = entity.getEntityData().get(EntityStructureFinder.COLOR);
for (var d24 = 0.0D; d24 < (Math.PI * 2D); d24 += 0.15707963267948966D) {
NaturesAuraAPI.instance().spawnMagicParticle(d0 + Math.cos(d24) * 5.0D, d13 - 0.4D, d18 + Math.sin(d24) * 5.0D, Math.cos(d24) * -2, 0.0D, Math.sin(d24) * -2, color, 2, 60, 0, false, true);
NaturesAuraAPI.instance().spawnMagicParticle(d0 + Math.cos(d24) * 5.0D, d13 - 0.4D, d18 + Math.sin(d24) * 5.0D, Math.cos(d24) * -2.5, 0.0D, Math.sin(d24) * -2.5, color, 2, 60, 0, false, true);
}
}),
SLIME_SPLIT_GEN_CREATE((message, level) -> {
for (int i = level.rand.nextInt(5) + 5; i >= 0; i--)
for (var i = level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + 0.25F + level.rand.nextFloat() * 0.5F,
message.posX + 0.25F + level.random.nextFloat() * 0.5F,
message.posY + 1.01F,
message.posZ + 0.25F + level.rand.nextFloat() * 0.5F,
level.rand.nextGaussian() * 0.01F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.01F,
message.data[0], 1F + level.rand.nextFloat() * 1.5F, 40, 0F, false, true);
message.posZ + 0.25F + level.random.nextFloat() * 0.5F,
level.random.nextGaussian() * 0.01F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.01F,
message.data[0], 1F + level.random.nextFloat() * 1.5F, 40, 0F, false, true);
}),
SLIME_SPLIT_GEN_START((message, level) -> {
int x = message.data[0];
int y = message.data[1];
int z = message.data[2];
int color = message.data[3];
for (int i = level.rand.nextInt(10) + 5; i >= 0; i--)
var x = message.data[0];
var y = message.data[1];
var z = message.data[2];
var color = message.data[3];
for (var i = level.random.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + (float) level.rand.nextGaussian() * 0.5F,
message.posY + (float) level.rand.nextGaussian() * 0.5F,
message.posZ + (float) level.rand.nextGaussian() * 0.5F,
level.rand.nextGaussian() * 0.02F,
level.rand.nextFloat() * 0.04F + 0.02F,
level.rand.nextGaussian() * 0.02F,
color, level.rand.nextFloat() + 1, level.rand.nextInt(20) + 20, 0, false, true);
for (int i = level.rand.nextInt(10) + 5; i >= 0; i--)
message.posX + (float) level.random.nextGaussian() * 0.5F,
message.posY + (float) level.random.nextGaussian() * 0.5F,
message.posZ + (float) level.random.nextGaussian() * 0.5F,
level.random.nextGaussian() * 0.02F,
level.random.nextFloat() * 0.04F + 0.02F,
level.random.nextGaussian() * 0.02F,
color, level.random.nextFloat() + 1, level.random.nextInt(20) + 20, 0, false, true);
for (var i = level.random.nextInt(10) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnParticleStream(
message.posX + (float) level.rand.nextGaussian() * 0.5F,
message.posY + (float) level.rand.nextGaussian() * 0.5F,
message.posZ + (float) level.rand.nextGaussian() * 0.5F,
x + 0.5F, y + 0.5F, z + 0.5F, 0.2F, color, level.rand.nextFloat() + 1);
message.posX + (float) level.random.nextGaussian() * 0.5F,
message.posY + (float) level.random.nextGaussian() * 0.5F,
message.posZ + (float) level.random.nextGaussian() * 0.5F,
x + 0.5F, y + 0.5F, z + 0.5F, 0.2F, color, level.random.nextFloat() + 1);
}),
PET_REVIVER((message, level) -> {
for (int i = level.rand.nextInt(50) + 150; i >= 0; i--)
for (var i = level.random.nextInt(50) + 150; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle(
message.posX + (float) level.rand.nextGaussian() * 0.4F,
message.posY + (float) level.rand.nextGaussian() * 0.4F,
message.posZ + (float) level.rand.nextGaussian() * 0.4F,
level.rand.nextGaussian() * 0.002F,
level.rand.nextFloat() * 0.001F + 0.002F,
level.rand.nextGaussian() * 0.002F,
message.data[0], level.rand.nextFloat() * 2 + 1, level.rand.nextInt(50) + 50, 0, false, true);
message.posX + (float) level.random.nextGaussian() * 0.4F,
message.posY + (float) level.random.nextGaussian() * 0.4F,
message.posZ + (float) level.random.nextGaussian() * 0.4F,
level.random.nextGaussian() * 0.002F,
level.random.nextFloat() * 0.001F + 0.002F,
level.random.nextGaussian() * 0.002F,
message.data[0], level.random.nextFloat() * 2 + 1, level.random.nextInt(50) + 50, 0, false, true);
});
public final BiConsumer<PacketParticles, Level> action;

View file

@ -17,7 +17,6 @@ import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.EntityRenderers;
@ -84,12 +83,6 @@ public class ClientProxy implements IProxy {
Minecraft.getInstance().getBlockColors().register(block.getBlockColor(), (Block) block);
}
@Override
public void registerTESR(ITESRProvider<?> provider) {
var tesr = provider.getTESR();
BlockEntityRenderers.register(tesr.getA(), tesr.getB().get());
}
@Override
public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) {
ParticleHandler.spawnParticle(() -> new ParticleMagic(Minecraft.getInstance().level,

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@ -22,8 +21,6 @@ public interface IProxy {
void addColorProvidingBlock(IColorProvidingBlock block);
void registerTESR(ITESRProvider<?> provider);
void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade);
void setParticleDepth(boolean depth);

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.proxy;
import de.ellpeck.naturesaura.reg.IColorProvidingBlock;
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ITESRProvider;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@ -37,11 +36,6 @@ public class ServerProxy implements IProxy {
}
@Override
public void registerTESR(ITESRProvider<?> provider) {
}
@Override
public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) {

View file

@ -1,16 +1,11 @@
package de.ellpeck.naturesaura.reg;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.util.Tuple;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.function.Supplier;
public interface ITESRProvider<T extends BlockEntity> {
@OnlyIn(Dist.CLIENT)
Tuple<BlockEntityType<? extends T>, Supplier<BlockEntityRendererProvider<T>>> getTESR();
void registerTESR();
}

View file

@ -334,7 +334,7 @@ public final class ModRegistry {
if (item instanceof IColorProvidingItem)
NaturesAura.proxy.addColorProvidingItem((IColorProvidingItem) item);
if (item instanceof ITESRProvider provider)
NaturesAura.proxy.registerTESR(provider);
provider.registerTESR();
}
// register features again for some reason

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