mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 03:43:30 +01:00
a bunch more work, ugh
This commit is contained in:
parent
78eaf11948
commit
559c4165e8
44 changed files with 724 additions and 790 deletions
|
@ -108,7 +108,7 @@ dependencies {
|
|||
/* compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75:api")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.1.75")*/
|
||||
|
||||
// TDOO Patchouli
|
||||
// TODO Patchouli
|
||||
/* compileOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50:api")
|
||||
runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:1.16.4-50")*/
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ import de.ellpeck.naturesaura.api.misc.ILevelData;
|
|||
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
|
||||
import de.ellpeck.naturesaura.blocks.multi.Multiblock;
|
||||
import de.ellpeck.naturesaura.misc.LevelData;
|
||||
import net.minecraft.entity.player.Player;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.level.Level;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.apache.commons.lang3.mutable.MutableFloat;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
|
@ -59,7 +59,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
|
||||
@Override
|
||||
public void spawnParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
|
||||
Vector3d dir = new Vector3d(endX - startX, endY - startY, endZ - startZ);
|
||||
Vec3 dir = new Vec3(endX - startX, endY - startY, endZ - startZ);
|
||||
double length = dir.length();
|
||||
if (length > 0) {
|
||||
dir = dir.normalize();
|
||||
|
@ -90,9 +90,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Tuple<Vector3d, Integer>> getActiveEffectPowders(Level level, AxisAlignedBB area, ResourceLocation name) {
|
||||
List<Tuple<Vector3d, Integer>> found = new ArrayList<>();
|
||||
for (Tuple<Vector3d, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name))
|
||||
public List<Tuple<Vec3, Integer>> getActiveEffectPowders(Level level, AABB area, ResourceLocation name) {
|
||||
List<Tuple<Vec3, Integer>> found = new ArrayList<>();
|
||||
for (Tuple<Vec3, Integer> powder : ((LevelData) ILevelData.getLevelData(level)).effectPowders.get(name))
|
||||
if (area.contains(powder.getA()))
|
||||
found.add(powder);
|
||||
return found;
|
||||
|
@ -100,10 +100,10 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
|
||||
@Override
|
||||
public boolean isEffectPowderActive(Level level, BlockPos pos, ResourceLocation name) {
|
||||
Vector3d posVec = new Vector3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
List<Tuple<Vector3d, Integer>> powders = this.getActiveEffectPowders(level, new AxisAlignedBB(pos).grow(64), name);
|
||||
for (Tuple<Vector3d, Integer> powder : powders) {
|
||||
AxisAlignedBB bounds = Helper.aabb(powder.getA()).grow(powder.getB());
|
||||
Vec3 posVec = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
List<Tuple<Vec3, Integer>> powders = this.getActiveEffectPowders(level, new AABB(pos).inflate(64), name);
|
||||
for (Tuple<Vec3, Integer> powder : powders) {
|
||||
AABB bounds = Helper.aabb(powder.getA()).inflate(powder.getB());
|
||||
if (bounds.contains(posVec))
|
||||
return true;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
|||
public int triangulateAuraInArea(Level level, BlockPos pos, int radius) {
|
||||
MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA);
|
||||
IAuraChunk.getSpotsInArea(level, pos, radius, (blockPos, spot) -> {
|
||||
float percentage = 1F - (float) Math.sqrt(pos.distanceSq(blockPos)) / radius;
|
||||
float percentage = 1F - (float) Math.sqrt(pos.distSqr(blockPos)) / radius;
|
||||
result.add(spot * percentage);
|
||||
});
|
||||
return result.intValue();
|
||||
|
|
|
@ -4,8 +4,8 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|||
import de.ellpeck.naturesaura.api.aura.type.BasicAuraType;
|
||||
import de.ellpeck.naturesaura.api.misc.WeightedOre;
|
||||
import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package de.ellpeck.naturesaura.api.aura.container;
|
||||
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class ItemAuraContainer implements IAuraContainer {
|
||||
|
||||
|
|
|
@ -7,15 +7,7 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class Matcher {
|
||||
|
||||
private final BlockState defaultState;
|
||||
private final ICheck check;
|
||||
|
||||
public Matcher(BlockState defaultState, ICheck check) {
|
||||
this.defaultState = defaultState;
|
||||
this.check = check;
|
||||
}
|
||||
public record Matcher(BlockState defaultState, ICheck check) {
|
||||
|
||||
public static Matcher wildcard() {
|
||||
return new Matcher(Blocks.AIR.defaultBlockState(), null);
|
||||
|
@ -25,14 +17,6 @@ public class Matcher {
|
|||
return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName()));
|
||||
}
|
||||
|
||||
public BlockState getDefaultState() {
|
||||
return this.defaultState;
|
||||
}
|
||||
|
||||
public ICheck getCheck() {
|
||||
return this.check;
|
||||
}
|
||||
|
||||
public interface ICheck {
|
||||
|
||||
boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);
|
||||
|
|
|
@ -5,17 +5,18 @@ import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAncientLeaves;
|
|||
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
||||
import de.ellpeck.naturesaura.reg.*;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.LeavesBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.material.MaterialColor;
|
||||
import net.minecraft.client.renderer.color.IBlockColor;
|
||||
import net.minecraft.client.renderer.color.IItemColor;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.level.IBlockReader;
|
||||
import net.minecraft.level.Level;
|
||||
import net.minecraft.level.server.ServerLevel;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.LeavesBlock;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
|
@ -25,7 +26,7 @@ import java.util.Random;
|
|||
public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorProvidingBlock, IColorProvidingItem, ICustomBlockState {
|
||||
|
||||
public BlockAncientLeaves() {
|
||||
super(Properties.create(Material.LEAVES, MaterialColor.PINK).hardnessAndResistance(0.2F).tickRandomly().notSolid().sound(SoundType.PLANT));
|
||||
super(Block.Properties.of(Material.LEAVES, MaterialColor.COLOR_PINK).strength(0.2F).randomTicks().noOcclusion().sound(SoundType.GRASS));
|
||||
ModRegistry.add(this);
|
||||
ModRegistry.add(new ModTileType<>(BlockEntityAncientLeaves::new, this));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|||
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
|
||||
import de.ellpeck.naturesaura.api.multiblock.Matcher;
|
||||
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.level.Level;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -80,13 +80,11 @@ public class Multiblock implements IMultiblock {
|
|||
continue;
|
||||
|
||||
Object value = rawMatchers[i + 1];
|
||||
if (value instanceof BlockState) {
|
||||
BlockState state = (BlockState) value;
|
||||
if (value instanceof BlockState state) {
|
||||
matchers.put(c, new Matcher(state,
|
||||
(level, start, offset, pos, other, otherC) -> other == state));
|
||||
} else if (value instanceof Block) {
|
||||
Block block = (Block) value;
|
||||
matchers.put(c, new Matcher(block.getDefaultState(),
|
||||
} else if (value instanceof Block block) {
|
||||
matchers.put(c, new Matcher(block.defaultBlockState(),
|
||||
(level, start, offset, pos, state, otherC) -> state.getBlock() == block));
|
||||
} else
|
||||
matchers.put(c, (Matcher) value);
|
||||
|
@ -121,7 +119,7 @@ public class Multiblock implements IMultiblock {
|
|||
for (Map.Entry<BlockPos, Matcher> entry : this.matchers.entrySet()) {
|
||||
BlockPos offset = entry.getKey();
|
||||
if (c == 0 || this.getChar(offset) == c)
|
||||
if (!function.apply(start.add(offset), entry.getValue()))
|
||||
if (!function.apply(start.offset(offset), entry.getValue()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -129,7 +127,7 @@ public class Multiblock implements IMultiblock {
|
|||
|
||||
@Override
|
||||
public BlockPos getStart(BlockPos center) {
|
||||
return center.add(-this.xOffset, -this.yOffset, -this.zOffset);
|
||||
return center.offset(-this.xOffset, -this.yOffset, -this.zOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer;
|
||||
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.EntityPredicates;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -46,8 +45,8 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
|
|||
|
||||
public boolean isDrainMode;
|
||||
|
||||
public BlockEntityEndFlower() {
|
||||
super(ModTileEntities.END_FLOWER);
|
||||
public BlockEntityEndFlower(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.END_FLOWER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,10 +56,9 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
|
|||
return;
|
||||
|
||||
if (!this.isDrainMode) {
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
|
||||
new AxisAlignedBB(this.worldPosition).grow(1), EntityPredicates.IS_ALIVE);
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
|
||||
for (ItemEntity item : items) {
|
||||
if (item.cannotPickup())
|
||||
if (item.hasPickUpDelay())
|
||||
continue;
|
||||
ItemStack stack = item.getItem();
|
||||
if (stack.getCount() != 1)
|
||||
|
@ -69,10 +67,10 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
|
|||
continue;
|
||||
|
||||
this.isDrainMode = true;
|
||||
item.remove();
|
||||
item.kill();
|
||||
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
|
||||
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor()));
|
||||
new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.END_FLOWER_CONSUME, this.container.getAuraColor()));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -81,7 +79,7 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
|
|||
this.generateAura(toDrain);
|
||||
|
||||
if (this.container.getStoredAura() <= 0) {
|
||||
this.level.setBlockState(this.worldPosition, Blocks.DEAD_BUSH.getDefaultState());
|
||||
this.level.setBlockAndUpdate(this.worldPosition, Blocks.DEAD_BUSH.defaultBlockState());
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
|
||||
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.END_FLOWER_DECAY, this.container.getAuraColor()));
|
||||
}
|
||||
|
@ -89,13 +87,13 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
|
|||
} else {
|
||||
if (this.isDrainMode && this.level.getGameTime() % 5 == 0)
|
||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.level.rand.nextGaussian() * 0.05F,
|
||||
this.level.rand.nextFloat() * 0.1F,
|
||||
this.level.rand.nextGaussian() * 0.05F,
|
||||
this.container.getAuraColor(), this.level.rand.nextFloat() * 2F + 1F, 50, 0F, false, true);
|
||||
this.worldPosition.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.worldPosition.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.worldPosition.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.level.random.nextGaussian() * 0.05F,
|
||||
this.level.random.nextFloat() * 0.1F,
|
||||
this.level.random.nextGaussian() * 0.05F,
|
||||
this.container.getAuraColor(), this.level.random.nextFloat() * 2F + 1F, 50, 0F, false, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,19 +6,15 @@ 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.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.player.Player;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.inventory.MenuConstructor;
|
||||
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.level.block.state.BlockState;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
@ -143,13 +139,13 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
|
|||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".ender_crate", TextFormatting.ITALIC + this.name + TextFormatting.RESET);
|
||||
public Component getDisplayName() {
|
||||
return new TranslatableComponent("info." + NaturesAura.MOD_ID + ".ender_crate", ChatFormatting.ITALIC + this.name + ChatFormatting.RESET);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container createMenu(int window, PlayerInventory inv, Player player) {
|
||||
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
|
||||
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler());
|
||||
}
|
||||
}
|
|
@ -6,24 +6,23 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticleStream;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.level.server.ServerLevel;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -34,8 +33,8 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
public boolean isCharged;
|
||||
private int chargeTimer;
|
||||
|
||||
public BlockEntityFieldCreator() {
|
||||
super(ModTileEntities.FIELD_CREATOR);
|
||||
public BlockEntityFieldCreator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.FIELD_CREATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +43,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
return;
|
||||
|
||||
BlockPos connectedPos = this.getConnectedPos();
|
||||
if (connectedPos == null || !this.level.isBlockLoaded(connectedPos))
|
||||
if (connectedPos == null || !this.level.isLoaded(connectedPos))
|
||||
return;
|
||||
|
||||
BlockEntity other = this.level.getBlockEntity(connectedPos);
|
||||
|
@ -95,16 +94,16 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
chunk.drainAura(spot, 20);
|
||||
|
||||
ItemStack tool = this.getToolUsed(creator);
|
||||
Vector3d dist = new Vector3d(
|
||||
Vec3 dist = new Vec3(
|
||||
this.worldPosition.getX() - connectedPos.getX(),
|
||||
this.worldPosition.getY() - connectedPos.getY(),
|
||||
this.worldPosition.getZ() - connectedPos.getZ()
|
||||
);
|
||||
double length = dist.length();
|
||||
Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length);
|
||||
Vec3 normal = new Vec3(dist.x / length, dist.y / length, dist.z / length);
|
||||
for (float i = Mth.floor(length); i > 0; i -= 0.5F) {
|
||||
Vector3d scaled = normal.scale(i);
|
||||
BlockPos pos = connectedPos.add(
|
||||
Vec3 scaled = normal.scale(i);
|
||||
BlockPos pos = connectedPos.offset(
|
||||
Mth.floor(scaled.x + 0.5F),
|
||||
Mth.floor(scaled.y + 0.5F),
|
||||
Mth.floor(scaled.z + 0.5F));
|
||||
|
@ -114,18 +113,18 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
|
||||
BlockState state = this.level.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if (!block.isAir(state, this.level, pos) && state.getBlockHardness(this.level, pos) >= 0F) {
|
||||
if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) {
|
||||
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
|
||||
if (!MinecraftForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) {
|
||||
List<ItemStack> drops = state.getDrops(new LootContext.Builder((ServerLevel) this.level)
|
||||
.withParameter(LootParameters.THIS_ENTITY, fake)
|
||||
.withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(pos))
|
||||
.withParameter(LootParameters.BLOCK_STATE, state)
|
||||
.withParameter(LootParameters.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool)
|
||||
.withNullableParameter(LootParameters.BLOCK_ENTITY, this.level.getBlockEntity(pos)));
|
||||
.withParameter(LootContextParams.THIS_ENTITY, fake)
|
||||
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
|
||||
.withParameter(LootContextParams.BLOCK_STATE, state)
|
||||
.withParameter(LootContextParams.TOOL, tool.isEmpty() ? new ItemStack(Items.DIAMOND_PICKAXE) : tool)
|
||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, this.level.getBlockEntity(pos)));
|
||||
this.level.destroyBlock(pos, false);
|
||||
for (ItemStack stack : drops)
|
||||
Block.spawnAsEntity(this.level, pos, stack);
|
||||
Block.popResource(this.level, pos, stack);
|
||||
chunk.drainAura(spot, !tool.isEmpty() ? 300 : 100);
|
||||
this.sendParticles();
|
||||
}
|
||||
|
@ -140,16 +139,16 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
if (!myTool.isEmpty()) {
|
||||
// if both have tools, choose randomly
|
||||
if (!otherTool.isEmpty())
|
||||
return this.level.rand.nextBoolean() ? myTool : otherTool;
|
||||
return this.level.random.nextBoolean() ? myTool : otherTool;
|
||||
return myTool;
|
||||
}
|
||||
return otherTool;
|
||||
}
|
||||
|
||||
private ItemStack getMyTool() {
|
||||
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
for (ItemFrameEntity frame : frames) {
|
||||
ItemStack stack = frame.getDisplayedItem();
|
||||
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
for (ItemFrame frame : frames) {
|
||||
ItemStack stack = frame.getItem();
|
||||
if (!stack.isEmpty())
|
||||
return stack;
|
||||
}
|
||||
|
@ -160,26 +159,26 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
for (int j = 0; j < 2; j++) {
|
||||
BlockPos p = j == 0 ? this.worldPosition : this.getConnectedPos();
|
||||
PacketHandler.sendToAllAround(this.level, p, 32, new PacketParticleStream(
|
||||
p.getX() + (float) this.level.rand.nextGaussian() * 3F,
|
||||
p.getY() + 1 + this.level.rand.nextFloat() * 3F,
|
||||
p.getZ() + (float) this.level.rand.nextGaussian() * 3F,
|
||||
p.getX() + (float) this.level.random.nextGaussian() * 3F,
|
||||
p.getY() + 1 + this.level.random.nextFloat() * 3F,
|
||||
p.getZ() + (float) this.level.random.nextGaussian() * 3F,
|
||||
p.getX() + 0.5F,
|
||||
p.getY() + 0.5F,
|
||||
p.getZ() + 0.5F,
|
||||
this.level.rand.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.rand.nextFloat() + 0.5F
|
||||
this.level.random.nextFloat() * 0.07F + 0.07F, IAuraType.forLevel(this.level).getColor(), this.level.random.nextFloat() + 0.5F
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCloseEnough(BlockPos pos) {
|
||||
int range = ModConfig.instance.fieldCreatorRange.get() + 1;
|
||||
return this.worldPosition.distanceSq(pos) <= range * range;
|
||||
return this.worldPosition.distSqr(pos) <= range * range;
|
||||
}
|
||||
|
||||
public BlockPos getConnectedPos() {
|
||||
if (this.connectionOffset == null)
|
||||
return null;
|
||||
return this.worldPosition.add(this.connectionOffset);
|
||||
return this.worldPosition.offset(this.connectionOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,7 +186,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
super.writeNBT(compound, type);
|
||||
if (type != SaveType.BLOCK) {
|
||||
if (this.connectionOffset != null)
|
||||
compound.putLong("connection", this.connectionOffset.toLong());
|
||||
compound.putLong("connection", this.connectionOffset.asLong());
|
||||
compound.putBoolean("main", this.isMain);
|
||||
compound.putBoolean("charged", this.isCharged);
|
||||
|
||||
|
@ -201,7 +200,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
|
|||
super.readNBT(compound, type);
|
||||
if (type != SaveType.BLOCK) {
|
||||
if (compound.contains("connection"))
|
||||
this.connectionOffset = BlockPos.fromLong(compound.getLong("connection"));
|
||||
this.connectionOffset = BlockPos.of(compound.getLong("connection"));
|
||||
else
|
||||
this.connectionOffset = null;
|
||||
this.isMain = compound.getBoolean("main");
|
|
@ -1,21 +1,20 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.projectile.FireworkRocketEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.EntityPredicates;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -29,33 +28,33 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
private int toRelease;
|
||||
private int releaseTimer;
|
||||
|
||||
public BlockEntityFireworkGenerator() {
|
||||
super(ModTileEntities.FIREWORK_GENERATOR);
|
||||
public BlockEntityFireworkGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.FIREWORK_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!this.level.isClientSide) {
|
||||
if (this.level.getGameTime() % 10 == 0) {
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
|
||||
new AxisAlignedBB(this.worldPosition).grow(4), EntityPredicates.IS_ALIVE);
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(4), Entity::isAlive);
|
||||
for (ItemEntity item : items) {
|
||||
if (item.cannotPickup())
|
||||
if (item.hasPickUpDelay())
|
||||
continue;
|
||||
ItemStack stack = item.getItem();
|
||||
if (stack.isEmpty() || stack.getItem() != Items.FIREWORK_ROCKET)
|
||||
continue;
|
||||
if (this.trackedEntity == null && this.releaseTimer <= 0) {
|
||||
FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getPosX(), item.getPosY(), item.getPosZ(), stack);
|
||||
FireworkRocketEntity entity = new FireworkRocketEntity(this.level, item.getX(), item.getY(), item.getZ(), stack);
|
||||
this.trackedEntity = entity;
|
||||
this.trackedItem = stack.copy();
|
||||
this.level.addEntity(entity);
|
||||
this.level.addFreshEntity(entity);
|
||||
}
|
||||
stack.shrink(1);
|
||||
if (stack.isEmpty())
|
||||
item.remove();
|
||||
else
|
||||
if (stack.isEmpty()) {
|
||||
item.kill();
|
||||
} else {
|
||||
item.setItem(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,11 +67,11 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
CompoundTag fireworks = compound.getCompound("Fireworks");
|
||||
|
||||
int flightTime = fireworks.getInt("Flight");
|
||||
ListNBT explosions = fireworks.getList("Explosions", 10);
|
||||
ListTag explosions = fireworks.getList("Explosions", 10);
|
||||
if (!explosions.isEmpty()) {
|
||||
generateFactor += flightTime;
|
||||
|
||||
for (INBT base : explosions) {
|
||||
for (Tag base : explosions) {
|
||||
CompoundTag explosion = (CompoundTag) base;
|
||||
generateFactor += 1.5F;
|
||||
|
||||
|
@ -109,7 +108,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
data.add(this.worldPosition.getZ());
|
||||
data.addAll(usedColors);
|
||||
PacketHandler.sendToAllLoaded(this.level, this.worldPosition, new PacketParticles(
|
||||
(float) this.trackedEntity.getPosX(), (float) this.trackedEntity.getPosY(), (float) this.trackedEntity.getPosZ(),
|
||||
(float) this.trackedEntity.getX(), (float) this.trackedEntity.getY(), (float) this.trackedEntity.getZ(),
|
||||
PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
|
||||
|
||||
public BlockEntityGeneratorLimitRemover(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.GENERATOR_LIMIT_REMOVER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public AABB getRenderBoundingBox() {
|
||||
return new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1));
|
||||
}
|
||||
}
|
|
@ -2,15 +2,15 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.blocks.BlockGratedChute;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
@ -33,8 +33,8 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
|
|||
};
|
||||
private int cooldown;
|
||||
|
||||
public BlockEntityGratedChute() {
|
||||
super(ModTileEntities.GRATED_CHUTE);
|
||||
public BlockEntityGratedChute(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.GRATED_CHUTE, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,8 +49,8 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
|
|||
push:
|
||||
if (!curr.isEmpty()) {
|
||||
BlockState state = this.level.getBlockState(this.worldPosition);
|
||||
Direction facing = state.get(BlockGratedChute.FACING);
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing));
|
||||
Direction facing = state.getValue(BlockGratedChute.FACING);
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
|
||||
if (tile == null)
|
||||
break push;
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
|
||||
|
@ -70,7 +70,7 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
|
|||
}
|
||||
pull:
|
||||
if (curr.isEmpty() || curr.getCount() < curr.getMaxStackSize()) {
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(
|
||||
this.worldPosition.getX(), this.worldPosition.getY() + 0.5, this.worldPosition.getZ(),
|
||||
this.worldPosition.getX() + 1, this.worldPosition.getY() + 2, this.worldPosition.getZ() + 1));
|
||||
for (ItemEntity item : items) {
|
||||
|
@ -80,16 +80,17 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
|
|||
if (stack.isEmpty())
|
||||
continue;
|
||||
ItemStack left = this.items.insertItem(0, stack, false);
|
||||
if (!ItemStack.areItemStacksEqual(stack, left)) {
|
||||
if (left.isEmpty())
|
||||
item.remove();
|
||||
else
|
||||
if (!ItemStack.isSame(stack, left)) {
|
||||
if (left.isEmpty()) {
|
||||
item.kill();
|
||||
} else {
|
||||
item.setItem(left);
|
||||
}
|
||||
break pull;
|
||||
}
|
||||
}
|
||||
|
||||
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.up());
|
||||
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.above());
|
||||
if (tileUp == null)
|
||||
break pull;
|
||||
IItemHandler handlerUp = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
|
||||
|
@ -112,11 +113,11 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
|
|||
}
|
||||
|
||||
private boolean isItemInFrame(ItemStack stack) {
|
||||
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
if (frames.isEmpty())
|
||||
return false;
|
||||
for (ItemFrameEntity frame : frames) {
|
||||
ItemStack frameStack = frame.getDisplayedItem();
|
||||
for (ItemFrame frame : frames) {
|
||||
ItemStack frameStack = frame.getItem();
|
||||
if (Helper.areItemsEqual(stack, frameStack, true)) {
|
||||
return true;
|
||||
}
|
|
@ -1,23 +1,21 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
||||
import de.ellpeck.naturesaura.misc.LevelData;
|
||||
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.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
public BlockEntityMossGenerator() {
|
||||
super(ModTileEntities.MOSS_GENERATOR);
|
||||
public BlockEntityMossGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.MOSS_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +30,7 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
|
|||
for (int x = -range; x <= range; x++)
|
||||
for (int y = -range; y <= range; y++)
|
||||
for (int z = -range; z <= range; z++) {
|
||||
BlockPos offset = this.worldPosition.add(x, y, z);
|
||||
BlockPos offset = this.worldPosition.offset(x, y, z);
|
||||
boolean isRecent = data.recentlyConvertedMossStones.contains(offset);
|
||||
BlockState state = this.level.getBlockState(offset);
|
||||
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().containsKey(state)) {
|
||||
|
@ -46,7 +44,7 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
|
|||
|
||||
if (possibleOffsets.isEmpty())
|
||||
return;
|
||||
BlockPos offset = possibleOffsets.get(this.level.rand.nextInt(possibleOffsets.size()));
|
||||
BlockPos offset = possibleOffsets.get(this.level.random.nextInt(possibleOffsets.size()));
|
||||
BlockState state = this.level.getBlockState(offset);
|
||||
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.inverse().get(state);
|
||||
|
||||
|
@ -57,8 +55,8 @@ public class BlockEntityMossGenerator extends BlockEntityImpl implements ITickab
|
|||
new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.MOSS_GENERATOR));
|
||||
}
|
||||
|
||||
this.level.playEvent(2001, offset, Block.getStateId(state));
|
||||
this.level.setBlockState(offset, result);
|
||||
this.level.levelEvent(2001, offset, Block.getId(state));
|
||||
this.level.setBlockAndUpdate(offset, result);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,16 +11,15 @@ import de.ellpeck.naturesaura.packet.PacketParticleStream;
|
|||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import de.ellpeck.naturesaura.recipes.AltarRecipe;
|
||||
import de.ellpeck.naturesaura.recipes.ModRecipes;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
@ -67,21 +66,21 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
|
|||
private int lastAura;
|
||||
private boolean firstTick = true;
|
||||
|
||||
public BlockEntityNatureAltar() {
|
||||
super(ModTileEntities.NATURE_ALTAR);
|
||||
public BlockEntityNatureAltar(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.NATURE_ALTAR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
Random rand = this.level.rand;
|
||||
Random 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.add(x, 1, z);
|
||||
BlockPos offset = this.worldPosition.offset(x, 1, z);
|
||||
BlockState state = this.level.getBlockState(offset);
|
||||
this.catalysts[index] = state.getBlock().getItem(this.level, offset, state);
|
||||
this.catalysts[index] = state.getBlock().getCloneItemStack(this.level, offset, state);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
@ -156,8 +155,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
|
|||
this.currentRecipe = null;
|
||||
this.timer = 0;
|
||||
|
||||
this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5,
|
||||
SoundEvents.ENTITY_ARROW_HIT_PLAYER, SoundCategory.BLOCKS, 0.65F, 1F);
|
||||
this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, SoundEvents.ARROW_HIT_PLAYER, SoundSource.BLOCKS, 0.65F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +201,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
|
|||
|
||||
private AltarRecipe getRecipeForInput(ItemStack input) {
|
||||
IAuraType type = IAuraType.forLevel(this.level);
|
||||
for (AltarRecipe recipe : this.level.getRecipeManager().getRecipes(ModRecipes.ALTAR_TYPE, null, null)) {
|
||||
for (AltarRecipe 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;
|
||||
|
@ -251,7 +249,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
|
|||
if (type == SaveType.TILE) {
|
||||
if (compound.contains("recipe")) {
|
||||
if (this.hasLevel())
|
||||
this.currentRecipe = (AltarRecipe) this.level.getRecipeManager().getRecipe(new ResourceLocation(compound.getString("recipe"))).orElse(null);
|
||||
this.currentRecipe = (AltarRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
|
||||
this.timer = compound.getInt("timer");
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
@ -14,8 +13,8 @@ public class BlockEntityOakGenerator extends BlockEntityImpl implements ITickabl
|
|||
|
||||
public Queue<BlockPos> scheduledBigTrees = new ArrayDeque<>();
|
||||
|
||||
public BlockEntityOakGenerator() {
|
||||
super(ModTileEntities.OAK_GENERATOR);
|
||||
public BlockEntityOakGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.OAK_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -6,18 +6,19 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
|
|||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import de.ellpeck.naturesaura.recipes.ModRecipes;
|
||||
import de.ellpeck.naturesaura.recipes.OfferingRecipe;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.effect.LightningBoltEntity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Queue;
|
||||
|
||||
public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
public final ItemStackHandler items = new ItemStackHandlerNA(1, this, true) {
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
|
@ -34,12 +36,12 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
};
|
||||
private final Queue<ItemStack> itemsToSpawn = new ArrayDeque<>();
|
||||
|
||||
public BlockEntityOfferingTable() {
|
||||
super(ModTileEntities.OFFERING_TABLE);
|
||||
public BlockEntityOfferingTable(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.OFFERING_TABLE, pos, state);
|
||||
}
|
||||
|
||||
private OfferingRecipe getRecipe(ItemStack input) {
|
||||
for (OfferingRecipe recipe : this.level.getRecipeManager().getRecipes(ModRecipes.OFFERING_TYPE, null, null))
|
||||
for (OfferingRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.OFFERING_TYPE, null, null))
|
||||
if (recipe.input.test(input))
|
||||
return recipe;
|
||||
return null;
|
||||
|
@ -56,7 +58,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
if (stack.isEmpty())
|
||||
return;
|
||||
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(this.worldPosition).grow(1));
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1));
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -65,7 +67,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
return;
|
||||
|
||||
for (ItemEntity item : items) {
|
||||
if (!item.isAlive() || item.cannotPickup())
|
||||
if (!item.isAlive() || item.hasPickUpDelay())
|
||||
continue;
|
||||
|
||||
ItemStack itemStack = item.getItem();
|
||||
|
@ -78,33 +80,30 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
int amount = Helper.getIngredientAmount(recipe.input);
|
||||
int recipeCount = stack.getCount() / amount;
|
||||
stack.shrink(recipeCount * amount);
|
||||
item.remove();
|
||||
item.kill();
|
||||
this.sendToClients();
|
||||
|
||||
for (int i = 0; i < recipeCount; i++)
|
||||
this.itemsToSpawn.add(recipe.output.copy());
|
||||
|
||||
if (Multiblocks.OFFERING_TABLE.forEach(this.worldPosition, 'R', (pos, m) -> this.level.getBlockState(pos).getBlock() == Blocks.WITHER_ROSE)) {
|
||||
for (int i = this.level.rand.nextInt(5) + 3; i >= 0; i--)
|
||||
for (int i = this.level.random.nextInt(5) + 3; i >= 0; i--)
|
||||
this.itemsToSpawn.add(new ItemStack(Items.BLACK_DYE));
|
||||
}
|
||||
|
||||
LightningBoltEntity lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level);
|
||||
lightningboltentity.setEffectOnly(true);
|
||||
lightningboltentity.moveForced(Vector3d.copyCenteredHorizontally(this.worldPosition));
|
||||
this.level.addEntity(lightningboltentity);
|
||||
LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(this.level);
|
||||
lightningboltentity.setVisualOnly(true);
|
||||
lightningboltentity.moveTo(Vec3.atCenterOf(this.worldPosition));
|
||||
this.level.addFreshEntity(lightningboltentity);
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(
|
||||
(float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.OFFERING_TABLE,
|
||||
(float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.OFFERING_TABLE,
|
||||
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()));
|
||||
|
||||
break;
|
||||
}
|
||||
} else if (this.level.getGameTime() % 3 == 0) {
|
||||
if (!this.itemsToSpawn.isEmpty())
|
||||
this.level.addEntity(new ItemEntity(
|
||||
this.level,
|
||||
this.worldPosition.getX() + 0.5F, 256, this.worldPosition.getZ() + 0.5F,
|
||||
this.itemsToSpawn.remove()));
|
||||
this.level.addFreshEntity(new ItemEntity(this.level, this.worldPosition.getX() + 0.5F, 256, this.worldPosition.getZ() + 0.5F, this.itemsToSpawn.remove()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,10 +115,9 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
compound.put("items", this.items.serializeNBT());
|
||||
|
||||
if (type != SaveType.SYNC) {
|
||||
ListNBT list = new ListNBT();
|
||||
for (ItemStack stack : this.itemsToSpawn) {
|
||||
ListTag list = new ListTag();
|
||||
for (ItemStack stack : this.itemsToSpawn)
|
||||
list.add(stack.serializeNBT());
|
||||
}
|
||||
compound.put("items_to_spawn", list);
|
||||
}
|
||||
}
|
||||
|
@ -133,10 +131,9 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
|
|||
|
||||
if (type != SaveType.SYNC) {
|
||||
this.itemsToSpawn.clear();
|
||||
ListNBT list = compound.getList("items_to_spawn", 10);
|
||||
for (INBT base : list) {
|
||||
this.itemsToSpawn.add(ItemStack.read((CompoundTag) base));
|
||||
}
|
||||
ListTag list = compound.getList("items_to_spawn", 10);
|
||||
for (Tag base : list)
|
||||
this.itemsToSpawn.add(ItemStack.of((CompoundTag) base));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockEntityPickupStopper extends BlockEntityImpl {
|
||||
|
||||
public BlockEntityPickupStopper() {
|
||||
super(ModTileEntities.PICKUP_STOPPER);
|
||||
public BlockEntityPickupStopper(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.PICKUP_STOPPER, pos, state);
|
||||
}
|
||||
|
||||
public float getRadius() {
|
|
@ -5,19 +5,18 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
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.InteractionHand;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
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;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
|
@ -29,8 +28,8 @@ import java.util.List;
|
|||
|
||||
public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
public BlockEntityPlacer() {
|
||||
super(ModTileEntities.PLACER);
|
||||
public BlockEntityPlacer(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.PLACER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,13 +37,13 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
|
|||
if (!this.level.isClientSide && this.level.getGameTime() % 15 == 0) {
|
||||
if (this.redstonePower > 0)
|
||||
return;
|
||||
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.up());
|
||||
BlockEntity tileUp = this.level.getBlockEntity(this.worldPosition.above());
|
||||
if (tileUp == null)
|
||||
return;
|
||||
IItemHandler handler = tileUp.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.DOWN).orElse(null);
|
||||
if (handler == null)
|
||||
return;
|
||||
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
if (frames.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -53,11 +52,11 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
|
|||
for (int x = -range; x <= range; x++)
|
||||
for (int y = -range; y <= range; y++)
|
||||
for (int z = -range; z <= range; z++) {
|
||||
BlockPos pos = this.worldPosition.add(x, y, z);
|
||||
BlockPos pos = this.worldPosition.offset(x, y, z);
|
||||
if (!this.framesContain(frames, pos, this.level.getBlockState(pos)))
|
||||
continue;
|
||||
|
||||
BlockPos up = pos.up();
|
||||
BlockPos up = pos.above();
|
||||
BlockState state = this.level.getBlockState(up);
|
||||
if (state.getMaterial().isReplaceable())
|
||||
validPositions.add(up);
|
||||
|
@ -70,9 +69,9 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
|
|||
if (stack.isEmpty())
|
||||
continue;
|
||||
|
||||
BlockPos pos = validPositions.get(this.level.rand.nextInt(validPositions.size()));
|
||||
BlockPos pos = validPositions.get(this.level.random.nextInt(validPositions.size()));
|
||||
ItemStack left = this.tryPlace(stack.copy(), pos);
|
||||
if (ItemStack.areItemStacksEqual(stack, left))
|
||||
if (ItemStack.isSame(stack, left))
|
||||
continue;
|
||||
|
||||
handler.extractItem(i, 1, false);
|
||||
|
@ -86,13 +85,13 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
|
|||
}
|
||||
}
|
||||
|
||||
private boolean framesContain(List<ItemFrameEntity> frames, BlockPos pos, BlockState state) {
|
||||
ItemStack stack = state.getBlock().getItem(this.level, pos, state);
|
||||
private boolean framesContain(List<ItemFrame> frames, BlockPos pos, BlockState state) {
|
||||
ItemStack stack = state.getBlock().getCloneItemStack(this.level, pos, state);
|
||||
if (stack.isEmpty())
|
||||
return false;
|
||||
|
||||
for (ItemFrameEntity frame : frames) {
|
||||
ItemStack frameStack = frame.getDisplayedItem();
|
||||
for (ItemFrame frame : frames) {
|
||||
ItemStack frameStack = frame.getItem();
|
||||
if (frameStack.isEmpty())
|
||||
continue;
|
||||
if (Helper.areItemsEqual(stack, frameStack, false))
|
||||
|
@ -108,9 +107,9 @@ public class BlockEntityPlacer extends BlockEntityImpl implements ITickableBlock
|
|||
if (!(this.level instanceof ServerLevel))
|
||||
return stack;
|
||||
FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
|
||||
fake.inventory.mainInventory.set(fake.inventory.currentItem, stack);
|
||||
BlockRayTraceResult ray = new BlockRayTraceResult(Vector3d.copyCentered(pos), Direction.UP, pos, false);
|
||||
ForgeHooks.onPlaceItemIntoLevel(new ItemUseContext(fake, Hand.MAIN_HAND, ray));
|
||||
return fake.getHeldItemMainhand().copy();
|
||||
fake.getInventory().items.set(fake.getInventory().selected, stack);
|
||||
BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
|
||||
ForgeHooks.onPlaceItemIntoWorld(new UseOnContext(fake, InteractionHand.MAIN_HAND, ray));
|
||||
return fake.getMainHandItem().copy();
|
||||
}
|
||||
}
|
|
@ -1,25 +1,23 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.entity.AreaEffectCloudEntity;
|
||||
import net.minecraft.potion.Effect;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionUtils;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.AreaEffectCloud;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
public BlockEntityPotionGenerator() {
|
||||
super(ModTileEntities.POTION_GENERATOR);
|
||||
public BlockEntityPotionGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.POTION_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,19 +26,19 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
|
|||
if (Multiblocks.POTION_GENERATOR.isComplete(this.level, this.worldPosition)) {
|
||||
boolean addedOne = false;
|
||||
|
||||
List<AreaEffectCloudEntity> clouds = this.level.getEntitiesWithinAABB(AreaEffectCloudEntity.class, new AxisAlignedBB(this.worldPosition).grow(2));
|
||||
for (AreaEffectCloudEntity cloud : clouds) {
|
||||
List<AreaEffectCloud> clouds = this.level.getEntitiesOfClass(AreaEffectCloud.class, new AABB(this.worldPosition).inflate(2));
|
||||
for (AreaEffectCloud cloud : clouds) {
|
||||
if (!cloud.isAlive())
|
||||
continue;
|
||||
|
||||
if (!addedOne) {
|
||||
Potion type = ObfuscationReflectionHelper.getPrivateValue(AreaEffectCloudEntity.class, cloud, "field_184502_e");
|
||||
Potion type = cloud.getPotion();
|
||||
if (type == null)
|
||||
continue;
|
||||
|
||||
for (EffectInstance effect : type.getEffects()) {
|
||||
Effect potion = effect.getPotion();
|
||||
if (!potion.isBeneficial() || potion.isInstant()) {
|
||||
for (MobEffectInstance effect : type.getEffects()) {
|
||||
MobEffect potion = effect.getEffect();
|
||||
if (!potion.isBeneficial() || potion.isInstantenous()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -51,7 +49,7 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
|
|||
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(
|
||||
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.POTION_GEN,
|
||||
PotionUtils.getPotionColor(type), canGen ? 1 : 0));
|
||||
PotionUtils.getColor(type), canGen ? 1 : 0));
|
||||
|
||||
addedOne = true;
|
||||
break;
|
||||
|
@ -59,10 +57,11 @@ public class BlockEntityPotionGenerator extends BlockEntityImpl implements ITick
|
|||
}
|
||||
|
||||
float newRadius = cloud.getRadius() - 0.25F;
|
||||
if (newRadius < 0.5F)
|
||||
cloud.remove();
|
||||
else
|
||||
if (newRadius < 0.5F) {
|
||||
cloud.kill();
|
||||
} else {
|
||||
cloud.setRadius(newRadius);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,12 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.entity.monster.MagmaCubeEntity;
|
||||
import net.minecraft.entity.monster.SlimeEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.entity.monster.MagmaCube;
|
||||
import net.minecraft.world.entity.monster.Slime;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
|
@ -15,8 +14,8 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
|
|||
private int amountToRelease;
|
||||
private int color;
|
||||
|
||||
public BlockEntitySlimeSplitGenerator() {
|
||||
super(ModTileEntities.SLIME_SPLIT_GENERATOR);
|
||||
public BlockEntitySlimeSplitGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.SLIME_SPLIT_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,13 +41,13 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
|
|||
return this.generationTimer > 0;
|
||||
}
|
||||
|
||||
public void startGenerating(SlimeEntity slime) {
|
||||
int size = slime.getSlimeSize();
|
||||
public void startGenerating(Slime slime) {
|
||||
int size = slime.getSize();
|
||||
this.generationTimer = size * 30;
|
||||
this.amountToRelease = (size * this.getGenerationAmount(slime)) / this.generationTimer;
|
||||
this.color = this.getSlimeColor(slime);
|
||||
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles((float) slime.getPosX(), (float) slime.getPosY(), (float) slime.getPosZ(), PacketParticles.Type.SLIME_SPLIT_GEN_START,
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles((float) slime.getX(), (float) slime.getY(), (float) slime.getZ(), PacketParticles.Type.SLIME_SPLIT_GEN_START,
|
||||
this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), this.color));
|
||||
}
|
||||
|
||||
|
@ -72,16 +71,16 @@ public class BlockEntitySlimeSplitGenerator extends BlockEntityImpl implements I
|
|||
}
|
||||
}
|
||||
|
||||
private int getSlimeColor(SlimeEntity slime) {
|
||||
if (slime instanceof MagmaCubeEntity) {
|
||||
private int getSlimeColor(Slime slime) {
|
||||
if (slime instanceof MagmaCube) {
|
||||
return 0x942516;
|
||||
} else {
|
||||
return 0x4da84f;
|
||||
}
|
||||
}
|
||||
|
||||
private int getGenerationAmount(SlimeEntity slime) {
|
||||
if (slime instanceof MagmaCubeEntity) {
|
||||
private int getGenerationAmount(Slime slime) {
|
||||
if (slime instanceof MagmaCube) {
|
||||
return 45000;
|
||||
} else {
|
||||
return 25000;
|
|
@ -1,20 +1,19 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CauldronBlock;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.tags.FluidTags;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.common.FarmlandWaterManager;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.ticket.AABBTicket;
|
||||
|
@ -30,23 +29,23 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
private final LazyOptional<IFluidHandler> tank = LazyOptional.of(InfiniteTank::new);
|
||||
private AABBTicket waterTicket;
|
||||
|
||||
public BlockEntitySpring() {
|
||||
super(ModTileEntities.SPRING);
|
||||
public BlockEntitySpring(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.SPRING, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
if (!this.level.isClientSide) {
|
||||
// add a ticket to water crops
|
||||
AxisAlignedBB area = new AxisAlignedBB(this.worldPosition).grow(5, 1, 5);
|
||||
AABB area = new AABB(this.worldPosition).inflate(5, 1, 5);
|
||||
this.waterTicket = FarmlandWaterManager.addAABBTicket(this.level, area);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
if (!this.level.isClientSide && this.waterTicket != null && this.waterTicket.isValid()) {
|
||||
this.waterTicket.invalidate();
|
||||
this.waterTicket = null;
|
||||
|
@ -60,13 +59,13 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
return;
|
||||
|
||||
// fill cauldrons
|
||||
BlockPos up = this.worldPosition.up();
|
||||
BlockPos up = this.worldPosition.above();
|
||||
BlockState upState = this.level.getBlockState(up);
|
||||
if (upState.hasProperty(CauldronBlock.LEVEL)) {
|
||||
int level = upState.get(CauldronBlock.LEVEL);
|
||||
if (upState.hasProperty(BlockStateProperties.LEVEL_CAULDRON)) {
|
||||
int level = upState.getValue(BlockStateProperties.LEVEL_CAULDRON);
|
||||
if (level < 3) {
|
||||
this.level.setBlockState(up, upState.with(CauldronBlock.LEVEL, level + 1));
|
||||
this.level.playSound(null, up, SoundEvents.ITEM_BUCKET_FILL, SoundCategory.BLOCKS, 1, 1);
|
||||
this.level.setBlockAndUpdate(up, upState.setValue(BlockStateProperties.LEVEL_CAULDRON, level + 1));
|
||||
this.level.playSound(null, up, SoundEvents.BUCKET_FILL, SoundSource.BLOCKS, 1, 1);
|
||||
this.consumeAura(2500);
|
||||
return;
|
||||
}
|
||||
|
@ -77,11 +76,11 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
for (int x = -spongeRadius; x <= spongeRadius; x++) {
|
||||
for (int y = -spongeRadius; y <= spongeRadius; y++) {
|
||||
for (int z = -spongeRadius; z <= spongeRadius; z++) {
|
||||
BlockPos pos = this.worldPosition.add(x, y, z);
|
||||
BlockPos pos = this.worldPosition.offset(x, y, z);
|
||||
BlockState state = this.level.getBlockState(pos);
|
||||
if (state.getBlock() == Blocks.SPONGE) {
|
||||
this.level.setBlockState(pos, Blocks.WET_SPONGE.getDefaultState(), 2);
|
||||
this.level.playEvent(2001, pos, Block.getStateId(Blocks.WATER.getDefaultState()));
|
||||
this.level.setBlock(pos, Blocks.WET_SPONGE.defaultBlockState(), 2);
|
||||
this.level.levelEvent(2001, pos, Block.getId(Blocks.WATER.defaultBlockState()));
|
||||
this.consumeAura(2500);
|
||||
return;
|
||||
}
|
||||
|
@ -91,31 +90,31 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
|
||||
// generate obsidian
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
BlockPos side = this.worldPosition.offset(dir);
|
||||
BlockPos side = this.worldPosition.relative(dir);
|
||||
if (this.isLava(side, true)) {
|
||||
this.level.setBlockState(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.getDefaultState()));
|
||||
this.level.playEvent(1501, side, 0);
|
||||
this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, side, Blocks.OBSIDIAN.defaultBlockState()));
|
||||
this.level.levelEvent(1501, side, 0);
|
||||
this.consumeAura(1500);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// generate stone
|
||||
BlockPos twoUp = this.worldPosition.up(2);
|
||||
if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir(this.level, up) || this.isLava(up, false))) {
|
||||
this.level.setBlockState(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.getDefaultState()));
|
||||
this.level.playEvent(1501, up, 0);
|
||||
BlockPos twoUp = this.worldPosition.above(2);
|
||||
if (this.isLava(twoUp, false) && (this.level.getBlockState(up).isAir() || this.isLava(up, false))) {
|
||||
this.level.setBlockAndUpdate(up, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, up, twoUp, Blocks.STONE.defaultBlockState()));
|
||||
this.level.levelEvent(1501, up, 0);
|
||||
this.consumeAura(150);
|
||||
return;
|
||||
}
|
||||
|
||||
// generate cobblestone
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
BlockPos twoSide = this.worldPosition.offset(dir, 2);
|
||||
BlockPos side = this.worldPosition.offset(dir);
|
||||
if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir(this.level, side) || this.isLava(side, false))) {
|
||||
this.level.setBlockState(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.getDefaultState()));
|
||||
this.level.playEvent(1501, side, 0);
|
||||
BlockPos twoSide = this.worldPosition.relative(dir, 2);
|
||||
BlockPos side = this.worldPosition.relative(dir);
|
||||
if (this.isLava(twoSide, false) && (this.level.getBlockState(side).isAir() || this.isLava(side, false))) {
|
||||
this.level.setBlockAndUpdate(side, ForgeEventFactory.fireFluidPlaceBlockEvent(this.level, side, twoSide, Blocks.COBBLESTONE.defaultBlockState()));
|
||||
this.level.levelEvent(1501, side, 0);
|
||||
this.consumeAura(100);
|
||||
return;
|
||||
}
|
||||
|
@ -138,10 +137,11 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
|
||||
private boolean isLava(BlockPos offset, boolean source) {
|
||||
FluidState state = this.level.getFluidState(offset);
|
||||
return (!source || state.isSource()) && state.getFluid().isIn(FluidTags.LAVA);
|
||||
return (!source || state.isSource()) && state.getType().is(FluidTags.LAVA);
|
||||
}
|
||||
|
||||
private class InfiniteTank implements IFluidTank, IFluidHandler {
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid() {
|
||||
return new FluidStack(Fluids.WATER, 1000);
|
||||
|
@ -159,7 +159,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
|
|||
|
||||
@Override
|
||||
public boolean isFluidValid(FluidStack stack) {
|
||||
return stack.getFluid().isIn(FluidTags.WATER);
|
||||
return stack.getFluid().is(FluidTags.WATER);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -2,20 +2,18 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticleStream;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.INBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
|
@ -28,8 +26,8 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
|
||||
private final Map<BlockState, MutableInt> consumedRecently = new HashMap<>();
|
||||
|
||||
public BlockEntityFlowerGenerator() {
|
||||
super(ModTileEntities.FLOWER_GENERATOR);
|
||||
public BlockEntityFlowerGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.FLOWER_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +38,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
for (int x = -range; x <= range; x++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int z = -range; z <= range; z++) {
|
||||
BlockPos offset = this.worldPosition.add(x, y, z);
|
||||
BlockPos offset = this.worldPosition.offset(x, y, z);
|
||||
BlockState state = this.level.getBlockState(offset);
|
||||
if (BlockTags.SMALL_FLOWERS.contains(state.getBlock()))
|
||||
possible.add(offset);
|
||||
|
@ -51,7 +49,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
if (possible.isEmpty())
|
||||
return;
|
||||
|
||||
BlockPos pos = possible.get(this.level.rand.nextInt(possible.size()));
|
||||
BlockPos pos = possible.get(this.level.random.nextInt(possible.size()));
|
||||
BlockState state = this.level.getBlockState(pos);
|
||||
MutableInt curr = this.consumedRecently.computeIfAbsent(state, s -> new MutableInt());
|
||||
|
||||
|
@ -78,15 +76,15 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
|
||||
int color = Helper.blendColors(0x5ccc30, 0xe53c16, toAdd / (float) addAmount);
|
||||
if (toAdd > 0) {
|
||||
for (int i = this.level.rand.nextInt(5) + 5; i >= 0; i--)
|
||||
for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--)
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
|
||||
pos.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
pos.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
pos.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.worldPosition.getX() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.worldPosition.getY() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.worldPosition.getZ() + 0.25F + this.level.rand.nextFloat() * 0.5F,
|
||||
this.level.rand.nextFloat() * 0.02F + 0.1F, color, 1F
|
||||
pos.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
pos.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
pos.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.worldPosition.getX() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.worldPosition.getY() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.worldPosition.getZ() + 0.25F + this.level.random.nextFloat() * 0.5F,
|
||||
this.level.random.nextFloat() * 0.02F + 0.1F, color, 1F
|
||||
));
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
|
||||
}
|
||||
|
@ -104,7 +102,7 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
super.writeNBT(compound, type);
|
||||
|
||||
if (type != SaveType.SYNC && !this.consumedRecently.isEmpty()) {
|
||||
ListNBT list = new ListNBT();
|
||||
ListTag list = new ListTag();
|
||||
for (Map.Entry<BlockState, MutableInt> entry : this.consumedRecently.entrySet()) {
|
||||
BlockState state = entry.getKey();
|
||||
Block block = state.getBlock();
|
||||
|
@ -123,12 +121,12 @@ public class BlockEntityFlowerGenerator extends BlockEntityImpl implements ITick
|
|||
super.readNBT(compound, type);
|
||||
if (type != SaveType.SYNC) {
|
||||
this.consumedRecently.clear();
|
||||
ListNBT list = compound.getList("consumed_recently", 10);
|
||||
for (INBT base : list) {
|
||||
ListTag list = compound.getList("consumed_recently", 10);
|
||||
for (Tag base : list) {
|
||||
CompoundTag tag = (CompoundTag) base;
|
||||
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(tag.getString("block")));
|
||||
if (block != null)
|
||||
this.consumedRecently.put(block.getDefaultState(), new MutableInt(tag.getInt("amount")));
|
||||
this.consumedRecently.put(block.defaultBlockState(), new MutableInt(tag.getInt("amount")));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
|
||||
|
||||
public BlockEntityGeneratorLimitRemover() {
|
||||
super(ModTileEntities.GENERATOR_LIMIT_REMOVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return new AxisAlignedBB(this.worldPosition, this.worldPosition.add(1, 2, 1));
|
||||
}
|
||||
}
|
|
@ -3,28 +3,29 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.HopperBlock;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.HopperBlockEntity;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.HopperBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
public BlockEntityHopperUpgrade() {
|
||||
super(ModTileEntities.HOPPER_UPGRADE);
|
||||
|
||||
public BlockEntityHopperUpgrade(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.HOPPER_UPGRADE, pos, state);
|
||||
}
|
||||
|
||||
private static boolean isValidHopper(BlockEntity tile) {
|
||||
if (tile instanceof HopperBlockEntity)
|
||||
return tile.getLevel().getBlockState(tile.getPos()).get(HopperBlock.ENABLED);
|
||||
return tile.getLevel().getBlockState(tile.getBlockPos()).getValue(HopperBlock.ENABLED);
|
||||
if (tile instanceof BlockEntityGratedChute)
|
||||
return ((BlockEntityGratedChute) tile).redstonePower <= 0;
|
||||
return false;
|
||||
|
@ -35,20 +36,19 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
|
|||
if (!this.level.isClientSide && this.level.getGameTime() % 10 == 0) {
|
||||
if (IAuraChunk.getAuraInArea(this.level, this.worldPosition, 25) < 100000)
|
||||
return;
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.down());
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.below());
|
||||
if (!isValidHopper(tile))
|
||||
return;
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
|
||||
if (handler == null)
|
||||
return;
|
||||
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
|
||||
new AxisAlignedBB(this.worldPosition).grow(7));
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(7));
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
|
||||
for (ItemEntity item : items) {
|
||||
if (!item.isAlive() || item.cannotPickup())
|
||||
if (!item.isAlive() || item.hasPickUpDelay())
|
||||
continue;
|
||||
ItemStack stack = item.getItem();
|
||||
if (stack.isEmpty())
|
||||
|
@ -62,16 +62,16 @@ public class BlockEntityHopperUpgrade extends BlockEntityImpl implements ITickab
|
|||
}
|
||||
}
|
||||
|
||||
if (!ItemStack.areItemStacksEqual(stack, copy)) {
|
||||
if (!ItemStack.isSame(stack, copy)) {
|
||||
item.setItem(copy);
|
||||
if (copy.isEmpty())
|
||||
item.remove();
|
||||
item.kill();
|
||||
|
||||
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 25, this.worldPosition);
|
||||
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, 500);
|
||||
|
||||
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
|
||||
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.HOPPER_UPGRADE));
|
||||
new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.HOPPER_UPGRADE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -18,8 +18,8 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
|
|||
private Direction currentSide = Direction.NORTH;
|
||||
public boolean isRandomMode;
|
||||
|
||||
public BlockEntityItemDistributor() {
|
||||
super(ModTileEntities.ITEM_DISTRIBUTOR);
|
||||
public BlockEntityItemDistributor(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.ITEM_DISTRIBUTOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +44,7 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
|
|||
continue;
|
||||
for (int j = 0; j < dest.getSlots(); j++) {
|
||||
ItemStack remain = dest.insertItem(j, stack, false);
|
||||
if (!ItemStack.areItemStacksEqual(remain, stack)) {
|
||||
if (!ItemStack.isSame(remain, stack)) {
|
||||
above.extractItem(i, 1, false);
|
||||
this.cooldown = 3;
|
||||
return;
|
||||
|
@ -54,7 +54,7 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
|
|||
}
|
||||
|
||||
private IItemHandler getHandler(Direction direction) {
|
||||
BlockPos offset = this.worldPosition.offset(direction);
|
||||
BlockPos offset = this.worldPosition.relative(direction);
|
||||
BlockEntity tile = this.level.getBlockEntity(offset);
|
||||
if (tile == null)
|
||||
return null;
|
||||
|
@ -65,16 +65,16 @@ public class BlockEntityItemDistributor extends BlockEntityImpl implements ITick
|
|||
if (this.isRandomMode) {
|
||||
List<IItemHandler> handlers = new ArrayList<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
IItemHandler handler = this.getHandler(Direction.byHorizontalIndex(i));
|
||||
IItemHandler handler = this.getHandler(Direction.values()[i]);
|
||||
if (handler != null)
|
||||
handlers.add(handler);
|
||||
}
|
||||
if (handlers.isEmpty())
|
||||
return null;
|
||||
return handlers.get(this.level.rand.nextInt(handlers.size()));
|
||||
return handlers.get(this.level.random.nextInt(handlers.size()));
|
||||
} else {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
this.currentSide = this.currentSide.rotateY();
|
||||
this.currentSide = this.currentSide.getClockWise();
|
||||
IItemHandler handler = this.getHandler(this.currentSide);
|
||||
if (handler != null)
|
||||
return handler;
|
||||
|
|
|
@ -2,11 +2,13 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
|
||||
import de.ellpeck.naturesaura.entities.EntityEffectInhibitor;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.EntityPredicates;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
@ -14,19 +16,18 @@ import java.util.List;
|
|||
|
||||
public class BlockEntityPowderPlacer extends BlockEntityImpl {
|
||||
|
||||
public BlockEntityPowderPlacer() {
|
||||
super(ModTileEntities.POWDER_PLACER);
|
||||
public BlockEntityPowderPlacer(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.POWDER_PLACER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRedstonePowerChange(int newPower) {
|
||||
if (this.redstonePower <= 0 && newPower > 0) {
|
||||
List<EntityEffectInhibitor> powders = this.level.getEntitiesWithinAABB(EntityEffectInhibitor.class,
|
||||
new AxisAlignedBB(this.worldPosition, this.worldPosition.add(1, 2, 1)), EntityPredicates.IS_ALIVE);
|
||||
List<EntityEffectInhibitor> powders = this.level.getEntitiesOfClass(EntityEffectInhibitor.class, new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1)), Entity::isAlive);
|
||||
for (Direction facing : Direction.values()) {
|
||||
if (!facing.getAxis().isHorizontal())
|
||||
continue;
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing));
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
|
||||
if (tile == null)
|
||||
continue;
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()).orElse(null);
|
||||
|
@ -39,7 +40,7 @@ public class BlockEntityPowderPlacer extends BlockEntityImpl {
|
|||
for (int i = 0; i < handler.getSlots(); i++) {
|
||||
ItemStack remain = handler.insertItem(i, drop, false);
|
||||
if (remain.isEmpty()) {
|
||||
powder.remove();
|
||||
powder.kill();
|
||||
break;
|
||||
} else if (remain.getCount() != drop.getCount()) {
|
||||
powder.setAmount(remain.getCount());
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockEntityProjectileGenerator extends BlockEntityImpl {
|
||||
|
||||
public Direction nextSide = Direction.NORTH;
|
||||
|
||||
public BlockEntityProjectileGenerator() {
|
||||
super(ModTileEntities.PROJECTILE_GENERATOR);
|
||||
public BlockEntityProjectileGenerator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.PROJECTILE_GENERATOR, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNBT(CompoundTag compound, SaveType type) {
|
||||
super.writeNBT(compound, type);
|
||||
if (type != SaveType.BLOCK) {
|
||||
compound.putInt("next_side", this.nextSide.getHorizontalIndex());
|
||||
}
|
||||
if (type != SaveType.BLOCK)
|
||||
compound.putInt("next_side", this.nextSide.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(CompoundTag compound, SaveType type) {
|
||||
super.readNBT(compound, type);
|
||||
if (type != SaveType.BLOCK) {
|
||||
this.nextSide = Direction.byHorizontalIndex(compound.getInt("next_side"));
|
||||
}
|
||||
if (type != SaveType.BLOCK)
|
||||
this.nextSide = Direction.values()[compound.getInt("next_side")];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,12 +5,12 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|||
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.tileentity.BlockEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
|
@ -25,8 +25,8 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
|
|||
private final LazyOptional<IEnergyStorage> storageOptional = LazyOptional.of(() -> this.storage);
|
||||
private int lastEnergy;
|
||||
|
||||
public BlockEntityRFConverter() {
|
||||
super(ModTileEntities.RF_CONVERTER);
|
||||
public BlockEntityRFConverter(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.RF_CONVERTER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,7 +50,7 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
|
|||
}
|
||||
|
||||
for (Direction facing : Direction.values()) {
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.offset(facing));
|
||||
BlockEntity tile = this.level.getBlockEntity(this.worldPosition.relative(facing));
|
||||
if (tile == null)
|
||||
continue;
|
||||
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite()).orElse(null);
|
||||
|
@ -99,8 +99,8 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
|
|||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
this.storageOptional.invalidate();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,24 +4,24 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.passive.SnowGolemEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.level.gen.Heightmap;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.animal.SnowGolem;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
|
||||
public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickableBlockEntity {
|
||||
|
||||
private int snowmanCount;
|
||||
|
||||
public BlockEntitySnowCreator() {
|
||||
super(ModTileEntities.SNOW_CREATOR);
|
||||
public BlockEntitySnowCreator(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.SNOW_CREATOR, pos, state);
|
||||
}
|
||||
|
||||
public int getRange() {
|
||||
|
@ -45,23 +45,23 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
|
|||
return;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
double angle = this.level.rand.nextFloat() * Math.PI * 2;
|
||||
BlockPos pos = this.worldPosition.add(Math.cos(angle) * range * this.level.rand.nextFloat(), 0, Math.sin(angle) * range * this.level.rand.nextFloat());
|
||||
pos = this.level.getHeight(Heightmap.Type.MOTION_BLOCKING, pos);
|
||||
BlockPos down = pos.down();
|
||||
double angle = this.level.random.nextFloat() * Math.PI * 2;
|
||||
BlockPos pos = this.worldPosition.offset(Math.cos(angle) * range * this.level.random.nextFloat(), 0, Math.sin(angle) * range * this.level.random.nextFloat());
|
||||
pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos);
|
||||
BlockPos down = pos.below();
|
||||
|
||||
Fluid fluid = this.level.getFluidState(down).getFluid();
|
||||
Fluid fluid = this.level.getFluidState(down).getType();
|
||||
if (fluid == Fluids.WATER) {
|
||||
if (this.level.getBlockState(down).getMaterial().isReplaceable())
|
||||
this.level.setBlockState(down, Blocks.ICE.getDefaultState());
|
||||
} else if (Blocks.SNOW.getDefaultState().isValidPosition(this.level, pos) && this.level.getBlockState(pos).getBlock() != Blocks.SNOW && this.level.getBlockState(pos).getMaterial().isReplaceable()) {
|
||||
this.level.setBlockState(pos, Blocks.SNOW.getDefaultState());
|
||||
this.level.setBlockAndUpdate(down, Blocks.ICE.defaultBlockState());
|
||||
} else if (Blocks.SNOW.defaultBlockState().canSurvive(this.level, pos) && this.level.getBlockState(pos).getBlock() != Blocks.SNOW && this.level.getBlockState(pos).getMaterial().isReplaceable()) {
|
||||
this.level.setBlockAndUpdate(pos, Blocks.SNOW.defaultBlockState());
|
||||
|
||||
if (this.snowmanCount < range / 2 && this.level.rand.nextFloat() >= 0.995F) {
|
||||
if (this.snowmanCount < range / 2 && this.level.random.nextFloat() >= 0.995F) {
|
||||
this.snowmanCount++;
|
||||
Entity golem = new SnowGolemEntity(EntityType.SNOW_GOLEM, this.level);
|
||||
golem.setPosition(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
|
||||
this.level.addEntity(golem);
|
||||
Entity golem = new SnowGolem(EntityType.SNOW_GOLEM, this.level);
|
||||
golem.setPos(pos.getX() + 0.5F, pos.getY(), pos.getZ() + 0.5F);
|
||||
this.level.addFreshEntity(golem);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
|
@ -78,15 +78,15 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
|
|||
if (this.level.getGameTime() % 30 != 0)
|
||||
return;
|
||||
for (int i = range * 4; i >= 0; i--) {
|
||||
double angle = this.level.rand.nextFloat() * Math.PI * 2;
|
||||
BlockPos pos = this.worldPosition.add(
|
||||
Math.cos(angle) * range * this.level.rand.nextFloat(),
|
||||
Mth.nextInt(this.level.rand, range / 2, range),
|
||||
Math.sin(angle) * range * this.level.rand.nextFloat());
|
||||
double angle = this.level.random.nextFloat() * Math.PI * 2;
|
||||
BlockPos pos = this.worldPosition.offset(
|
||||
Math.cos(angle) * range * this.level.random.nextFloat(),
|
||||
Mth.nextInt(this.level.random, range / 2, range),
|
||||
Math.sin(angle) * range * this.level.random.nextFloat());
|
||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
pos.getX() + this.level.rand.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.rand.nextFloat(),
|
||||
this.level.rand.nextGaussian() * 0.05, 0, this.level.rand.nextGaussian() * 0.05,
|
||||
0xdbe9ff, 1 + this.level.rand.nextFloat() * 1.5F, 10 * range, 0.05F + this.level.rand.nextFloat() * 0.05F, true, true
|
||||
pos.getX() + this.level.random.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.random.nextFloat(),
|
||||
this.level.random.nextGaussian() * 0.05, 0, this.level.random.nextGaussian() * 0.05,
|
||||
0xdbe9ff, 1 + this.level.random.nextFloat() * 1.5F, 10 * range, 0.05F + this.level.random.nextFloat() * 0.05F, true, true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ package de.ellpeck.naturesaura.blocks.tiles;
|
|||
|
||||
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
||||
import de.ellpeck.naturesaura.misc.LevelData;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockEntitySpawnLamp extends BlockEntityImpl {
|
||||
|
||||
public BlockEntitySpawnLamp() {
|
||||
super(ModTileEntities.SPAWN_LAMP);
|
||||
public BlockEntitySpawnLamp(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.SPAWN_LAMP, pos, state);
|
||||
}
|
||||
|
||||
public int getRadius() {
|
||||
|
@ -14,8 +16,8 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
if (!this.level.isClientSide) {
|
||||
LevelData data = (LevelData) ILevelData.getLevelData(this.level);
|
||||
data.spawnLamps.add(this);
|
||||
|
@ -23,8 +25,8 @@ public class BlockEntitySpawnLamp extends BlockEntityImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
public void setRemoved() {
|
||||
super.setRemoved();
|
||||
if (!this.level.isClientSide) {
|
||||
LevelData data = (LevelData) ILevelData.getLevelData(this.level);
|
||||
data.spawnLamps.remove(this);
|
||||
|
|
|
@ -5,21 +5,21 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.item.ItemFrameEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.play.server.SUpdateTimePacket;
|
||||
import net.minecraft.server.management.PlayerList;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.EntityPredicates;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.level.GameRules;
|
||||
import net.minecraft.level.server.ServerLevel;
|
||||
import net.minecraft.level.storage.IServerLevelInfo;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,16 +27,16 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
|
||||
private long goalTime;
|
||||
|
||||
public BlockEntityTimeChanger() {
|
||||
super(ModTileEntities.TIME_CHANGER);
|
||||
public BlockEntityTimeChanger(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.TIME_CHANGER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!this.level.isClientSide) {
|
||||
List<ItemFrameEntity> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
for (ItemFrameEntity frame : frames) {
|
||||
ItemStack frameStack = frame.getDisplayedItem();
|
||||
List<ItemFrame> frames = Helper.getAttachedItemFrames(this.level, this.worldPosition);
|
||||
for (ItemFrame frame : frames) {
|
||||
ItemStack frameStack = frame.getItem();
|
||||
if (frameStack.isEmpty() || frameStack.getItem() != ModItems.CLOCK_HAND)
|
||||
continue;
|
||||
|
||||
|
@ -48,16 +48,16 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
this.sendToClients();
|
||||
return;
|
||||
}
|
||||
((IServerLevelInfo) this.level.getLevelInfo()).setDayTime(current + toAdd);
|
||||
((ServerLevelData) this.level.getLevelData()).setDayTime(current + toAdd);
|
||||
|
||||
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
|
||||
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, (int) toAdd * 20);
|
||||
|
||||
if (this.level instanceof ServerLevel) {
|
||||
PlayerList list = this.level.getServer().getPlayerList();
|
||||
list.sendPacketToAllPlayers(new SUpdateTimePacket(
|
||||
list.broadcastAll(new ClientboundSetTimePacket(
|
||||
this.level.getGameTime(), this.level.getDayTime(),
|
||||
this.level.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)));
|
||||
this.level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -65,10 +65,9 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
if (this.level.getGameTime() % 20 != 0)
|
||||
return;
|
||||
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class,
|
||||
new AxisAlignedBB(this.worldPosition).grow(1), EntityPredicates.IS_ALIVE);
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, new AABB(this.worldPosition).inflate(1), Entity::isAlive);
|
||||
for (ItemEntity item : items) {
|
||||
if (item.cannotPickup())
|
||||
if (item.hasPickUpDelay())
|
||||
continue;
|
||||
ItemStack stack = item.getItem();
|
||||
if (stack.isEmpty() || stack.getItem() != Items.CLOCK)
|
||||
|
@ -80,9 +79,9 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
this.goalTime = current + toMove;
|
||||
this.sendToClients();
|
||||
|
||||
if (stack.getCount() <= 1)
|
||||
item.remove();
|
||||
else {
|
||||
if (stack.getCount() <= 1) {
|
||||
item.kill();
|
||||
} else {
|
||||
stack.shrink(1);
|
||||
item.setItem(stack);
|
||||
}
|
||||
|
@ -93,7 +92,7 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
this.goalTime = 0;
|
||||
this.sendToClients();
|
||||
}
|
||||
} else if (this.goalTime > 0 && this.level.rand.nextFloat() >= 0.25F) {
|
||||
} else if (this.goalTime > 0 && this.level.random.nextFloat() >= 0.25F) {
|
||||
double angle = Math.toRadians(this.level.getDayTime() * 5F % 360);
|
||||
double x = this.worldPosition.getX() + 0.5 + Math.sin(angle) * 3F;
|
||||
double z = this.worldPosition.getZ() + 0.5 + Math.cos(angle) * 3F;
|
||||
|
@ -101,12 +100,12 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
|
|||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
x, this.worldPosition.getY() + 0.1F, z,
|
||||
0F, 0.12F, 0F,
|
||||
color, 1F + this.level.rand.nextFloat() * 2F,
|
||||
this.level.rand.nextInt(100) + 100, 0, false, true);
|
||||
color, 1F + this.level.random.nextFloat() * 2F,
|
||||
this.level.random.nextInt(100) + 100, 0, false, true);
|
||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
x, this.worldPosition.getY() + 0.1F, z,
|
||||
0F, 0F, 0F,
|
||||
IAuraType.forLevel(this.level).getColor(), 1F + this.level.rand.nextFloat(),
|
||||
IAuraType.forLevel(this.level).getColor(), 1F + this.level.random.nextFloat(),
|
||||
150, 0, false, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import de.ellpeck.naturesaura.Helper;
|
|||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.misc.WeatherType;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tileentity.ITickableBlockEntity;
|
||||
import net.minecraft.util.EntityPredicates;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.level.server.ServerLevel;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -23,8 +23,8 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
|
|||
private WeatherType type;
|
||||
private int itemAmount;
|
||||
|
||||
public BlockEntityWeatherChanger() {
|
||||
super(ModTileEntities.WEATHER_CHANGER);
|
||||
public BlockEntityWeatherChanger(BlockPos pos, BlockState state) {
|
||||
super(ModTileEntities.WEATHER_CHANGER, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,15 +38,15 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
|
|||
for (int r = 0; r < 360; r += 20) {
|
||||
double xOff = Math.cos(Math.toRadians(r)) * 3F;
|
||||
double zOff = Math.sin(Math.toRadians(r)) * 3F;
|
||||
for (int i = this.level.rand.nextInt(3); i > 0; i--) {
|
||||
for (int i = this.level.random.nextInt(3); i > 0; i--) {
|
||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
this.worldPosition.getX() + 0.5F + xOff,
|
||||
this.worldPosition.getY(),
|
||||
this.worldPosition.getZ() + 0.5F + zOff,
|
||||
this.level.rand.nextGaussian() * 0.02F,
|
||||
this.level.rand.nextFloat() * 0.1F + 0.1F,
|
||||
this.level.rand.nextGaussian() * 0.02F,
|
||||
color, this.level.rand.nextFloat() * 2 + 1, this.level.rand.nextInt(80) + 80, 0, false, true);
|
||||
this.level.random.nextGaussian() * 0.02F,
|
||||
this.level.random.nextFloat() * 0.1F + 0.1F,
|
||||
this.level.random.nextGaussian() * 0.02F,
|
||||
color, this.level.random.nextFloat() * 2 + 1, this.level.random.nextInt(80) + 80, 0, false, true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -64,15 +64,9 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
|
|||
int time = 6000 * this.itemAmount;
|
||||
ServerLevel server = (ServerLevel) this.level;
|
||||
switch (this.type) {
|
||||
case SUN:
|
||||
server.func_241113_a_(time, 0, false, false);
|
||||
break;
|
||||
case RAIN:
|
||||
server.func_241113_a_(0, time, true, false);
|
||||
break;
|
||||
case THUNDERSTORM:
|
||||
server.func_241113_a_(0, time, true, true);
|
||||
break;
|
||||
case SUN -> server.setWeatherParameters(time, 0, false, false);
|
||||
case RAIN -> server.setWeatherParameters(0, time, true, false);
|
||||
case THUNDERSTORM -> server.setWeatherParameters(0, time, true, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -110,17 +104,17 @@ public class BlockEntityWeatherChanger extends BlockEntityImpl implements ITicka
|
|||
}
|
||||
|
||||
private Pair<WeatherType, Integer> getNextWeatherType() {
|
||||
AxisAlignedBB area = new AxisAlignedBB(this.worldPosition).grow(2);
|
||||
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, area, EntityPredicates.IS_ALIVE);
|
||||
AABB area = new AABB(this.worldPosition).inflate(2);
|
||||
List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class, area, Entity::isAlive);
|
||||
for (ItemEntity entity : items) {
|
||||
if (entity.cannotPickup())
|
||||
if (entity.hasPickUpDelay())
|
||||
continue;
|
||||
ItemStack stack = entity.getItem();
|
||||
for (Map.Entry<ItemStack, WeatherType> entry : NaturesAuraAPI.WEATHER_CHANGER_CONVERSIONS.entrySet()) {
|
||||
if (!Helper.areItemsEqual(stack, entry.getKey(), true))
|
||||
continue;
|
||||
entity.setItem(ItemStack.EMPTY);
|
||||
entity.remove();
|
||||
entity.kill();
|
||||
return Pair.of(entry.getValue(), stack.getCount());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,23 +7,28 @@ 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.api.misc.WeightedOre;
|
||||
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.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
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.level.Level;
|
||||
import net.minecraft.level.chunk.Chunk;
|
||||
import net.minecraft.level.server.ServerLevel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.random.WeightedRandom;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
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.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
@ -55,12 +60,12 @@ public class OreSpawnEffect 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.getOnPos(), NAME))
|
||||
return ActiveType.INHIBITED;
|
||||
return ActiveType.ACTIVE;
|
||||
}
|
||||
|
@ -71,7 +76,7 @@ public class OreSpawnEffect 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))
|
||||
|
@ -88,46 +93,48 @@ public class OreSpawnEffect implements IDrainSpotEffect {
|
|||
}
|
||||
int totalWeight = WeightedRandom.getTotalWeight(ores);
|
||||
|
||||
List<Tuple<Vector3d, Integer>> powders = NaturesAuraAPI.instance().getActiveEffectPowders(level,
|
||||
new AxisAlignedBB(pos).grow(this.dist), NAME);
|
||||
List<Tuple<Vec3, Integer>> powders = NaturesAuraAPI.instance().getActiveEffectPowders(level,
|
||||
new AABB(pos).inflate(this.dist), NAME);
|
||||
if (powders.isEmpty())
|
||||
return;
|
||||
for (int i = 0; i < this.amount; i++) {
|
||||
Tuple<Vector3d, Integer> powder = powders.get(i % powders.size());
|
||||
Vector3d powderPos = powder.getA();
|
||||
Tuple<Vec3, Integer> powder = powders.get(i % powders.size());
|
||||
Vec3 powderPos = powder.getA();
|
||||
int range = powder.getB();
|
||||
int x = Mth.floor(powderPos.x + level.rand.nextGaussian() * range);
|
||||
int y = Mth.floor(powderPos.y + level.rand.nextGaussian() * range);
|
||||
int z = Mth.floor(powderPos.z + level.rand.nextGaussian() * range);
|
||||
int x = Mth.floor(powderPos.x + level.random.nextGaussian() * range);
|
||||
int y = Mth.floor(powderPos.y + level.random.nextGaussian() * range);
|
||||
int z = Mth.floor(powderPos.z + level.random.nextGaussian() * range);
|
||||
BlockPos orePos = new BlockPos(x, y, z);
|
||||
if (orePos.distanceSq(powderPos.x, powderPos.y, powderPos.z, true) <= range * range
|
||||
&& orePos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(orePos)) {
|
||||
if (orePos.distSqr(powderPos.x, powderPos.y, powderPos.z, true) <= range * range
|
||||
&& orePos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(orePos)) {
|
||||
BlockState state = level.getBlockState(orePos);
|
||||
if (state.getBlock() != requiredBlock)
|
||||
continue;
|
||||
|
||||
outer:
|
||||
while (true) {
|
||||
WeightedOre ore = WeightedRandom.getRandomItem(level.rand, ores, totalWeight);
|
||||
ITag<Block> tag = level.getTags().func_241835_a().get(ore.tag);
|
||||
WeightedOre ore = WeightedRandom.getRandomItem(level.random, ores, totalWeight).orElse(null);
|
||||
if (ore == null)
|
||||
continue;
|
||||
Tag<Block> tag = level.getTagManager().getOrEmpty(Registry.BLOCK_REGISTRY).getTag(ore.tag);
|
||||
if (tag == null)
|
||||
continue;
|
||||
for (Block toPlace : tag.getAllElements()) {
|
||||
for (Block toPlace : tag.getValues()) {
|
||||
if (toPlace == null || toPlace == Blocks.AIR)
|
||||
continue;
|
||||
|
||||
FakePlayer player = FakePlayerFactory.getMinecraft((ServerLevel) level);
|
||||
player.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
|
||||
BlockRayTraceResult ray = new BlockRayTraceResult(Vector3d.copyCentered(pos), Direction.UP, pos, false);
|
||||
BlockItemUseContext context = new BlockItemUseContext(new ItemUseContext(player, Hand.MAIN_HAND, ray));
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
||||
BlockHitResult ray = new BlockHitResult(Vec3.atCenterOf(pos), Direction.UP, pos, false);
|
||||
BlockPlaceContext context = new BlockPlaceContext(new UseOnContext(player, InteractionHand.MAIN_HAND, ray));
|
||||
BlockState stateToPlace = toPlace.getStateForPlacement(context);
|
||||
if (SPAWN_EXCEPTIONS.contains(stateToPlace))
|
||||
continue;
|
||||
|
||||
level.setBlockState(orePos, stateToPlace);
|
||||
level.playEvent(2001, orePos, Block.getStateId(stateToPlace));
|
||||
level.setBlockAndUpdate(orePos, stateToPlace);
|
||||
level.levelEvent(2001, orePos, Block.getId(stateToPlace));
|
||||
|
||||
int toDrain = (20000 - ore.itemWeight * 2) * 2;
|
||||
int toDrain = (20000 - ore.getWeight().asInt() * 2) * 2;
|
||||
BlockPos highestSpot = IAuraChunk.getHighestSpot(level, orePos, 30, pos);
|
||||
IAuraChunk.getAuraChunk(level, highestSpot).drainAura(highestSpot, toDrain);
|
||||
break outer;
|
||||
|
@ -138,7 +145,7 @@ public class OreSpawnEffect implements IDrainSpotEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
||||
public boolean appliesHere(LevelChunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
||||
return ModConfig.instance.oreEffect.get() &&
|
||||
(type.isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) || type.isSimilar(NaturesAuraAPI.TYPE_NETHER));
|
||||
}
|
||||
|
|
|
@ -1,49 +1,25 @@
|
|||
package de.ellpeck.naturesaura.compat.patchouli;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.multiblock.Matcher;
|
||||
import de.ellpeck.naturesaura.compat.ICompat;
|
||||
import de.ellpeck.naturesaura.data.ItemTagProvider;
|
||||
import de.ellpeck.naturesaura.events.ClientEvents;
|
||||
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler;
|
||||
import de.ellpeck.naturesaura.renderers.SupporterFancyHandler.FancyInfo;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.RecipeManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import vazkii.patchouli.api.BookDrawScreenEvent;
|
||||
import vazkii.patchouli.api.IMultiblock;
|
||||
import vazkii.patchouli.api.IVariable;
|
||||
import vazkii.patchouli.api.PatchouliAPI;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// TODO Patchouli
|
||||
public class PatchouliCompat implements ICompat {
|
||||
|
||||
private static final ResourceLocation BOOK = new ResourceLocation(NaturesAura.MOD_ID, "book");
|
||||
/*
|
||||
private static final Map<ResourceLocation, IMultiblock> MULTIBLOCKS = new HashMap<>();
|
||||
*/
|
||||
|
||||
public static void addPatchouliMultiblock(ResourceLocation name, String[][] pattern, Object... rawMatchers) {
|
||||
for (int i = 1; i < rawMatchers.length; i += 2) {
|
||||
/* for (int i = 1; i < rawMatchers.length; i += 2) {
|
||||
if (rawMatchers[i] instanceof Matcher) {
|
||||
Matcher matcher = (Matcher) rawMatchers[i];
|
||||
Matcher.ICheck check = matcher.getCheck();
|
||||
|
@ -54,30 +30,31 @@ public class PatchouliCompat implements ICompat {
|
|||
state -> check.matches(null, null, null, null, state, (char) 0));
|
||||
}
|
||||
}
|
||||
MULTIBLOCKS.put(name, PatchouliAPI.get().makeMultiblock(pattern, rawMatchers));
|
||||
MULTIBLOCKS.put(name, PatchouliAPI.get().makeMultiblock(pattern, rawMatchers));*/
|
||||
}
|
||||
|
||||
public static <T extends IRecipe<?>> T getRecipe(String type, String name) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Recipe<?>> T getRecipe(String type, String name) {
|
||||
RecipeManager manager = Minecraft.getInstance().level.getRecipeManager();
|
||||
ResourceLocation res = new ResourceLocation(name);
|
||||
ResourceLocation pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
|
||||
return (T) manager.getRecipe(pre).orElse(null);
|
||||
return (T) manager.byKey(pre).orElse(null);
|
||||
}
|
||||
|
||||
public static IVariable ingredientVariable(Ingredient ingredient) {
|
||||
/* public static IVariable ingredientVariable(Ingredient ingredient) {
|
||||
return IVariable.wrapList(Arrays.stream(ingredient.getMatchingStacks())
|
||||
.map(IVariable::from).collect(Collectors.toList()));
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void setup(FMLCommonSetupEvent event) {
|
||||
event.enqueueWork(() -> {
|
||||
/* event.enqueueWork(() -> {
|
||||
for (Map.Entry<ResourceLocation, IMultiblock> entry : MULTIBLOCKS.entrySet())
|
||||
PatchouliAPI.get().registerMultiblock(entry.getKey(), entry.getValue());
|
||||
|
||||
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":rf_converter", ModConfig.instance.rfConverter.get());
|
||||
PatchouliAPI.get().setConfigFlag(NaturesAura.MOD_ID + ":chunk_loader", ModConfig.instance.chunkLoader.get());
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +67,7 @@ public class PatchouliCompat implements ICompat {
|
|||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
/* @SubscribeEvent
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void onBookDraw(BookDrawScreenEvent event) {
|
||||
if (event.book == null || !event.book.equals(BOOK))
|
||||
|
@ -151,5 +128,5 @@ public class PatchouliCompat implements ICompat {
|
|||
event.mouseX, event.mouseY, event.gui.width, event.gui.height, 0, event.gui.getMinecraft().fontRenderer);
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -1,46 +1,45 @@
|
|||
package de.ellpeck.naturesaura.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.Player;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class GuiEnderCrate extends ContainerScreen<ContainerEnderCrate> {
|
||||
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
|
||||
private final Player player;
|
||||
public class GuiEnderCrate extends AbstractContainerScreen<ContainerEnderCrate> {
|
||||
|
||||
public GuiEnderCrate(ContainerEnderCrate container, PlayerInventory inv, ITextComponent title) {
|
||||
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
|
||||
|
||||
public GuiEnderCrate(ContainerEnderCrate container, Inventory inv, Component title) {
|
||||
super(container, inv, title);
|
||||
this.player = inv.player;
|
||||
this.ySize = 114 + 3 * 18;
|
||||
this.imageHeight = 114 + 3 * 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(matrixStack);
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
this.func_230459_a_(matrixStack, mouseX, mouseY);
|
||||
this.renderTooltip(matrixStack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) {
|
||||
this.font.drawString(matrixStack, this.title.getString(), 8, 6, 4210752);
|
||||
this.font.drawString(matrixStack, this.player.inventory.getDisplayName().getString(), 8, this.ySize - 96 + 2, 4210752);
|
||||
protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) {
|
||||
this.font.draw(matrixStack, this.title.getString(), 8, 6, 4210752);
|
||||
this.font.draw(matrixStack, this.playerInventoryTitle, 8, this.imageHeight - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.getMinecraft().getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
|
||||
int i = (this.width - this.xSize) / 2;
|
||||
int j = (this.height - this.ySize) / 2;
|
||||
this.blit(matrixStack, i, j, 0, 0, this.xSize, 3 * 18 + 17);
|
||||
this.blit(matrixStack, i, j + 3 * 18 + 17, 0, 126, this.xSize, 96);
|
||||
protected void renderBg(PoseStack matrixStack, float partialTicks, int mouseX, int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, CHEST_GUI_TEXTURE);
|
||||
int i = (this.width - this.imageWidth) / 2;
|
||||
int j = (this.height - this.imageHeight) / 2;
|
||||
this.blit(matrixStack, i, j, 0, 0, this.imageWidth, 3 * 18 + 17);
|
||||
this.blit(matrixStack, i, j + 3 * 18 + 17, 0, 126, this.imageHeight, 96);
|
||||
}
|
||||
}
|
|
@ -2,19 +2,20 @@ package de.ellpeck.naturesaura.particles;
|
|||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.IParticleRenderType;
|
||||
import net.minecraft.client.ParticleStatus;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.particle.ParticleRenderType;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.settings.ParticleStatus;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -22,17 +23,18 @@ import java.util.function.Supplier;
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public final class ParticleHandler {
|
||||
|
||||
public static final IParticleRenderType MAGIC = new IParticleRenderType() {
|
||||
public static final ParticleRenderType MAGIC = new ParticleRenderType() {
|
||||
|
||||
@Override
|
||||
public void beginRender(BufferBuilder buffer, TextureManager textureManager) {
|
||||
setupRendering(textureManager);
|
||||
public void begin(BufferBuilder buffer, TextureManager textureManager) {
|
||||
setupRendering();
|
||||
RenderSystem.enableDepthTest();
|
||||
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRender(Tessellator tessellator) {
|
||||
tessellator.draw();
|
||||
public void end(Tesselator tessellator) {
|
||||
tessellator.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,17 +43,17 @@ public final class ParticleHandler {
|
|||
}
|
||||
};
|
||||
|
||||
public static final IParticleRenderType MAGIC_NO_DEPTH = new IParticleRenderType() {
|
||||
public static final ParticleRenderType MAGIC_NO_DEPTH = new ParticleRenderType() {
|
||||
@Override
|
||||
public void beginRender(BufferBuilder buffer, TextureManager textureManager) {
|
||||
setupRendering(textureManager);
|
||||
public void begin(BufferBuilder buffer, TextureManager textureManager) {
|
||||
setupRendering();
|
||||
RenderSystem.disableDepthTest();
|
||||
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP);
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishRender(Tessellator tessellator) {
|
||||
tessellator.draw();
|
||||
public void end(Tesselator tessellator) {
|
||||
tessellator.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,32 +68,30 @@ public final class ParticleHandler {
|
|||
|
||||
public static void spawnParticle(Supplier<Particle> particle, double x, double y, double z) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player.getDistanceSq(x, y, z) <= range * range) {
|
||||
if (mc.player.distanceToSqr(x, y, z) <= range * range) {
|
||||
if (culling) {
|
||||
if (ModConfig.instance.respectVanillaParticleSettings.get()) {
|
||||
ParticleStatus setting = mc.gameSettings.particles;
|
||||
ParticleStatus setting = mc.options.particles;
|
||||
if (setting != ParticleStatus.ALL &&
|
||||
(setting != ParticleStatus.DECREASED || mc.level.rand.nextInt(3) != 0) &&
|
||||
(setting != ParticleStatus.MINIMAL || mc.level.rand.nextInt(10) != 0))
|
||||
(setting != ParticleStatus.DECREASED || mc.level.random.nextInt(3) != 0) &&
|
||||
(setting != ParticleStatus.MINIMAL || mc.level.random.nextInt(10) != 0))
|
||||
return;
|
||||
}
|
||||
double setting = ModConfig.instance.particleAmount.get();
|
||||
if (setting < 1 && mc.level.rand.nextDouble() > setting)
|
||||
if (setting < 1 && mc.level.random.nextDouble() > setting)
|
||||
return;
|
||||
}
|
||||
mc.particles.addEffect(particle.get());
|
||||
mc.particleEngine.add(particle.get());
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupRendering(TextureManager textureManager) {
|
||||
RenderSystem.enableAlphaTest();
|
||||
private static void setupRendering() {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.alphaFunc(516, 0.003921569F);
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);
|
||||
RenderSystem.enableFog();
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.depthMask(false);
|
||||
textureManager.bindTexture(ParticleMagic.TEXTURE);
|
||||
RenderSystem.setShader(GameRenderer::getParticleShader);
|
||||
RenderSystem.setShaderTexture(0, ParticleMagic.TEXTURE);
|
||||
}
|
||||
}
|
|
@ -1,23 +1,21 @@
|
|||
package de.ellpeck.naturesaura.particles;
|
||||
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.particle.IParticleRenderType;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.ReuseableStream;
|
||||
import net.minecraft.util.math.Mth;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.vector.Quaternion;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraft.client.particle.ParticleRenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Collections;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ParticleMagic extends Particle {
|
||||
|
@ -32,41 +30,41 @@ public class ParticleMagic extends Particle {
|
|||
public ParticleMagic(ClientLevel level, double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade, boolean depth) {
|
||||
super(level, posX, posY, posZ);
|
||||
this.desiredScale = scale;
|
||||
this.maxAge = maxAge;
|
||||
this.canCollide = collision;
|
||||
this.particleGravity = gravity;
|
||||
this.lifetime = maxAge;
|
||||
this.hasPhysics = collision;
|
||||
this.gravity = gravity;
|
||||
this.fade = fade;
|
||||
this.depth = depth;
|
||||
|
||||
this.motionX = motionX;
|
||||
this.motionY = motionY;
|
||||
this.motionZ = motionZ;
|
||||
this.xd = motionX;
|
||||
this.yd = motionY;
|
||||
this.zd = motionZ;
|
||||
|
||||
float r = (color >> 16 & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F);
|
||||
float g = (color >> 8 & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F);
|
||||
float b = (color & 255) / 255F * (1F - this.rand.nextFloat() * 0.25F);
|
||||
float r = (color >> 16 & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
|
||||
float g = (color >> 8 & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
|
||||
float b = (color & 255) / 255F * (1F - this.random.nextFloat() * 0.25F);
|
||||
this.setColor(r, g, b);
|
||||
|
||||
this.particleAlpha = 1F;
|
||||
this.alpha = 1F;
|
||||
this.particleScale = 0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
this.xo = this.x;
|
||||
this.yo = this.y;
|
||||
this.zo = this.z;
|
||||
|
||||
this.age++;
|
||||
if (this.age > this.maxAge) {
|
||||
this.setExpired();
|
||||
if (this.age > this.lifetime) {
|
||||
this.remove();
|
||||
} else {
|
||||
this.motionY -= 0.04D * (double) this.particleGravity;
|
||||
this.move(this.motionX, this.motionY, this.motionZ);
|
||||
this.yd -= 0.04D * (double) this.gravity;
|
||||
this.move(this.xd, this.yd, this.zd);
|
||||
|
||||
float lifeRatio = (float) this.age / (float) this.maxAge;
|
||||
float lifeRatio = (float) this.age / (float) this.lifetime;
|
||||
if (this.fade && lifeRatio > 0.75F)
|
||||
this.particleAlpha = 1F - (lifeRatio - 0.75F) / 0.25F;
|
||||
this.alpha = 1F - (lifeRatio - 0.75F) / 0.25F;
|
||||
if (lifeRatio <= 0.25F)
|
||||
this.particleScale = this.desiredScale * (lifeRatio / 0.25F);
|
||||
else if (this.fade)
|
||||
|
@ -77,30 +75,30 @@ public class ParticleMagic extends Particle {
|
|||
@Override
|
||||
public void move(double x, double y, double z) {
|
||||
double lastY = y;
|
||||
if (this.canCollide && (x != 0 || y != 0 || z != 0)) {
|
||||
Vector3d motion = Entity.collideBoundingBoxHeuristically(null, new Vector3d(x, y, z), this.getBoundingBox(), this.level, ISelectionContext.dummy(), new ReuseableStream<>(Stream.empty()));
|
||||
if (this.hasPhysics && (x != 0 || y != 0 || z != 0)) {
|
||||
Vec3 motion = Entity.collideBoundingBox(null, new Vec3(x, y, z), this.getBoundingBox(), this.level, Collections.emptyList());
|
||||
x = motion.x;
|
||||
y = motion.y;
|
||||
z = motion.z;
|
||||
}
|
||||
if (x != 0 || y != 0 || z != 0) {
|
||||
this.setBoundingBox(this.getBoundingBox().offset(x, y, z));
|
||||
this.resetPositionToBB();
|
||||
this.setBoundingBox(this.getBoundingBox().move(x, y, z));
|
||||
this.setLocationFromBoundingbox();
|
||||
}
|
||||
this.onGround = lastY != y && lastY < 0;
|
||||
if (this.onGround) {
|
||||
this.motionX = 0;
|
||||
this.motionZ = 0;
|
||||
this.xd = 0;
|
||||
this.zd = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
|
||||
Vector3d vec3d = renderInfo.getProjectedView();
|
||||
float f = (float) (Mth.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX());
|
||||
float f1 = (float) (Mth.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY());
|
||||
float f2 = (float) (Mth.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ());
|
||||
Quaternion quaternion = renderInfo.getRotation();
|
||||
public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) {
|
||||
Vec3 vec3d = renderInfo.getPosition();
|
||||
float f = (float) (Mth.lerp(partialTicks, this.xo, this.x) - vec3d.x);
|
||||
float f1 = (float) (Mth.lerp(partialTicks, this.yo, this.y) - vec3d.y);
|
||||
float f2 = (float) (Mth.lerp(partialTicks, this.zo, this.z) - vec3d.z);
|
||||
Quaternion quaternion = renderInfo.rotation();
|
||||
Vector3f[] avector3f = new Vector3f[]{new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F)};
|
||||
float f4 = 0.1F * this.particleScale;
|
||||
|
||||
|
@ -111,20 +109,20 @@ public class ParticleMagic extends Particle {
|
|||
vector3f.add(f, f1, f2);
|
||||
}
|
||||
|
||||
int j = this.getBrightnessForRender(partialTicks);
|
||||
buffer.pos(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).tex(0, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
|
||||
buffer.pos(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).tex(1, 1).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
|
||||
buffer.pos(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).tex(1, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
|
||||
buffer.pos(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).tex(0, 0).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j).endVertex();
|
||||
int j = this.getLightColor(partialTicks);
|
||||
buffer.vertex(avector3f[0].x(), avector3f[0].y(), avector3f[0].z()).uv(0, 1).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
|
||||
buffer.vertex(avector3f[1].x(), avector3f[1].y(), avector3f[1].z()).uv(1, 1).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
|
||||
buffer.vertex(avector3f[2].x(), avector3f[2].y(), avector3f[2].z()).uv(1, 0).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
|
||||
buffer.vertex(avector3f[3].x(), avector3f[3].y(), avector3f[3].z()).uv(0, 0).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParticleRenderType getRenderType() {
|
||||
public ParticleRenderType getRenderType() {
|
||||
return this.depth ? ParticleHandler.MAGIC : ParticleHandler.MAGIC_NO_DEPTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightnessForRender(float f) {
|
||||
protected int getLightColor(float p_107249_) {
|
||||
return 15 << 20 | 15 << 4;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package de.ellpeck.naturesaura.potion;
|
||||
|
||||
import net.minecraft.potion.Effect;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
|
||||
@SuppressWarnings("FieldNamingConvention")
|
||||
public final class ModPotions {
|
||||
|
||||
public static Effect BREATHLESS;
|
||||
public static MobEffect BREATHLESS;
|
||||
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ public class ClientProxy implements IProxy {
|
|||
MenuScreens.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new);
|
||||
|
||||
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "fill_mode"),
|
||||
(stack, levelIn, entityIn) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F);
|
||||
(stack, levelIn, entityIn, i) -> ItemColorChanger.isFillMode(stack) ? 1F : 0F);
|
||||
ItemProperties.register(ModItems.COLOR_CHANGER, new ResourceLocation(NaturesAura.MOD_ID, "has_color"),
|
||||
(stack, levelIn, entityIn) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F);
|
||||
(stack, levelIn, entityIn, i) -> ItemColorChanger.getStoredColor(stack) != null ? 1F : 0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,9 +3,9 @@ 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.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraftforge.fml.client.registry.IRenderFactory;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
@ -38,7 +38,7 @@ public class ServerProxy implements IProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void registerTESR(ITESRProvider provider) {
|
||||
public void registerTESR(ITESRProvider<?> provider) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class ServerProxy implements IProxy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<IRenderFactory<T>> renderFactory) {
|
||||
public <T extends Entity> void registerEntityRenderer(EntityType<T> entityClass, Supplier<EntityRendererProvider<T>> renderFactory) {
|
||||
|
||||
}
|
||||
}
|
|
@ -3,10 +3,7 @@ package de.ellpeck.naturesaura.recipes;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
|
|
@ -3,17 +3,19 @@ package de.ellpeck.naturesaura.recipes;
|
|||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
|
||||
public class EnabledCondition implements ICondition {
|
||||
|
||||
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled");
|
||||
private ForgeConfigSpec.ConfigValue<Boolean> config;
|
||||
private final String name;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EnabledCondition(String name) {
|
||||
this.name = name;
|
||||
try {
|
||||
|
@ -34,6 +36,7 @@ public class EnabledCondition implements ICondition {
|
|||
}
|
||||
|
||||
public static class Serializer implements IConditionSerializer<EnabledCondition> {
|
||||
|
||||
@Override
|
||||
public void write(JsonObject json, EnabledCondition value) {
|
||||
json.addProperty("config", value.name);
|
||||
|
@ -41,7 +44,7 @@ public class EnabledCondition implements ICondition {
|
|||
|
||||
@Override
|
||||
public EnabledCondition read(JsonObject json) {
|
||||
return new EnabledCondition(JSONUtils.getString(json, "config"));
|
||||
return new EnabledCondition(GsonHelper.getAsString(json, "config"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
package de.ellpeck.naturesaura.renderers;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import net.minecraft.client.CameraType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.PointOfView;
|
||||
import net.minecraft.entity.player.Player;
|
||||
import net.minecraft.entity.player.PlayerModelPart;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.level.biome.BiomeColors;
|
||||
import net.minecraft.client.renderer.BiomeColors;
|
||||
import net.minecraft.world.entity.player.PlayerModelPart;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
@ -22,7 +18,6 @@ import java.io.InputStreamReader;
|
|||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class SupporterFancyHandler {
|
||||
|
@ -38,32 +33,32 @@ public class SupporterFancyHandler {
|
|||
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.END)
|
||||
return;
|
||||
Player player = event.player;
|
||||
var player = event.player;
|
||||
if (!player.level.isClientSide)
|
||||
return;
|
||||
if (player.isInvisible() || !player.isWearing(PlayerModelPart.CAPE))
|
||||
if (player.isInvisible() || !player.isModelPartShown(PlayerModelPart.CAPE))
|
||||
return;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (player == mc.player && mc.gameSettings.func_243230_g() == PointOfView.FIRST_PERSON)
|
||||
var mc = Minecraft.getInstance();
|
||||
if (player == mc.player && mc.options.getCameraType() == CameraType.FIRST_PERSON)
|
||||
return;
|
||||
FancyInfo info = FANCY_INFOS.get(player.getGameProfile().getName());
|
||||
var info = FANCY_INFOS.get(player.getGameProfile().getName());
|
||||
if (info == null)
|
||||
return;
|
||||
|
||||
Random rand = player.level.rand;
|
||||
var rand = player.level.random;
|
||||
if (rand.nextFloat() >= 0.75F) {
|
||||
int color;
|
||||
if (info.tier == 1) {
|
||||
BlockPos pos = player.getPosition();
|
||||
color = BiomeColors.getGrassColor(player.level, pos);
|
||||
var pos = player.getOnPos();
|
||||
color = BiomeColors.getAverageGrassColor(player.level, pos);
|
||||
} else {
|
||||
color = info.color;
|
||||
}
|
||||
|
||||
NaturesAuraAPI.instance().spawnMagicParticle(
|
||||
player.getPosX() + rand.nextGaussian() * 0.15F,
|
||||
player.getPosY() + rand.nextFloat() * 1.8F,
|
||||
player.getPosZ() + rand.nextGaussian() * 0.15F,
|
||||
player.getX() + rand.nextGaussian() * 0.15F,
|
||||
player.getY() + rand.nextFloat() * 1.8F,
|
||||
player.getZ() + rand.nextGaussian() * 0.15F,
|
||||
rand.nextGaussian() * 0.01F,
|
||||
rand.nextFloat() * 0.01F,
|
||||
rand.nextGaussian() * 0.01F,
|
||||
|
@ -71,17 +66,12 @@ public class SupporterFancyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static class FancyInfo {
|
||||
public final int tier;
|
||||
public final int color;
|
||||
public record FancyInfo(int tier, int color) {
|
||||
|
||||
public FancyInfo(int tier, int color) {
|
||||
this.tier = tier;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
private static class FetchThread extends Thread {
|
||||
|
||||
public FetchThread() {
|
||||
this.setName(NaturesAura.MOD_ID + "_support_fetcher");
|
||||
this.setDaemon(true);
|
||||
|
@ -91,15 +81,14 @@ public class SupporterFancyHandler {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
URL url = new URL("https://raw.githubusercontent.com/Ellpeck/NaturesAura/main/supporters.json");
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(url.openStream()));
|
||||
JsonParser parser = new JsonParser();
|
||||
var url = new URL("https://raw.githubusercontent.com/Ellpeck/NaturesAura/main/supporters.json");
|
||||
var reader = new JsonReader(new InputStreamReader(url.openStream()));
|
||||
|
||||
JsonObject main = parser.parse(reader).getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> entry : main.entrySet()) {
|
||||
JsonObject object = entry.getValue().getAsJsonObject();
|
||||
int tier = object.get("tier").getAsInt();
|
||||
int color = object.has("color") ? Integer.parseInt(object.get("color").getAsString(), 16) : 0;
|
||||
var main = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
for (var entry : main.entrySet()) {
|
||||
var object = entry.getValue().getAsJsonObject();
|
||||
var tier = object.get("tier").getAsInt();
|
||||
var color = object.has("color") ? Integer.parseInt(object.get("color").getAsString(), 16) : 0;
|
||||
FANCY_INFOS.put(entry.getKey(), new FancyInfo(tier, color));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue