some more workkkk

This commit is contained in:
Ell 2021-12-04 19:17:21 +01:00
parent cd328cab6a
commit 1880bf785d
71 changed files with 723 additions and 751 deletions

View file

@ -1,73 +1,63 @@
package de.ellpeck.naturesaura; package de.ellpeck.naturesaura;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge; import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import net.minecraft.advancements.Advancement; import net.minecraft.core.BlockPos;
import net.minecraft.block.Block; import net.minecraft.core.Direction;
import net.minecraft.block.BlockState; import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.Minecraft; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.sounds.SoundEvents;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.sounds.SoundSource;
import net.minecraft.entity.player.Player; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.ServerPlayer; import net.minecraft.world.InteractionResult;
import net.minecraft.item.Item; import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.entity.player.Player;
import net.minecraft.nbt.INBT; import net.minecraft.world.item.Item;
import net.minecraft.state.Property; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.*; import net.minecraft.world.level.ChunkPos;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.level.Level;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.ChunkPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.level.ILevel; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.level.Level; import net.minecraft.world.phys.AABB;
import net.minecraft.level.chunk.AbstractChunkProvider; import net.minecraft.world.phys.Vec3;
import net.minecraft.level.chunk.Chunk;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraftforge.registries.IForgeRegistryEntry;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import top.theillusivec4.curios.api.CuriosApi;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
public final class Helper { public final class Helper {
public static boolean getTileEntitiesInArea(ILevel level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) { public static boolean getBlockEntitiesInArea(Level level, BlockPos pos, int radius, Function<BlockEntity, Boolean> consumer) {
for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
Chunk chunk = getLoadedChunk(level, x, z); var chunk = getLoadedChunk(level, x, z);
if (chunk != null) { if (chunk != null) {
for (BlockPos tilePos : chunk.getTileEntitiesPos()) { for (var tilePos : chunk.getBlockEntitiesPos()) {
if (tilePos.distanceSq(pos) <= radius * radius) if (tilePos.distSqr(pos) <= radius * radius)
if (consumer.apply(chunk.getBlockEntity(tilePos))) if (consumer.apply(chunk.getBlockEntity(tilePos)))
return true; return true;
} }
@ -78,77 +68,64 @@ public final class Helper {
} }
public static void getAuraChunksWithSpotsInArea(Level level, BlockPos pos, int radius, Consumer<AuraChunk> consumer) { public static void getAuraChunksWithSpotsInArea(Level level, BlockPos pos, int radius, Consumer<AuraChunk> consumer) {
LevelData data = (LevelData) ILevelData.getLevelData(level); var data = (LevelData) ILevelData.getLevelData(level);
for (int x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) { for (var x = pos.getX() - radius >> 4; x <= pos.getX() + radius >> 4; x++) {
for (int z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) { for (var z = pos.getZ() - radius >> 4; z <= pos.getZ() + radius >> 4; z++) {
AuraChunk chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z)); var chunk = data.auraChunksWithSpots.get(ChunkPos.asLong(x, z));
if (chunk != null) if (chunk != null)
consumer.accept(chunk); consumer.accept(chunk);
} }
} }
} }
public static List<ItemFrameEntity> getAttachedItemFrames(Level level, BlockPos pos) { public static List<ItemFrame> getAttachedItemFrames(Level level, BlockPos pos) {
List<ItemFrameEntity> frames = level.getEntitiesWithinAABB(ItemFrameEntity.class, new AxisAlignedBB(pos).grow(0.25)); var frames = level.getEntitiesOfClass(ItemFrame.class, new AABB(pos).inflate(0.25));
for (int i = frames.size() - 1; i >= 0; i--) { for (var i = frames.size() - 1; i >= 0; i--) {
ItemFrameEntity frame = frames.get(i); var frame = frames.get(i);
BlockPos framePos = frame.getHangingPosition().offset(frame.getHorizontalFacing().getOpposite()); var framePos = frame.getPos().relative(frame.getDirection().getOpposite());
if (!pos.equals(framePos)) if (!pos.equals(framePos))
frames.remove(i); frames.remove(i);
} }
return frames; return frames;
} }
public static Chunk getLoadedChunk(ILevel level, int x, int z) { public static LevelChunk getLoadedChunk(Level level, int x, int z) {
// DO NOT EDIT PLEASE FOR THE LOVE OF GOD // DO NOT EDIT PLEASE FOR THE LOVE OF GOD
// This is very finicky and easily causes the game to hang for some reason // This is very finicky and easily causes the game to hang for some reason
AbstractChunkProvider provider = level.getChunkProvider(); var provider = level.getChunkSource();
if (provider.isChunkLoaded(new ChunkPos(x, z))) if (provider.hasChunk(x, z))
return provider.getChunk(x, z, false); return provider.getChunk(x, z, false);
return null; return null;
} }
public static int blendColors(int c1, int c2, float ratio) { public static int blendColors(int c1, int c2, float ratio) {
int a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio)); var a = (int) ((c1 >> 24 & 0xFF) * ratio + (c2 >> 24 & 0xFF) * (1 - ratio));
int r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio)); var r = (int) ((c1 >> 16 & 0xFF) * ratio + (c2 >> 16 & 0xFF) * (1 - ratio));
int g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio)); var g = (int) ((c1 >> 8 & 0xFF) * ratio + (c2 >> 8 & 0xFF) * (1 - ratio));
int b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio)); var b = (int) ((c1 & 0xFF) * ratio + (c2 & 0xFF) * (1 - ratio));
return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | b & 255; return (a & 255) << 24 | (r & 255) << 16 | (g & 255) << 8 | b & 255;
} }
public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) { public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) {
if (!ItemStack.areItemsEqual(first, second)) if (!ItemStack.isSame(first, second))
return false; return false;
return !nbt || ItemStack.areItemStackTagsEqual(first, second); return !nbt || ItemStack.tagMatches(first, second);
} }
@OnlyIn(Dist.CLIENT) public static InteractionResult putStackOnTile(Player player, InteractionHand hand, BlockPos pos, int slot, boolean sound) {
public static void renderItemInGui(ItemStack stack, int x, int y, float scale) { var tile = player.level.getBlockEntity(pos);
RenderSystem.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.enableDepthTest();
RenderSystem.enableRescaleNormal();
RenderSystem.translatef(x, y, 0);
RenderSystem.scalef(scale, scale, scale);
Minecraft.getInstance().getItemRenderer().renderItemAndEffectIntoGUI(stack, 0, 0);
Minecraft.getInstance().getItemRenderer().renderItemOverlayIntoGUI(Minecraft.getInstance().fontRenderer, stack, 0, 0, null);
RenderSystem.popMatrix();
}
public static InteractionResult putStackOnTile(Player player, Hand hand, BlockPos pos, int slot, boolean sound) {
BlockEntity tile = player.level.getBlockEntity(pos);
if (tile instanceof BlockEntityImpl) { if (tile instanceof BlockEntityImpl) {
IItemHandlerModifiable handler = ((BlockEntityImpl) tile).getItemHandler(); var handler = ((BlockEntityImpl) tile).getItemHandler();
if (handler != null) { if (handler != null) {
ItemStack handStack = player.getHeldItem(hand); var handStack = player.getItemInHand(hand);
if (!handStack.isEmpty()) { if (!handStack.isEmpty()) {
ItemStack remain = handler.insertItem(slot, handStack, player.level.isClientSide); var remain = handler.insertItem(slot, handStack, player.level.isClientSide);
if (!ItemStack.areItemStacksEqual(remain, handStack)) { if (!ItemStack.isSame(remain, handStack)) {
if (sound) if (sound)
player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 0.75F, 1F); SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
if (!player.level.isClientSide) if (!player.level.isClientSide)
player.setHeldItem(hand, remain); player.setItemInHand(hand, remain);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
@ -156,12 +133,12 @@ public final class Helper {
if (!handler.getStackInSlot(slot).isEmpty()) { if (!handler.getStackInSlot(slot).isEmpty()) {
if (sound) if (sound)
player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, player.level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
SoundEvents.ENTITY_ITEM_FRAME_REMOVE_ITEM, SoundCategory.PLAYERS, 0.75F, 1F); SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.PLAYERS, 0.75F, 1F);
if (!player.level.isClientSide) { if (!player.level.isClientSide) {
ItemStack stack = handler.getStackInSlot(slot); var stack = handler.getStackInSlot(slot);
if (!player.addItemStackToInventory(stack)) { if (!player.addItem(stack)) {
ItemEntity item = new ItemEntity(player.level, player.getPosX(), player.getPosY(), player.getPosZ(), stack); var item = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), stack);
player.level.addEntity(item); player.level.addFreshEntity(item);
} }
handler.setStackInSlot(slot, ItemStack.EMPTY); handler.setStackInSlot(slot, ItemStack.EMPTY);
} }
@ -191,8 +168,8 @@ public final class Helper {
} }
public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container, int toDrain) { public static boolean rechargeAuraItem(ItemStack stack, IAuraContainer container, int toDrain) {
if (stack.getDamage() > 0 && container.drainAura(toDrain, true) >= toDrain) { if (stack.getDamageValue() > 0 && container.drainAura(toDrain, true) >= toDrain) {
stack.setDamage(stack.getDamage() - 1); stack.setDamageValue(stack.getDamageValue() - 1);
container.drainAura(toDrain, false); container.drainAura(toDrain, false);
return true; return true;
} }
@ -200,15 +177,15 @@ public final class Helper {
} }
public static BlockState getStateFromString(String raw) { public static BlockState getStateFromString(String raw) {
String[] split = raw.split("\\["); var split = raw.split("\\[");
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); var block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));
if (block != null) { if (block != null) {
BlockState state = block.getDefaultState(); var state = block.defaultBlockState();
if (split.length > 1) { if (split.length > 1) {
for (String part : split[1].replace("]", "").split(",")) { for (var part : split[1].replace("]", "").split(",")) {
String[] keyValue = part.split("="); var keyValue = part.split("=");
for (Property<?> prop : state.getProperties()) { for (var prop : state.getProperties()) {
BlockState changed = findProperty(state, prop, keyValue[0], keyValue[1]); var changed = findProperty(state, prop, keyValue[0], keyValue[1]);
if (changed != null) { if (changed != null) {
state = changed; state = changed;
break; break;
@ -223,39 +200,23 @@ public final class Helper {
private static <T extends Comparable<T>> BlockState findProperty(BlockState state, Property<T> prop, String key, String newValue) { private static <T extends Comparable<T>> BlockState findProperty(BlockState state, Property<T> prop, String key, String newValue) {
if (key.equals(prop.getName())) if (key.equals(prop.getName()))
for (T value : prop.getAllowedValues()) for (var value : prop.getPossibleValues())
if (prop.getName(value).equals(newValue)) if (prop.getName(value).equals(newValue))
return state.with(prop, value); return state.setValue(prop, value);
return null; return null;
} }
public static <T> void registerCap(Class<T> type) {
CapabilityManager.INSTANCE.register(type, new Capability.IStorage<T>() {
@Override
public void readNBT(Capability<T> capability, T instance, Direction side, INBT nbt) {
}
@Nullable
@Override
public INBT writeNBT(Capability capability, Object instance, Direction side) {
return null;
}
}, () -> null);
}
public static void addAdvancement(Player player, ResourceLocation advancement, String criterion) { public static void addAdvancement(Player player, ResourceLocation advancement, String criterion) {
if (!(player instanceof ServerPlayer)) if (!(player instanceof ServerPlayer playerMp))
return; return;
ServerPlayer playerMp = (ServerPlayer) player; var adv = playerMp.getLevel().getServer().getAdvancements().getAdvancement(advancement);
Advancement adv = playerMp.getServerLevel().getServer().getAdvancementManager().getAdvancement(advancement);
if (adv != null) if (adv != null)
playerMp.getAdvancements().grantCriterion(adv, criterion); playerMp.getAdvancements().award(adv, criterion);
} }
public static int getIngredientAmount(Ingredient ingredient) { public static int getIngredientAmount(Ingredient ingredient) {
int highestAmount = 0; var highestAmount = 0;
for (ItemStack stack : ingredient.getMatchingStacks()) for (var stack : ingredient.getItems())
if (stack.getCount() > highestAmount) if (stack.getCount() > highestAmount)
highestAmount = stack.getCount(); highestAmount = stack.getCount();
return highestAmount; return highestAmount;
@ -290,8 +251,8 @@ public final class Helper {
} }
public static boolean isHoldingItem(Player player, Item item) { public static boolean isHoldingItem(Player player, Item item) {
for (Hand hand : Hand.values()) { for (var hand : InteractionHand.values()) {
ItemStack stack = player.getHeldItem(hand); var stack = player.getItemInHand(hand);
if (!stack.isEmpty() && stack.getItem() == item) if (!stack.isEmpty() && stack.getItem() == item)
return true; return true;
} }
@ -299,22 +260,22 @@ public final class Helper {
} }
public static boolean isEmpty(IItemHandler handler) { public static boolean isEmpty(IItemHandler handler) {
for (int i = 0; i < handler.getSlots(); i++) for (var i = 0; i < handler.getSlots(); i++)
if (!handler.getStackInSlot(i).isEmpty()) if (!handler.getStackInSlot(i).isEmpty())
return false; return false;
return true; return true;
} }
public static AxisAlignedBB aabb(Vector3d pos) { public static AABB aabb(Vec3 pos) {
return new AxisAlignedBB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z); return new AABB(pos.x, pos.y, pos.z, pos.x, pos.y, pos.z);
} }
// This is how @ObjectHolder _SHOULD_ work... // This is how @ObjectHolder SHOULD work...
public static <T extends IForgeRegistryEntry<T>> void populateObjectHolders(Class clazz, IForgeRegistry<T> registry) { public static <T extends IForgeRegistryEntry<T>> void populateObjectHolders(Class<?> clazz, IForgeRegistry<T> registry) {
for (Field entry : clazz.getFields()) { for (var entry : clazz.getFields()) {
if (!Modifier.isStatic(entry.getModifiers())) if (!Modifier.isStatic(entry.getModifiers()))
continue; continue;
ResourceLocation location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT)); var location = new ResourceLocation(NaturesAura.MOD_ID, entry.getName().toLowerCase(Locale.ROOT));
if (!registry.containsKey(location)) { if (!registry.containsKey(location)) {
NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry " + registry.getRegistryName()); NaturesAura.LOGGER.fatal("Couldn't find entry named " + location + " in registry " + registry.getRegistryName());
continue; continue;
@ -328,13 +289,14 @@ public final class Helper {
} }
public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player) { public static ItemStack getEquippedItem(Predicate<ItemStack> predicate, Player player) {
if (Compat.hasCompat("curios")) { // TODO Curios
/* if (Compat.hasCompat("curios")) {
Optional<ItemStack> stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight); Optional<ItemStack> stack = CuriosApi.getCuriosHelper().findEquippedCurio(predicate, player).map(ImmutableTriple::getRight);
if (stack.isPresent()) if (stack.isPresent())
return stack.get(); return stack.get();
} }*/
for (int i = 0; i < player.inventory.getSizeInventory(); i++) { for (var i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack slot = player.inventory.getStackInSlot(i); var slot = player.getInventory().getItem(i);
if (!slot.isEmpty() && predicate.test(slot)) if (!slot.isEmpty() && predicate.test(slot))
return slot; return slot;
} }

View file

@ -17,11 +17,10 @@ import de.ellpeck.naturesaura.proxy.IProxy;
import de.ellpeck.naturesaura.proxy.ServerProxy; import de.ellpeck.naturesaura.proxy.ServerProxy;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.item.ItemGroup; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@ -37,9 +36,9 @@ public final class NaturesAura {
public static final String MOD_NAME = "Nature's Aura"; public static final String MOD_NAME = "Nature's Aura";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME); public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final ItemGroup CREATIVE_TAB = new ItemGroup(MOD_ID) { public static final CreativeModeTab CREATIVE_TAB = new CreativeModeTab(MOD_ID) {
@Override @Override
public ItemStack createIcon() { public ItemStack makeIcon() {
return new ItemStack(ModItems.GOLD_LEAF); return new ItemStack(ModItems.GOLD_LEAF);
} }
}; };

View file

@ -1,9 +1,9 @@
package de.ellpeck.naturesaura.api.misc; package de.ellpeck.naturesaura.api.misc;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.WeightedRandom; import net.minecraft.util.random.WeightedEntry;
public class WeightedOre extends WeightedRandom.Item { public class WeightedOre extends WeightedEntry.IntrusiveBase {
public final ResourceLocation tag; public final ResourceLocation tag;

View file

@ -1,11 +1,11 @@
package de.ellpeck.naturesaura.api.multiblock; package de.ellpeck.naturesaura.api.multiblock;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.tags.Tag;
import net.minecraft.block.Blocks; import net.minecraft.world.level.Level;
import net.minecraft.tags.ITag; import net.minecraft.world.level.block.Block;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Blocks;
import net.minecraft.level.Level; import net.minecraft.world.level.block.state.BlockState;
public class Matcher { public class Matcher {
@ -18,11 +18,11 @@ public class Matcher {
} }
public static Matcher wildcard() { public static Matcher wildcard() {
return new Matcher(Blocks.AIR.getDefaultState(), null); return new Matcher(Blocks.AIR.defaultBlockState(), null);
} }
public static Matcher tag(Block defaultBlock, ITag.INamedTag tag) { public static Matcher tag(Block defaultBlock, Tag.Named<?> tag) {
return new Matcher(defaultBlock.getDefaultState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName())); return new Matcher(defaultBlock.defaultBlockState(), (level, start, offset, pos, state, c) -> state.getBlock().getTags().contains(tag.getName()));
} }
public BlockState getDefaultState() { public BlockState getDefaultState() {
@ -34,6 +34,7 @@ public class Matcher {
} }
public interface ICheck { public interface ICheck {
boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c); boolean matches(Level level, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);
} }
} }

View file

@ -17,7 +17,7 @@ import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -51,7 +51,7 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC) if (entity.level.isClientSide || !(entity instanceof AnimalEntity) || entity instanceof IMob || entity instanceof INPC)
return; return;
BlockPos pos = entity.getPosition(); BlockPos pos = entity.getPosition();
Helper.getTileEntitiesInArea(entity.level, pos, 5, tile -> { Helper.getBlockEntitiesInArea(entity.level, pos, 5, tile -> {
if (!(tile instanceof BlockEntityAnimalGenerator)) if (!(tile instanceof BlockEntityAnimalGenerator))
return false; return false;
BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile; BlockEntityAnimalGenerator gen = (BlockEntityAnimalGenerator) tile;
@ -67,8 +67,8 @@ public class BlockAnimalGenerator extends BlockContainerImpl implements IVisuali
float amountMod = child ? 0.667F : 1; float amountMod = child ? 0.667F : 1;
int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive"); int timeAlive = data.getInt(NaturesAura.MOD_ID + ":time_alive");
int time = Math.min(MathHelper.floor((timeAlive - 15000) / 500F * timeMod), 200); int time = Math.min(Mth.floor((timeAlive - 15000) / 500F * timeMod), 200);
int amount = Math.min(MathHelper.floor((timeAlive - 8000) / 2F * amountMod), 25000); int amount = Math.min(Mth.floor((timeAlive - 8000) / 2F * amountMod), 25000);
if (time <= 0 || amount <= 0) if (time <= 0 || amount <= 0)
return false; return false;
gen.setGenerationValues(time, amount); gen.setGenerationValues(time, amount);

View file

@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
@ -68,7 +68,7 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
BlockEntity tile = levelIn.getBlockEntity(pos); BlockEntity tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityChunkLoader) { if (tile instanceof BlockEntityChunkLoader) {
int range = ((BlockEntityChunkLoader) tile).range(); int range = ((BlockEntityChunkLoader) tile).range();
for (int i = MathHelper.ceil(range / 8F); i > 0; i--) { for (int i = Mth.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(), pos.getX() + levelIn.rand.nextFloat(), pos.getY() + levelIn.rand.nextFloat(), pos.getZ() + levelIn.rand.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true); 0, 0, 0, 0xa12dff, 1F + levelIn.rand.nextFloat(), 100, 0, false, true);

View file

@ -19,7 +19,7 @@ import net.minecraft.util.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
@ -135,7 +135,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
ItemStack stack = handler.getStackInSlot(0); ItemStack stack = handler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
return MathHelper.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15); return Mth.ceil(stack.getCount() / (float) stack.getMaxStackSize() * 15);
} else } else
return 0; return 0;
} }

View file

@ -36,7 +36,7 @@ public class BlockOakGenerator extends BlockContainerImpl implements IVisualizab
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD) if (level instanceof Level && !level.isClientSide() && IAuraType.forLevel(level).isSimilar(NaturesAuraAPI.TYPE_OVERWORLD)
&& level.getBlockState(pos).getBlock() instanceof SaplingBlock) { && level.getBlockState(pos).getBlock() instanceof SaplingBlock) {
Helper.getTileEntitiesInArea(level, pos, 10, tile -> { Helper.getBlockEntitiesInArea(level, pos, 10, tile -> {
if (!(tile instanceof BlockEntityOakGenerator)) if (!(tile instanceof BlockEntityOakGenerator))
return false; return false;

View file

@ -34,7 +34,7 @@ public class BlockPickupStopper extends BlockContainerImpl implements IVisualiza
if (player != null && !player.isSneaking()) { if (player != null && !player.isSneaking()) {
ItemEntity item = event.getItem(); ItemEntity item = event.getItem();
BlockPos pos = item.getPosition(); BlockPos pos = item.getPosition();
Helper.getTileEntitiesInArea(item.level, pos, 8, tile -> { Helper.getBlockEntitiesInArea(item.level, pos, 8, tile -> {
if (!(tile instanceof BlockEntityPickupStopper)) if (!(tile instanceof BlockEntityPickupStopper))
return false; return false;
BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) tile; BlockEntityPickupStopper stopper = (BlockEntityPickupStopper) tile;

View file

@ -54,7 +54,7 @@ public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVis
int size = slime.getSlimeSize(); int size = slime.getSlimeSize();
if (size <= 1) if (size <= 1)
return; return;
Helper.getTileEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> { Helper.getBlockEntitiesInArea(entity.level, entity.getPosition(), 8, tile -> {
if (!(tile instanceof BlockEntitySlimeSplitGenerator)) if (!(tile instanceof BlockEntitySlimeSplitGenerator))
return false; return false;
BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) tile; BlockEntitySlimeSplitGenerator gen = (BlockEntitySlimeSplitGenerator) tile;

View file

@ -8,12 +8,12 @@ import de.ellpeck.naturesaura.blocks.BlockNatureAltar;
import de.ellpeck.naturesaura.blocks.ModBlocks; import de.ellpeck.naturesaura.blocks.ModBlocks;
import de.ellpeck.naturesaura.data.BlockTagProvider; import de.ellpeck.naturesaura.data.BlockTagProvider;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.block.Blocks; import net.minecraft.resources.ResourceLocation;
import net.minecraft.block.SaplingBlock;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.material.Material;
public final class Multiblocks { public final class Multiblocks {
@ -38,23 +38,23 @@ public final class Multiblocks {
'B', Blocks.NETHER_BRICKS, 'B', Blocks.NETHER_BRICKS,
'W', Matcher.tag(Blocks.CRIMSON_PLANKS, BlockTagProvider.NETHER_ALTAR_WOOD), 'W', Matcher.tag(Blocks.CRIMSON_PLANKS, BlockTagProvider.NETHER_ALTAR_WOOD),
'M', ModBlocks.GOLD_NETHER_BRICK, 'M', ModBlocks.GOLD_NETHER_BRICK,
'0', ModBlocks.NATURE_ALTAR.getDefaultState().with(BlockNatureAltar.NETHER, true), '0', ModBlocks.NATURE_ALTAR.defaultBlockState().setValue(BlockNatureAltar.NETHER, true),
' ', Matcher.wildcard()); ' ', Matcher.wildcard());
public static final IMultiblock TREE_RITUAL = NaturesAuraAPI.instance().createMultiblock( public static final IMultiblock TREE_RITUAL = NaturesAuraAPI.instance().createMultiblock(
new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"), new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"),
new String[][]{ new String[][]{
{" W ", " W W ", " GGG ", " GG GG ", "W G 0 G W", " GG GG ", " GGG ", " W W ", " W "}}, {" W ", " W W ", " GGG ", " GG GG ", "W G 0 G W", " GG GG ", " GGG ", " W W ", " W "}},
'W', new Matcher(ModBlocks.WOOD_STAND.getDefaultState(), 'W', new Matcher(ModBlocks.WOOD_STAND.defaultBlockState(),
(level, start, offset, pos, state, c) -> level != null || state.getBlock() == ModBlocks.WOOD_STAND), (level, start, offset, pos, state, c) -> level != null || state.getBlock() == ModBlocks.WOOD_STAND),
'G', ModBlocks.GOLD_POWDER, 'G', ModBlocks.GOLD_POWDER,
'0', new Matcher(Blocks.OAK_SAPLING.getDefaultState(), '0', new Matcher(Blocks.OAK_SAPLING.defaultBlockState(),
(level, start, offset, pos, state, c) -> { (level, start, offset, pos, state, c) -> {
if (state.getBlock() instanceof SaplingBlock || state.getMaterial() == Material.WOOD) if (state.getBlock() instanceof SaplingBlock || state.getMaterial() == Material.WOOD)
return true; return true;
// try-catch to prevent blocks that need to have been placed crashing here // try-catch to prevent blocks that need to have been placed crashing here
try { try {
ItemStack stack = state.getBlock().getItem(level, pos, state); ItemStack stack = state.getBlock().getCloneItemStack(level, pos, state);
return !stack.isEmpty() && level.getRecipeManager().getRecipes(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack)); return !stack.isEmpty() && level.getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null).stream().anyMatch(r -> r.saplingType.test(stack));
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
@ -76,7 +76,7 @@ public final class Multiblocks {
new ResourceLocation(NaturesAura.MOD_ID, "offering_table"), new ResourceLocation(NaturesAura.MOD_ID, "offering_table"),
new String[][]{ new String[][]{
{" RRRRR ", " R R ", "R RRR R", "R R R R", "R R 0 R R", "R R R R", "R RRR R", " R R ", " RRRRR "}}, {" RRRRR ", " R R ", "R RRR R", "R R R R", "R R 0 R R", "R R R R", "R RRR R", " R R ", " RRRRR "}},
'R', new Matcher(Blocks.POPPY.getDefaultState(), 'R', new Matcher(Blocks.POPPY.defaultBlockState(),
(level, start, offset, pos, state, c) -> BlockTags.SMALL_FLOWERS.contains(state.getBlock())), (level, start, offset, pos, state, c) -> BlockTags.SMALL_FLOWERS.contains(state.getBlock())),
'0', ModBlocks.OFFERING_TABLE, '0', ModBlocks.OFFERING_TABLE,
' ', Matcher.wildcard()); ' ', Matcher.wildcard());

View file

@ -3,16 +3,11 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.entity.passive.Animal;
import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.AABB;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
public class BlockEntityAnimalContainer extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityAnimalContainer extends BlockEntityImpl implements ITickableBlockEntity {
@ -35,19 +30,19 @@ public class BlockEntityAnimalContainer extends BlockEntityImpl implements ITick
public void tick() { public void tick() {
if (this.level.isClientSide) if (this.level.isClientSide)
return; return;
int radius = this.getRadius(); var radius = this.getRadius();
Set<Animal> animalsInRange = new HashSet<>(this.level.getEntitiesWithinAABB(Animal.class, new AxisAlignedBB(this.worldPosition).grow(radius - 1))); Set<Animal> animalsInRange = new HashSet<>(this.level.getEntitiesOfClass(Animal.class, new AABB(this.worldPosition).inflate(radius - 1)));
List<Animal> animalsOutRange = this.level.getEntitiesWithinAABB(Animal.class, new AxisAlignedBB(this.worldPosition).grow(radius + 1)); var animalsOutRange = this.level.getEntitiesOfClass(Animal.class, new AABB(this.worldPosition).inflate(radius + 1));
for (Animal animal : animalsOutRange) { for (var animal : animalsOutRange) {
if (animalsInRange.contains(animal)) if (animalsInRange.contains(animal))
continue; continue;
Vec3 pos = animal.position(); var pos = animal.position();
Vec3 distance = pos.subtract(this.worldPosition.getX(), pos.y, this.worldPosition.getZ()); var distance = pos.subtract(this.worldPosition.getX(), pos.y, this.worldPosition.getZ());
distance = distance.normalize().scale(-0.15F); distance = distance.normalize().scale(-0.15F);
animal.setMotion(distance); animal.setDeltaMovement(distance);
if (this.level.rand.nextBoolean()) { if (this.level.random.nextBoolean()) {
Vec3 eye = animal.getEyePosition(1).add(animal.getLookAngle()); var eye = animal.getEyePosition(1).add(animal.getLookAngle());
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) eye.x, (float) eye.y, (float) eye.z, PacketParticles.Type.ANIMAL_CONTAINER)); new PacketParticles((float) eye.x, (float) eye.y, (float) eye.z, PacketParticles.Type.ANIMAL_CONTAINER));
} }

View file

@ -1,18 +1,17 @@
package de.ellpeck.naturesaura.blocks.tiles; 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.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityAnimalGenerator extends BlockEntityImpl implements ITickableBlockEntity {
private int timeRemaining; private int timeRemaining;
private int amountToRelease; private int amountToRelease;
public BlockEntityAnimalGenerator() { public BlockEntityAnimalGenerator(BlockPos pos, BlockState state) {
super(ModTileEntities.ANIMAL_GENERATOR); super(ModTileEntities.ANIMAL_GENERATOR, pos, state);
} }
@Override @Override

View file

@ -9,16 +9,16 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe; import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.entity.Entity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.Mth;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -32,8 +32,8 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
private int time; private int time;
private Entity entityClient; private Entity entityClient;
public BlockEntityAnimalSpawner() { public BlockEntityAnimalSpawner(BlockPos pos, BlockState state) {
super(ModTileEntities.ANIMAL_SPAWNER); super(ModTileEntities.ANIMAL_SPAWNER, pos, state);
} }
@Override @Override
@ -51,29 +51,29 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
int drain = MathHelper.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F); int drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F);
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain);
this.time += 10; this.time += 10;
if (this.time >= this.currentRecipe.time) { if (this.time >= this.currentRecipe.time) {
Entity entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ)); Entity entity = this.currentRecipe.makeEntity(this.level, new BlockPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ));
this.level.addEntity(entity); this.level.addFreshEntity(entity);
this.currentRecipe = null; this.currentRecipe = null;
this.time = 0; this.time = 0;
this.sendToClients(); this.sendToClients();
} }
} else { } else {
List<ItemEntity> items = this.level.getEntitiesWithinAABB(ItemEntity.class, List<ItemEntity> items = this.level.getEntitiesOfClass(ItemEntity.class,
new AxisAlignedBB(this.worldPosition).grow(2)); new AABB(this.worldPosition).inflate(2));
for (AnimalSpawnerRecipe recipe : this.level.getRecipeManager().getRecipes(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) { for (AnimalSpawnerRecipe recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, null)) {
if (recipe.ingredients.length != items.size()) if (recipe.ingredients.length != items.size())
continue; continue;
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
for (ItemEntity item : items) { for (ItemEntity item : items) {
if (!item.isAlive() || item.cannotPickup()) if (!item.isAlive() || item.hasPickUpDelay())
break; break;
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (stack.isEmpty()) if (stack.isEmpty())
@ -89,14 +89,14 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
continue; continue;
for (ItemEntity item : items) { for (ItemEntity item : items) {
item.remove(); item.remove(Entity.RemovalReason.KILLED);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.ANIMAL_SPAWNER)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.ANIMAL_SPAWNER));
} }
this.currentRecipe = recipe; this.currentRecipe = recipe;
this.spawnX = this.worldPosition.getX() + 0.5 + this.level.rand.nextFloat() * 4 - 2; this.spawnX = this.worldPosition.getX() + 0.5 + this.level.random.nextFloat() * 4 - 2;
this.spawnZ = this.worldPosition.getZ() + 0.5 + this.level.rand.nextFloat() * 4 - 2; this.spawnZ = this.worldPosition.getZ() + 0.5 + this.level.random.nextFloat() * 4 - 2;
this.sendToClients(); this.sendToClients();
break; break;
} }
@ -110,26 +110,26 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
NaturesAuraAPI.instance().spawnParticleStream( NaturesAuraAPI.instance().spawnParticleStream(
this.worldPosition.getX() + (float) this.level.rand.nextGaussian() * 5F, this.worldPosition.getX() + (float) this.level.random.nextGaussian() * 5F,
this.worldPosition.getY() + 1 + this.level.rand.nextFloat() * 5F, this.worldPosition.getY() + 1 + this.level.random.nextFloat() * 5F,
this.worldPosition.getZ() + (float) this.level.rand.nextGaussian() * 5F, this.worldPosition.getZ() + (float) this.level.random.nextGaussian() * 5F,
this.worldPosition.getX() + this.level.rand.nextFloat(), this.worldPosition.getX() + this.level.random.nextFloat(),
this.worldPosition.getY() + this.level.rand.nextFloat(), this.worldPosition.getY() + this.level.random.nextFloat(),
this.worldPosition.getZ() + this.level.rand.nextFloat(), this.worldPosition.getZ() + this.level.random.nextFloat(),
this.level.rand.nextFloat() * 0.07F + 0.07F, this.level.random.nextFloat() * 0.07F + 0.07F,
IAuraType.forLevel(this.level).getColor(), IAuraType.forLevel(this.level).getColor(),
this.level.rand.nextFloat() + 0.5F); this.level.random.nextFloat() + 0.5F);
if (this.entityClient == null) { if (this.entityClient == null) {
this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO); this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO);
this.entityClient.setPosition(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ); this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ);
} }
AxisAlignedBB bounds = this.entityClient.getBoundingBox(); AABB bounds = this.entityClient.getBoundingBox();
for (int i = this.level.rand.nextInt(5) + 5; i >= 0; i--) for (int i = this.level.random.nextInt(5) + 5; i >= 0; i--)
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
bounds.minX + this.level.rand.nextFloat() * (bounds.maxX - bounds.minX), bounds.minX + this.level.random.nextFloat() * (bounds.maxX - bounds.minX),
bounds.minY + this.level.rand.nextFloat() * (bounds.maxY - bounds.minY), bounds.minY + this.level.random.nextFloat() * (bounds.maxY - bounds.minY),
bounds.minZ + this.level.rand.nextFloat() * (bounds.maxZ - bounds.minZ), bounds.minZ + this.level.random.nextFloat() * (bounds.maxZ - bounds.minZ),
0F, 0F, 0F, 0x2fd8d3, 2F, 60, 0F, false, true); 0F, 0F, 0F, 0x2fd8d3, 2F, 60, 0F, false, true);
} }
} }
@ -154,7 +154,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) { if (this.hasLevel()) {
ResourceLocation name = new ResourceLocation(compound.getString("recipe")); ResourceLocation name = new ResourceLocation(compound.getString("recipe"));
this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().getRecipe(name).orElse(null); this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(name).orElse(null);
} }
this.spawnX = compound.getDouble("spawn_x"); this.spawnX = compound.getDouble("spawn_x");
this.spawnZ = compound.getDouble("spawn_z"); this.spawnZ = compound.getDouble("spawn_z");

View file

@ -5,21 +5,20 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticleStream;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.SoundCategory; import net.minecraft.world.level.Level;
import net.minecraft.util.SoundEvents; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.level.Level; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
@ -40,8 +39,8 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
private BlockPos ritualPos; private BlockPos ritualPos;
private int timer; private int timer;
public BlockEntityWoodStand() { public BlockEntityWoodStand(BlockPos pos, BlockState state) {
super(ModTileEntities.WOOD_STAND); super(ModTileEntities.WOOD_STAND, pos, state);
} }
public void setRitual(BlockPos pos, TreeRitualRecipe recipe) { public void setRitual(BlockPos pos, TreeRitualRecipe recipe) {
@ -64,11 +63,11 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
BlockEntity tile = this.level.getBlockEntity(pos); BlockEntity tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand && !((BlockEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) { if (tile instanceof BlockEntityWoodStand && !((BlockEntityWoodStand) tile).items.getStackInSlot(0).isEmpty()) {
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream( PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticleStream(
(float) pos.getX() + 0.2F + this.level.rand.nextFloat() * 0.6F, (float) pos.getX() + 0.2F + this.level.random.nextFloat() * 0.6F,
(float) pos.getY() + 0.85F, (float) pos.getY() + 0.85F,
(float) pos.getZ() + 0.2F + this.level.rand.nextFloat() * 0.6F, (float) pos.getZ() + 0.2F + this.level.random.nextFloat() * 0.6F,
this.ritualPos.getX() + 0.5F, this.ritualPos.getY() + this.level.rand.nextFloat() * 3F + 2F, this.ritualPos.getZ() + 0.5F, this.ritualPos.getX() + 0.5F, this.ritualPos.getY() + this.level.random.nextFloat() * 3F + 2F, this.ritualPos.getZ() + 0.5F,
this.level.rand.nextFloat() * 0.04F + 0.04F, 0x89cc37, this.level.rand.nextFloat() * 1F + 1F this.level.random.nextFloat() * 0.04F + 0.04F, 0x89cc37, this.level.random.nextFloat() + 1F
)); ));
} }
return true; return true;
@ -79,7 +78,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (this.timer >= this.recipe.time) { if (this.timer >= this.recipe.time) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> {
this.level.setBlockState(pos, Blocks.AIR.getDefaultState()); this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true; return true;
}); });
recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false); recurseTreeDestruction(this.level, this.ritualPos, this.ritualPos, true, false);
@ -87,12 +86,12 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
ItemEntity item = new ItemEntity(this.level, ItemEntity item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5, this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
this.recipe.result.copy()); this.recipe.result.copy());
this.level.addEntity(item); this.level.addFreshEntity(item);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
new PacketParticles((float) item.getPosX(), (float) item.getPosY(), (float) item.getPosZ(), PacketParticles.Type.TR_SPAWN_RESULT)); new PacketParticles((float) item.getX(), (float) item.getY(), (float) item.getZ(), PacketParticles.Type.TR_SPAWN_RESULT));
this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5, this.level.playSound(null, this.worldPosition.getX() + 0.5, this.worldPosition.getY() + 0.5, this.worldPosition.getZ() + 0.5,
SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 0.65F, 1F); SoundEvents.ENDERMAN_TELEPORT, SoundSource.BLOCKS, 0.65F, 1F);
this.ritualPos = null; this.ritualPos = null;
this.recipe = null; this.recipe = null;
@ -100,17 +99,14 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
} else if (isOverHalf && !wasOverHalf) { } else if (isOverHalf && !wasOverHalf) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
BlockEntity tile = this.level.getBlockEntity(pos); BlockEntity tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand) { if (tile instanceof BlockEntityWoodStand stand && !stand.items.getStackInSlot(0).isEmpty()) {
BlockEntityWoodStand stand = (BlockEntityWoodStand) tile; PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
if (!stand.items.getStackInSlot(0).isEmpty()) { new PacketParticles(stand.worldPosition.getX(), stand.worldPosition.getY(), stand.worldPosition.getZ(), PacketParticles.Type.TR_CONSUME_ITEM));
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, this.level.playSound(null, stand.worldPosition.getX() + 0.5, stand.worldPosition.getY() + 0.5, stand.worldPosition.getZ() + 0.5,
new PacketParticles(stand.pos.getX(), stand.pos.getY(), stand.pos.getZ(), PacketParticles.Type.TR_CONSUME_ITEM)); SoundEvents.WOOD_STEP, SoundSource.BLOCKS, 0.5F, 1F);
this.level.playSound(null, stand.pos.getX() + 0.5, stand.pos.getY() + 0.5, stand.pos.getZ() + 0.5,
SoundEvents.BLOCK_WOOD_STEP, SoundCategory.BLOCKS, 0.5F, 1F);
stand.items.setStackInSlot(0, ItemStack.EMPTY); stand.items.setStackInSlot(0, ItemStack.EMPTY);
stand.sendToClients(); stand.sendToClients();
}
} }
return true; return true;
}); });
@ -136,14 +132,14 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
for (int x = -1; x <= 1; x++) { for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) { for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) { for (int z = -1; z <= 1; z++) {
BlockPos offset = pos.add(x, y, z); BlockPos offset = pos.offset(x, y, z);
BlockState state = level.getBlockState(offset); BlockState state = level.getBlockState(offset);
if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) { if (state.getBlock().getTags().contains(BlockTags.LOGS.getName()) || includeLeaves && state.getBlock() instanceof LeavesBlock) {
if (drop) { if (drop) {
level.destroyBlock(offset, true); level.destroyBlock(offset, true);
} else { } else {
// in this case we don't want the particles, so we can't use destroyBlock // in this case we don't want the particles, so we can't use destroyBlock
level.setBlockState(offset, Blocks.AIR.getDefaultState()); level.setBlockAndUpdate(offset, Blocks.AIR.defaultBlockState());
PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.TR_DISAPPEAR)); PacketHandler.sendToAllAround(level, pos, 32, new PacketParticles(offset.getX(), offset.getY(), offset.getZ(), PacketParticles.Type.TR_DISAPPEAR));
} }
recurseTreeDestruction(level, offset, start, includeLeaves, drop); recurseTreeDestruction(level, offset, start, includeLeaves, drop);
@ -158,7 +154,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
return false; return false;
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
BlockState state = this.level.getBlockState(this.ritualPos.up(i)); BlockState state = this.level.getBlockState(this.ritualPos.above(i));
if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName()))) if (!(state.getBlock().getTags().contains(BlockTags.LOGS.getName())))
return false; return false;
} }
@ -194,7 +190,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
compound.putLong("ritual_pos", this.ritualPos.toLong()); compound.putLong("ritual_pos", this.ritualPos.asLong());
compound.putInt("timer", this.timer); compound.putInt("timer", this.timer);
compound.putString("recipe", this.recipe.name.toString()); compound.putString("recipe", this.recipe.name.toString());
} }
@ -209,10 +205,10 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
this.ritualPos = BlockPos.fromLong(compound.getLong("ritual_pos")); this.ritualPos = BlockPos.of(compound.getLong("ritual_pos"));
this.timer = compound.getInt("timer"); this.timer = compound.getInt("timer");
if (this.hasLevel()) if (this.hasLevel())
this.recipe = (TreeRitualRecipe) this.level.getRecipeManager().getRecipe(new ResourceLocation(compound.getString("recipe"))).orElse(null); this.recipe = (TreeRitualRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
} }
} }
} }

View file

@ -0,0 +1,7 @@
package de.ellpeck.naturesaura.blocks.tiles;
public interface ITickableBlockEntity {
void tick();
}

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickableBlockEntity {
@ -16,7 +16,7 @@ public class BlockEntityAuraDetector extends BlockEntityImpl implements ITickabl
public void tick() { public void tick() {
if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) { if (!this.level.isClientSide && this.level.getGameTime() % 20 == 0) {
int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25); int totalAmount = IAuraChunk.triangulateAuraInArea(this.level, this.worldPosition, 25);
int power = MathHelper.clamp(MathHelper.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); int power = Mth.clamp(Mth.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15);
if (this.redstonePower != power) { if (this.redstonePower != power) {
this.redstonePower = power; this.redstonePower = power;
this.level.updateComparatorOutputLevel(this.worldPosition, this.getBlockState().getBlock()); this.level.updateComparatorOutputLevel(this.worldPosition, this.getBlockState().getBlock());

View file

@ -6,7 +6,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.server.ServerLevel; import net.minecraft.level.server.ServerLevel;
import java.util.ArrayList; import java.util.ArrayList;
@ -88,7 +88,7 @@ public class BlockEntityChunkLoader extends BlockEntityImpl implements ITickable
if (this.level.getGameTime() % 20 != 0) if (this.level.getGameTime() % 20 != 0)
return; return;
int toUse = MathHelper.ceil(this.range() / 2F); int toUse = Mth.ceil(this.range() / 2F);
if (toUse > 0) { if (toUse > 0) {
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 35, this.worldPosition);
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, toUse);

View file

@ -17,7 +17,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.server.ServerLevel; import net.minecraft.level.server.ServerLevel;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -102,12 +102,12 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
); );
double length = dist.length(); double length = dist.length();
Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length); Vector3d normal = new Vector3d(dist.x / length, dist.y / length, dist.z / length);
for (float i = MathHelper.floor(length); i > 0; i -= 0.5F) { for (float i = Mth.floor(length); i > 0; i -= 0.5F) {
Vector3d scaled = normal.scale(i); Vector3d scaled = normal.scale(i);
BlockPos pos = connectedPos.add( BlockPos pos = connectedPos.add(
MathHelper.floor(scaled.x + 0.5F), Mth.floor(scaled.x + 0.5F),
MathHelper.floor(scaled.y + 0.5F), Mth.floor(scaled.y + 0.5F),
MathHelper.floor(scaled.z + 0.5F)); Mth.floor(scaled.z + 0.5F));
if (pos.equals(this.worldPosition) || pos.equals(connectedPos)) if (pos.equals(this.worldPosition) || pos.equals(connectedPos))
continue; continue;

View file

@ -15,7 +15,7 @@ import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.EntityPredicates;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -97,7 +97,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
} }
if (generateFactor > 0) { if (generateFactor > 0) {
int toAdd = MathHelper.ceil(generateFactor * 10000F); int toAdd = Mth.ceil(generateFactor * 10000F);
if (this.canGenerateRightNow(toAdd)) { if (this.canGenerateRightNow(toAdd)) {
this.toRelease = toAdd; this.toRelease = toAdd;
this.releaseTimer = 15 * flightTime + 40; this.releaseTimer = 15 * flightTime + 40;

View file

@ -16,7 +16,7 @@ import net.minecraft.tileentity.*;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.IIntArray; import net.minecraft.util.IIntArray;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -71,7 +71,7 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition); BlockPos spot = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 20, this.worldPosition);
IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot); IAuraChunk chunk = IAuraChunk.getAuraChunk(this.level, spot);
chunk.drainAura(spot, MathHelper.ceil((200 - burnTime) * 16.6F)); chunk.drainAura(spot, Mth.ceil((200 - burnTime) * 16.6F));
did = true; did = true;
if (this.level.getGameTime() % 15 == 0) { if (this.level.getGameTime() % 15 == 0) {

View file

@ -20,7 +20,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
@ -143,7 +143,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.currentRecipe = null; this.currentRecipe = null;
this.timer = 0; this.timer = 0;
} else { } else {
int req = MathHelper.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time); int req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time);
if (this.container.getStoredAura() >= req) { if (this.container.getStoredAura() >= req) {
this.container.drainAura(req, false); this.container.drainAura(req, false);

View file

@ -10,7 +10,7 @@ import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
@ -78,7 +78,7 @@ public class BlockEntityRFConverter extends BlockEntityImpl implements ITickable
if (aura <= IAuraChunk.DEFAULT_AURA) if (aura <= IAuraChunk.DEFAULT_AURA)
return; return;
int amountToGen = Math.min(Math.min(10000, aura / 1000), emptyPart); int amountToGen = Math.min(Math.min(10000, aura / 1000), emptyPart);
int amountToUse = MathHelper.ceil(amountToGen / ModConfig.instance.auraToRFRatio.get()); int amountToUse = Mth.ceil(amountToGen / ModConfig.instance.auraToRFRatio.get());
this.storage.setEnergy(this.storage.getEnergyStored() + amountToGen); this.storage.setEnergy(this.storage.getEnergyStored() + amountToGen);
BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 45, this.worldPosition); BlockPos pos = IAuraChunk.getHighestSpot(this.level, this.worldPosition, 45, this.worldPosition);

View file

@ -13,7 +13,7 @@ import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableBlockEntity; import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.gen.Heightmap; import net.minecraft.level.gen.Heightmap;
public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickableBlockEntity {
@ -81,7 +81,7 @@ public class BlockEntitySnowCreator extends BlockEntityImpl implements ITickable
double angle = this.level.rand.nextFloat() * Math.PI * 2; double angle = this.level.rand.nextFloat() * Math.PI * 2;
BlockPos pos = this.worldPosition.add( BlockPos pos = this.worldPosition.add(
Math.cos(angle) * range * this.level.rand.nextFloat(), Math.cos(angle) * range * this.level.rand.nextFloat(),
MathHelper.nextInt(this.level.rand, range / 2, range), Mth.nextInt(this.level.rand, range / 2, range),
Math.sin(angle) * range * this.level.rand.nextFloat()); Math.sin(angle) * range * this.level.rand.nextFloat());
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + this.level.rand.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.rand.nextFloat(), pos.getX() + this.level.rand.nextFloat(), pos.getY() + 1, pos.getZ() + this.level.rand.nextFloat(),

View file

@ -14,7 +14,7 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraftforge.common.FarmlandWaterManager; import net.minecraftforge.common.FarmlandWaterManager;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.ticket.AABBTicket; import net.minecraftforge.common.ticket.AABBTicket;
@ -171,7 +171,7 @@ public class BlockEntitySpring extends BlockEntityImpl implements ITickableBlock
public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) { public FluidStack drain(int maxDrain, IFluidHandler.FluidAction action) {
int drain = Math.min(maxDrain, 1000); int drain = Math.min(maxDrain, 1000);
if (action.execute()) if (action.execute())
BlockEntitySpring.this.consumeAura(MathHelper.ceil(drain / 2F)); BlockEntitySpring.this.consumeAura(Mth.ceil(drain / 2F));
return new FluidStack(Fluids.WATER, drain); return new FluidStack(Fluids.WATER, drain);
} }

View file

@ -16,7 +16,7 @@ import net.minecraft.tileentity.ITickableBlockEntity;
import net.minecraft.util.EntityPredicates; import net.minecraft.util.EntityPredicates;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.GameRules; import net.minecraft.level.GameRules;
import net.minecraft.level.server.ServerLevel; import net.minecraft.level.server.ServerLevel;
import net.minecraft.level.storage.IServerLevelInfo; import net.minecraft.level.storage.IServerLevelInfo;
@ -74,7 +74,7 @@ public class BlockEntityTimeChanger extends BlockEntityImpl implements ITickable
if (stack.isEmpty() || stack.getItem() != Items.CLOCK) if (stack.isEmpty() || stack.getItem() != Items.CLOCK)
continue; continue;
int dayGoal = MathHelper.floor((frame.getRotation() / 8F) * 24000F) + 18000; int dayGoal = Mth.floor((frame.getRotation() / 8F) * 24000F) + 18000;
long current = this.level.getDayTime(); long current = this.level.getDayTime();
long toMove = (24000 - current % 24000 + dayGoal) % 24000; long toMove = (24000 - current % 24000 + dayGoal) % 24000;
this.goalTime = current + toMove; this.goalTime = current + toMove;

View file

@ -10,7 +10,7 @@ import net.minecraft.client.renderer.tileentity.BlockEntityRendererDispatcher;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3f; import net.minecraft.util.math.vector.Vector3f;
import java.util.Random; import java.util.Random;
@ -29,7 +29,7 @@ public class RenderOfferingTable extends BlockEntityRenderer<BlockEntityOffering
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getDamage()); this.rand.setSeed(Item.getIdFromItem(stack.getItem()) + stack.getDamage());
int amount = MathHelper.ceil(stack.getCount() / 2F); int amount = Mth.ceil(stack.getCount() / 2F);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
matrixStack.push(); matrixStack.push();
Item item = stack.getItem(); Item item = stack.getItem();

View file

@ -12,13 +12,10 @@ import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
@ -27,7 +24,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Supplier;
public class AuraChunk implements IAuraChunk { public class AuraChunk implements IAuraChunk {
@ -41,8 +37,8 @@ public class AuraChunk implements IAuraChunk {
this.chunk = chunk; this.chunk = chunk;
this.type = type; this.type = type;
for (Supplier<IDrainSpotEffect> supplier : NaturesAuraAPI.DRAIN_SPOT_EFFECTS.values()) { for (var supplier : NaturesAuraAPI.DRAIN_SPOT_EFFECTS.values()) {
IDrainSpotEffect effect = supplier.get(); var effect = supplier.get();
if (effect.appliesHere(this.chunk, this, this.type)) if (effect.appliesHere(this.chunk, this, this.type))
this.effects.add(effect); this.effects.add(effect);
} }
@ -52,8 +48,8 @@ public class AuraChunk implements IAuraChunk {
public int drainAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) { public int drainAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) {
if (amount <= 0) if (amount <= 0)
return 0; return 0;
MutableInt spot = this.getActualDrainSpot(pos, !simulate); var spot = this.getActualDrainSpot(pos, !simulate);
int curr = spot != null ? spot.intValue() : 0; var curr = spot != null ? spot.intValue() : 0;
if (curr < 0 && curr - amount > 0) // Underflow protection if (curr < 0 && curr - amount > 0) // Underflow protection
return this.drainAura(pos.above(), amount, aimForZero, simulate); return this.drainAura(pos.above(), amount, aimForZero, simulate);
if (aimForZero) { if (aimForZero) {
@ -78,8 +74,8 @@ public class AuraChunk implements IAuraChunk {
public int storeAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) { public int storeAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) {
if (amount <= 0) if (amount <= 0)
return 0; return 0;
MutableInt spot = this.getActualDrainSpot(pos, !simulate); var spot = this.getActualDrainSpot(pos, !simulate);
int curr = spot != null ? spot.intValue() : 0; var curr = spot != null ? spot.intValue() : 0;
if (curr > 0 && curr + amount < 0) // Overflow protection if (curr > 0 && curr + amount < 0) // Overflow protection
return this.storeAura(pos.above(), amount, aimForZero, simulate); return this.storeAura(pos.above(), amount, aimForZero, simulate);
if (aimForZero) { if (aimForZero) {
@ -102,7 +98,7 @@ public class AuraChunk implements IAuraChunk {
} }
private MutableInt getActualDrainSpot(BlockPos pos, boolean make) { private MutableInt getActualDrainSpot(BlockPos pos, boolean make) {
MutableInt spot = this.drainSpots.get(pos); var spot = this.drainSpots.get(pos);
if (spot == null && make) { if (spot == null && make) {
spot = new MutableInt(); spot = new MutableInt();
this.addDrainSpot(pos, spot); this.addDrainSpot(pos, spot);
@ -112,14 +108,14 @@ public class AuraChunk implements IAuraChunk {
@Override @Override
public int getDrainSpot(BlockPos pos) { public int getDrainSpot(BlockPos pos) {
MutableInt spot = this.getActualDrainSpot(pos, false); var spot = this.getActualDrainSpot(pos, false);
return spot == null ? 0 : spot.intValue(); return spot == null ? 0 : spot.intValue();
} }
private void addDrainSpot(BlockPos pos, MutableInt spot) { private void addDrainSpot(BlockPos pos, MutableInt spot) {
int expX = pos.getX() >> 4; var expX = pos.getX() >> 4;
int expZ = pos.getZ() >> 4; var expZ = pos.getZ() >> 4;
ChunkPos myPos = this.chunk.getPos(); var myPos = this.chunk.getPos();
if (expX != myPos.x || expZ != myPos.z) if (expX != myPos.x || expZ != myPos.z)
throw new IllegalArgumentException("Tried to add drain spot " + pos + " to chunk at " + myPos.x + ", " + myPos.z + " when it should've been added to chunk at " + expX + ", " + expZ); throw new IllegalArgumentException("Tried to add drain spot " + pos + " to chunk at " + myPos.x + ", " + myPos.z + " when it should've been added to chunk at " + expX + ", " + expZ);
@ -128,7 +124,7 @@ public class AuraChunk implements IAuraChunk {
public void setSpots(Map<BlockPos, MutableInt> spots) { public void setSpots(Map<BlockPos, MutableInt> spots) {
this.drainSpots.clear(); this.drainSpots.clear();
for (Map.Entry<BlockPos, MutableInt> entry : spots.entrySet()) for (var entry : spots.entrySet())
this.addDrainSpot(entry.getKey(), entry.getValue()); this.addDrainSpot(entry.getKey(), entry.getValue());
this.addOrRemoveAsActive(); this.addOrRemoveAsActive();
} }
@ -140,23 +136,23 @@ public class AuraChunk implements IAuraChunk {
@Override @Override
public void markDirty() { public void markDirty() {
this.chunk.markDirty(); this.chunk.setUnsaved(true);
this.needsSync = true; this.needsSync = true;
this.addOrRemoveAsActive(); this.addOrRemoveAsActive();
} }
public void update() { public void update() {
Level level = this.chunk.getLevel(); var level = this.chunk.getLevel();
for (Map.Entry<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) { for (var entry : this.drainSpots.entrySet()) {
BlockPos pos = entry.getKey(); var pos = entry.getKey();
MutableInt amount = entry.getValue(); var amount = entry.getValue();
for (IDrainSpotEffect effect : this.effects) for (var effect : this.effects)
effect.update(level, this.chunk, this, pos, amount.intValue()); effect.update(level, this.chunk, this, pos, amount.intValue());
} }
if (this.needsSync) { if (this.needsSync) {
ChunkPos pos = this.chunk.getPos(); var pos = this.chunk.getPos();
PacketHandler.sendToAllLoaded(level, PacketHandler.sendToAllLoaded(level,
new BlockPos(pos.x * 16, 0, pos.z * 16), new BlockPos(pos.x * 16, 0, pos.z * 16),
this.makePacket()); this.makePacket());
@ -165,13 +161,13 @@ public class AuraChunk implements IAuraChunk {
} }
public PacketAuraChunk makePacket() { public PacketAuraChunk makePacket() {
ChunkPos pos = this.chunk.getPos(); var pos = this.chunk.getPos();
return new PacketAuraChunk(pos.x, pos.z, this.drainSpots); return new PacketAuraChunk(pos.x, pos.z, this.drainSpots);
} }
public void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) { public void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
for (Map.Entry<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) { for (var entry : this.drainSpots.entrySet()) {
BlockPos drainPos = entry.getKey(); var drainPos = entry.getKey();
if (drainPos.distSqr(pos) <= radius * radius) { if (drainPos.distSqr(pos) <= radius * radius) {
consumer.accept(drainPos, entry.getValue().intValue()); consumer.accept(drainPos, entry.getValue().intValue());
} }
@ -179,17 +175,17 @@ public class AuraChunk implements IAuraChunk {
} }
public void getActiveEffectIcons(Player player, Map<ResourceLocation, Tuple<ItemStack, Boolean>> icons) { public void getActiveEffectIcons(Player player, Map<ResourceLocation, Tuple<ItemStack, Boolean>> icons) {
for (IDrainSpotEffect effect : this.effects) { for (var effect : this.effects) {
Tuple<ItemStack, Boolean> alreadyThere = icons.get(effect.getName()); var alreadyThere = icons.get(effect.getName());
if (alreadyThere != null && alreadyThere.getB()) if (alreadyThere != null && alreadyThere.getB())
continue; continue;
for (Map.Entry<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) { for (var entry : this.drainSpots.entrySet()) {
BlockPos pos = entry.getKey(); var pos = entry.getKey();
MutableInt amount = entry.getValue(); var amount = entry.getValue();
ActiveType state = effect.isActiveHere(player, this.chunk, this, pos, amount.intValue()); var state = effect.isActiveHere(player, this.chunk, this, pos, amount.intValue());
if (state == ActiveType.INACTIVE) if (state == ActiveType.INACTIVE)
continue; continue;
ItemStack stack = effect.getDisplayIcon(); var stack = effect.getDisplayIcon();
if (stack.isEmpty()) if (stack.isEmpty())
continue; continue;
icons.put(effect.getName(), new Tuple<>(stack, state == ActiveType.INHIBITED)); icons.put(effect.getName(), new Tuple<>(stack, state == ActiveType.INHIBITED));
@ -199,15 +195,15 @@ public class AuraChunk implements IAuraChunk {
@Override @Override
public CompoundTag serializeNBT() { public CompoundTag serializeNBT() {
ListTag list = new ListTag(); var list = new ListTag();
for (Map.Entry<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) { for (var entry : this.drainSpots.entrySet()) {
CompoundTag tag = new CompoundTag(); var tag = new CompoundTag();
tag.putLong("pos", entry.getKey().asLong()); tag.putLong("pos", entry.getKey().asLong());
tag.putInt("amount", entry.getValue().intValue()); tag.putInt("amount", entry.getValue().intValue());
list.add(tag); list.add(tag);
} }
CompoundTag compound = new CompoundTag(); var compound = new CompoundTag();
compound.put("drain_spots", list); compound.put("drain_spots", list);
return compound; return compound;
} }
@ -215,9 +211,9 @@ public class AuraChunk implements IAuraChunk {
@Override @Override
public void deserializeNBT(CompoundTag compound) { public void deserializeNBT(CompoundTag compound) {
this.drainSpots.clear(); this.drainSpots.clear();
ListTag list = compound.getList("drain_spots", 10); var list = compound.getList("drain_spots", 10);
for (Tag base : list) { for (var base : list) {
CompoundTag tag = (CompoundTag) base; var tag = (CompoundTag) base;
this.addDrainSpot( this.addDrainSpot(
BlockPos.of(tag.getLong("pos")), BlockPos.of(tag.getLong("pos")),
new MutableInt(tag.getInt("amount"))); new MutableInt(tag.getInt("amount")));
@ -226,8 +222,8 @@ public class AuraChunk implements IAuraChunk {
} }
private void addOrRemoveAsActive() { private void addOrRemoveAsActive() {
long chunkPos = this.chunk.getPos().asLong(); var chunkPos = this.chunk.getPos().toLong();
LevelData data = (LevelData) ILevelData.getLevelData(this.chunk.getLevel()); var data = (LevelData) ILevelData.getLevelData(this.chunk.getLevel());
if (this.drainSpots.size() > 0) { if (this.drainSpots.size() > 0) {
data.auraChunksWithSpots.put(chunkPos, this); data.auraChunksWithSpots.put(chunkPos, this);
} else { } else {

View file

@ -18,7 +18,7 @@ import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
@ -42,10 +42,10 @@ public class AnimalEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
this.chance = Math.min(50, MathHelper.ceil(Math.abs(aura) / 500000F / auraAndSpots.getRight())); this.chance = Math.min(50, Mth.ceil(Math.abs(aura) / 500000F / auraAndSpots.getRight()));
if (this.chance <= 0) if (this.chance <= 0)
return false; return false;
int dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 35); int dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
this.bb = new AxisAlignedBB(pos).grow(dist); this.bb = new AxisAlignedBB(pos).grow(dist);
return true; return true;
} }

View file

@ -14,7 +14,7 @@ import net.minecraft.potion.EffectInstance;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
@ -36,7 +36,7 @@ public class BreathlessEffect implements IDrainSpotEffect {
int dist = Math.min(Math.abs(aura) / 50000, 75); int dist = Math.min(Math.abs(aura) / 50000, 75);
if (dist < 10) if (dist < 10)
return false; return false;
this.amp = Math.min(MathHelper.floor(Math.abs(aura) / 2500000F), 3); this.amp = Math.min(Mth.floor(Math.abs(aura) / 2500000F), 3);
this.bb = new AxisAlignedBB(pos).grow(dist); this.bb = new AxisAlignedBB(pos).grow(dist);
return true; return true;
} }

View file

@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -33,9 +33,9 @@ public class CacheRechargeEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
int dist = MathHelper.clamp(aura / 3500, 3, 15); int dist = Mth.clamp(aura / 3500, 3, 15);
this.bb = new AxisAlignedBB(pos).grow(dist); this.bb = new AxisAlignedBB(pos).grow(dist);
this.amount = MathHelper.ceil(aura / 250F / auraAndSpots.getRight()); this.amount = Mth.ceil(aura / 250F / auraAndSpots.getRight());
return true; return true;
} }

View file

@ -10,7 +10,7 @@ import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Explosion; import net.minecraft.level.Explosion;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
@ -35,7 +35,7 @@ public class ExplosionEffect implements IDrainSpotEffect {
this.strength = Math.min(Math.abs(aura) / 5000000F, 5F); this.strength = Math.min(Math.abs(aura) / 5000000F, 5F);
if (this.strength <= 0) if (this.strength <= 0)
return false; return false;
this.dist = MathHelper.clamp(Math.abs(aura) / 200000, 25, 100); this.dist = Mth.clamp(Math.abs(aura) / 200000, 25, 100);
return true; return true;
} }
@ -60,8 +60,8 @@ public class ExplosionEffect implements IDrainSpotEffect {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
int x = MathHelper.floor(pos.getX() + level.rand.nextGaussian() * this.dist); int x = Mth.floor(pos.getX() + level.rand.nextGaussian() * this.dist);
int z = MathHelper.floor(pos.getZ() + level.rand.nextGaussian() * this.dist); int z = Mth.floor(pos.getZ() + level.rand.nextGaussian() * this.dist);
BlockPos chosenPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z); BlockPos chosenPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
if (chosenPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(chosenPos)) { if (chosenPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(chosenPos)) {
level.createExplosion(null, level.createExplosion(null,

View file

@ -12,7 +12,7 @@ import net.minecraft.entity.player.Player;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -29,9 +29,9 @@ public class GrassDieEffect implements IDrainSpotEffect {
Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50); Pair<Integer, Integer> auraAndSpots = IAuraChunk.getAuraAndSpotAmountInArea(level, pos, 50);
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 0) { if (aura < 0) {
this.amount = Math.min(300, MathHelper.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight())); this.amount = Math.min(300, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight()));
if (this.amount > 1) { if (this.amount > 1) {
this.dist = MathHelper.clamp(Math.abs(aura) / 75000, 5, 75); this.dist = Mth.clamp(Math.abs(aura) / 75000, 5, 75);
return true; return true;
} }
} }

View file

@ -17,7 +17,7 @@ import net.minecraft.tags.BlockTags;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -36,10 +36,10 @@ public class NetherDecayEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura >= 0) if (aura >= 0)
return false; return false;
this.amount = Math.min(300, MathHelper.ceil(Math.abs(aura) / 50000F / auraAndSpots.getRight())); this.amount = Math.min(300, Mth.ceil(Math.abs(aura) / 50000F / auraAndSpots.getRight()));
if (this.amount <= 1) if (this.amount <= 1)
return false; return false;
this.dist = MathHelper.clamp(Math.abs(aura) / 50000, 5, 75); this.dist = Mth.clamp(Math.abs(aura) / 50000, 5, 75);
return true; return true;
} }

View file

@ -16,7 +16,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
@ -36,10 +36,10 @@ public class NetherGrassEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
this.amount = Math.min(20, MathHelper.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight())); this.amount = Math.min(20, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight()));
if (this.amount <= 1) if (this.amount <= 1)
return false; return false;
this.dist = MathHelper.clamp(Math.abs(aura) / 100000, 5, 35); this.dist = Mth.clamp(Math.abs(aura) / 100000, 5, 35);
return true; return true;
} }
@ -66,9 +66,9 @@ public class NetherGrassEffect implements IDrainSpotEffect {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) { for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
int x = MathHelper.floor(pos.getX() + level.rand.nextGaussian() * this.dist); int x = Mth.floor(pos.getX() + level.rand.nextGaussian() * this.dist);
int y = MathHelper.floor(pos.getY() + level.rand.nextGaussian() * this.dist); int y = Mth.floor(pos.getY() + level.rand.nextGaussian() * this.dist);
int z = MathHelper.floor(pos.getZ() + level.rand.nextGaussian() * this.dist); int z = Mth.floor(pos.getZ() + level.rand.nextGaussian() * this.dist);
for (int yOff = -5; yOff <= 5; yOff++) { for (int yOff = -5; yOff <= 5; yOff++) {
BlockPos goalPos = new BlockPos(x, y + yOff, z); BlockPos goalPos = new BlockPos(x, y + yOff, z);

View file

@ -19,7 +19,7 @@ import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
@ -47,10 +47,10 @@ public class OreSpawnEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura <= 2000000) if (aura <= 2000000)
return false; return false;
this.amount = Math.min(20, MathHelper.ceil(Math.abs(aura) / 300000F / auraAndSpots.getRight())); this.amount = Math.min(20, Mth.ceil(Math.abs(aura) / 300000F / auraAndSpots.getRight()));
if (this.amount <= 0) if (this.amount <= 0)
return false; return false;
this.dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 20); this.dist = Mth.clamp(Math.abs(aura) / 150000, 5, 20);
return true; return true;
} }
@ -96,9 +96,9 @@ public class OreSpawnEffect implements IDrainSpotEffect {
Tuple<Vector3d, Integer> powder = powders.get(i % powders.size()); Tuple<Vector3d, Integer> powder = powders.get(i % powders.size());
Vector3d powderPos = powder.getA(); Vector3d powderPos = powder.getA();
int range = powder.getB(); int range = powder.getB();
int x = MathHelper.floor(powderPos.x + level.rand.nextGaussian() * range); int x = Mth.floor(powderPos.x + level.rand.nextGaussian() * range);
int y = MathHelper.floor(powderPos.y + level.rand.nextGaussian() * range); int y = Mth.floor(powderPos.y + level.rand.nextGaussian() * range);
int z = MathHelper.floor(powderPos.z + level.rand.nextGaussian() * range); int z = Mth.floor(powderPos.z + level.rand.nextGaussian() * range);
BlockPos orePos = new BlockPos(x, y, z); BlockPos orePos = new BlockPos(x, y, z);
if (orePos.distanceSq(powderPos.x, powderPos.y, powderPos.z, true) <= range * range if (orePos.distanceSq(powderPos.x, powderPos.y, powderPos.z, true) <= range * range
&& orePos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(orePos)) { && orePos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(orePos)) {

View file

@ -14,7 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
import net.minecraft.level.gen.Heightmap; import net.minecraft.level.gen.Heightmap;
@ -35,10 +35,10 @@ public class PlantBoostEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
this.amount = Math.min(45, MathHelper.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight())); this.amount = Math.min(45, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight()));
if (this.amount <= 1) if (this.amount <= 1)
return false; return false;
this.dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 35); this.dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
return true; return true;
} }
@ -63,8 +63,8 @@ public class PlantBoostEffect implements IDrainSpotEffect {
if (!this.calcValues(level, pos, spot)) if (!this.calcValues(level, pos, spot))
return; return;
for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) { for (int i = this.amount / 2 + level.rand.nextInt(this.amount / 2); i >= 0; i--) {
int x = MathHelper.floor(pos.getX() + (2 * level.rand.nextFloat() - 1) * this.dist); int x = Mth.floor(pos.getX() + (2 * level.rand.nextFloat() - 1) * this.dist);
int z = MathHelper.floor(pos.getZ() + (2 * level.rand.nextFloat() - 1) * this.dist); int z = Mth.floor(pos.getZ() + (2 * level.rand.nextFloat() - 1) * this.dist);
BlockPos plantPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z).down(); BlockPos plantPos = new BlockPos(x, level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z).down();
if (plantPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(plantPos)) { if (plantPos.distanceSq(pos) <= this.dist * this.dist && level.isBlockLoaded(plantPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, NAME)) if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, NAME))

View file

@ -24,7 +24,7 @@ public class ReplenishingEffect implements IDrainSpotEffect {
public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { public void update(Level level, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
if (spot < 0) { if (spot < 0) {
List<ISpotDrainable> tiles = new ArrayList<>(); List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getTileEntitiesInArea(level, pos, 25, tile -> { Helper.getBlockEntitiesInArea(level, pos, 25, tile -> {
IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); IAuraContainer container = tile.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
if (container instanceof ISpotDrainable) if (container instanceof ISpotDrainable)
tiles.add((ISpotDrainable) container); tiles.add((ISpotDrainable) container);

View file

@ -7,7 +7,7 @@ import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.chunk.Chunk; import net.minecraft.level.chunk.Chunk;
@ -20,7 +20,7 @@ public class SpreadEffect implements IDrainSpotEffect {
if (Math.abs(spot) < 500000 || Math.abs(IAuraChunk.getAuraInArea(level, pos, 25)) < 2000000) if (Math.abs(spot) < 500000 || Math.abs(IAuraChunk.getAuraInArea(level, pos, 25)) < 2000000)
return; return;
boolean drain = spot > 0; boolean drain = spot > 0;
int toMove = MathHelper.ceil(Math.abs(spot) * 0.72F); int toMove = Mth.ceil(Math.abs(spot) * 0.72F);
int perSide = toMove / 6; int perSide = toMove / 6;
while (toMove > 0) { while (toMove > 0) {
BlockPos bestOffset = null; BlockPos bestOffset = null;

View file

@ -1,26 +1,26 @@
package de.ellpeck.naturesaura.enchant; package de.ellpeck.naturesaura.enchant;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.enchantment.Enchantment; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.enchantment.EnchantmentType; import net.minecraft.world.item.ItemStack;
import net.minecraft.enchantment.Enchantments; import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.enchantment.Enchantments;
public class AuraMendingEnchantment extends ModEnchantment { public class AuraMendingEnchantment extends ModEnchantment {
public AuraMendingEnchantment() { public AuraMendingEnchantment() {
super("aura_mending", Rarity.RARE, EnchantmentType.BREAKABLE, EquipmentSlotType.values()); super("aura_mending", Rarity.RARE, EnchantmentCategory.BREAKABLE, EquipmentSlot.values());
} }
@Override @Override
protected boolean canApplyTogether(Enchantment ench) { protected boolean checkCompatibility(Enchantment ench) {
return super.canApplyTogether(ench) && ench != Enchantments.MENDING; return super.checkCompatibility(ench) && ench != Enchantments.MENDING;
} }
@Override @Override
public boolean canApply(ItemStack stack) { public boolean canEnchant(ItemStack stack) {
return super.canApply(stack) && !stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent(); return super.canEnchant(stack) && !stack.getCapability(NaturesAuraAPI.capAuraRecharge).isPresent();
} }
@Override @Override

View file

@ -2,15 +2,15 @@ package de.ellpeck.naturesaura.enchant;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.enchantment.Enchantment; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.enchantment.EnchantmentType; import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.world.item.enchantment.EnchantmentCategory;
public class ModEnchantment extends Enchantment implements IModItem { public class ModEnchantment extends Enchantment implements IModItem {
private final String name; private final String name;
protected ModEnchantment(String name, Rarity rarityIn, EnchantmentType typeIn, EquipmentSlotType[] slots) { protected ModEnchantment(String name, Rarity rarityIn, EnchantmentCategory typeIn, EquipmentSlot[] slots) {
super(rarityIn, typeIn, slots); super(rarityIn, typeIn, slots);
this.name = name; this.name = name;
ModRegistry.add(this); ModRegistry.add(this);

View file

@ -27,9 +27,9 @@ public class EntityLightProjectile extends ThrowableEntity {
if (this.level.isClientSide && this.ticksExisted > 1) { if (this.level.isClientSide && this.ticksExisted > 1) {
for (float i = 0; i <= 1; i += 0.2F) { for (float i = 0; i <= 1; i += 0.2F) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
MathHelper.lerp(i, this.prevPosX, this.getPosX()), Mth.lerp(i, this.prevPosX, this.getPosX()),
MathHelper.lerp(i, this.prevPosY, this.getPosY()), Mth.lerp(i, this.prevPosY, this.getPosY()),
MathHelper.lerp(i, this.prevPosZ, this.getPosZ()), Mth.lerp(i, this.prevPosZ, this.getPosZ()),
this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F, this.rand.nextGaussian() * 0.01F,
0xffcb5c, this.rand.nextFloat() * 0.5F + 1, 20, 0, false, true); 0xffcb5c, this.rand.nextFloat() * 0.5F + 1, 20, 0, false, true);
} }

View file

@ -17,7 +17,7 @@ import net.minecraft.nbt.LongNBT;
import net.minecraft.network.IPacket; import net.minecraft.network.IPacket;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.GameRules; import net.minecraft.level.GameRules;
@ -55,7 +55,7 @@ public class EntityMoverMinecart extends AbstractMinecartEntity {
if (!this.spotOffsets.isEmpty() && this.level.getGameTime() % 10 == 0) if (!this.spotOffsets.isEmpty() && this.level.getGameTime() % 10 == 0)
PacketHandler.sendToAllAround(this.level, pos, 32, new PacketParticles( PacketHandler.sendToAllAround(this.level, pos, 32, new PacketParticles(
(float) this.getPosX(), (float) this.getPosY(), (float) this.getPosZ(), PacketParticles.Type.MOVER_CART, (float) this.getPosX(), (float) this.getPosY(), (float) this.getPosZ(), PacketParticles.Type.MOVER_CART,
MathHelper.floor(this.getMotion().getX() * 100F), MathHelper.floor(this.getMotion().getY() * 100F), MathHelper.floor(this.getMotion().getZ() * 100F))); Mth.floor(this.getMotion().getX() * 100F), Mth.floor(this.getMotion().getY() * 100F), Mth.floor(this.getMotion().getZ() * 100F)));
if (pos.distanceSq(this.lastPosition) < 8 * 8) if (pos.distanceSq(this.lastPosition) < 8 * 8)
return; return;
@ -75,7 +75,7 @@ public class EntityMoverMinecart extends AbstractMinecartEntity {
int drained = chunk.drainAura(spot, toMove, false, false); int drained = chunk.drainAura(spot, toMove, false, false);
if (drained <= 0) if (drained <= 0)
continue; continue;
int toLose = MathHelper.ceil(drained / 250F); int toLose = Mth.ceil(drained / 250F);
BlockPos newSpot = newPos.add(offset); BlockPos newSpot = newPos.add(offset);
IAuraChunk.getAuraChunk(newLevel, newSpot).storeAura(newSpot, drained - toLose, false, false); IAuraChunk.getAuraChunk(newLevel, newSpot).storeAura(newSpot, drained - toLose, false, false);
} }

View file

@ -14,7 +14,7 @@ import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.particles.ParticleTypes; import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
@ -58,7 +58,7 @@ public class EntityStructureFinder extends EyeOfEnderEntity {
double d1 = pos.getZ(); double d1 = pos.getZ();
double d2 = d0 - this.getPosX(); double d2 = d0 - this.getPosX();
double d3 = d1 - this.getPosZ(); double d3 = d1 - this.getPosZ();
float f = MathHelper.sqrt(d2 * d2 + d3 * d3); float f = Mth.sqrt(d2 * d2 + d3 * d3);
if (f > 12.0F) { if (f > 12.0F) {
this.targetX = this.getPosX() + d2 / (double) f * 12.0D; this.targetX = this.getPosX() + d2 / (double) f * 12.0D;
this.targetZ = this.getPosZ() + d3 / (double) f * 12.0D; this.targetZ = this.getPosZ() + d3 / (double) f * 12.0D;
@ -81,9 +81,9 @@ public class EntityStructureFinder extends EyeOfEnderEntity {
double d0 = this.getPosX() + vec3d.x; double d0 = this.getPosX() + vec3d.x;
double d1 = this.getPosY() + vec3d.y; double d1 = this.getPosY() + vec3d.y;
double d2 = this.getPosZ() + vec3d.z; double d2 = this.getPosZ() + vec3d.z;
float f = MathHelper.sqrt(horizontalMag(vec3d)); float f = Mth.sqrt(horizontalMag(vec3d));
this.rotationYaw = (float) (MathHelper.atan2(vec3d.x, vec3d.z) * (double) (180F / (float) Math.PI)); this.rotationYaw = (float) (Mth.atan2(vec3d.x, vec3d.z) * (double) (180F / (float) Math.PI));
this.rotationPitch = (float) (MathHelper.atan2(vec3d.y, f) * (double) (180F / (float) Math.PI)); this.rotationPitch = (float) (Mth.atan2(vec3d.y, f) * (double) (180F / (float) Math.PI));
while (this.rotationPitch - this.prevRotationPitch < -180.0F) while (this.rotationPitch - this.prevRotationPitch < -180.0F)
this.prevRotationPitch -= 360.0F; this.prevRotationPitch -= 360.0F;
while (this.rotationPitch - this.prevRotationPitch >= 180.0F) while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
@ -92,14 +92,14 @@ public class EntityStructureFinder extends EyeOfEnderEntity {
this.prevRotationYaw -= 360.0F; this.prevRotationYaw -= 360.0F;
while (this.rotationYaw - this.prevRotationYaw >= 180.0F) while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
this.prevRotationYaw += 360.0F; this.prevRotationYaw += 360.0F;
this.rotationPitch = MathHelper.lerp(0.2F, this.prevRotationPitch, this.rotationPitch); this.rotationPitch = Mth.lerp(0.2F, this.prevRotationPitch, this.rotationPitch);
this.rotationYaw = MathHelper.lerp(0.2F, this.prevRotationYaw, this.rotationYaw); this.rotationYaw = Mth.lerp(0.2F, this.prevRotationYaw, this.rotationYaw);
if (!this.level.isClientSide) { if (!this.level.isClientSide) {
double d3 = this.targetX - d0; double d3 = this.targetX - d0;
double d4 = this.targetZ - d2; double d4 = this.targetZ - d2;
float f1 = (float) Math.sqrt(d3 * d3 + d4 * d4); float f1 = (float) Math.sqrt(d3 * d3 + d4 * d4);
float f2 = (float) MathHelper.atan2(d4, d3); float f2 = (float) Mth.atan2(d4, d3);
double d5 = MathHelper.lerp(0.0025D, f, f1); double d5 = Mth.lerp(0.0025D, f, f1);
double d6 = vec3d.y; double d6 = vec3d.y;
if (f1 < 1.0F) { if (f1 < 1.0F) {
d5 *= 0.8D; d5 *= 0.8D;

View file

@ -33,7 +33,7 @@ import net.minecraft.util.Tuple;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.level.Level; import net.minecraft.level.Level;
@ -109,10 +109,10 @@ public class ClientEvents {
if (!mc.isGamePaused()) { if (!mc.isGamePaused()) {
if (mc.level.getGameTime() % 20 == 0) { if (mc.level.getGameTime() % 20 == 0) {
int amount = MathHelper.floor(190 * ModConfig.instance.excessParticleAmount.get()); int amount = Mth.floor(190 * ModConfig.instance.excessParticleAmount.get());
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
int x = MathHelper.floor(mc.player.getPosX()) + mc.level.rand.nextInt(64) - 32; int x = Mth.floor(mc.player.getPosX()) + mc.level.rand.nextInt(64) - 32;
int z = MathHelper.floor(mc.player.getPosZ()) + mc.level.rand.nextInt(64) - 32; int z = Mth.floor(mc.player.getPosZ()) + mc.level.rand.nextInt(64) - 32;
BlockPos pos = new BlockPos(x, mc.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z) - 1, z); BlockPos pos = new BlockPos(x, mc.level.getHeight(Heightmap.Type.WORLD_SURFACE, x, z) - 1, z);
BlockState state = mc.level.getBlockState(pos); BlockState state = mc.level.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
@ -262,7 +262,7 @@ public class ClientEvents {
if (mc.player != null) { if (mc.player != null) {
if (!heldCache.isEmpty()) { if (!heldCache.isEmpty()) {
IAuraContainer container = heldCache.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); IAuraContainer container = heldCache.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null);
int width = MathHelper.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80); int width = Mth.ceil(container.getStoredAura() / (float) container.getMaxAura() * 80);
int conf = ModConfig.instance.cacheBarLocation.get(); int conf = ModConfig.instance.cacheBarLocation.get();
int x = res.getScaledWidth() / 2 + (conf == 0 ? -173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29) : 93); int x = res.getScaledWidth() / 2 + (conf == 0 ? -173 - (mc.player.getHeldItemOffhand().isEmpty() ? 0 : 29) : 93);
@ -307,7 +307,7 @@ public class ClientEvents {
float textX = conf % 2 == 0 ? 3 : res.getScaledWidth() - 3 - mc.fontRenderer.getStringWidth(text) * textScale; float textX = conf % 2 == 0 ? 3 : res.getScaledWidth() - 3 - mc.fontRenderer.getStringWidth(text) * textScale;
float textY = conf < 2 ? 3 : res.getScaledHeight() - 3 - 6; float textY = conf < 2 ? 3 : res.getScaledHeight() - 3 - 6;
int tHeight = MathHelper.ceil(MathHelper.clamp(totalPercentage, 0F, 1F) * 50); int tHeight = Mth.ceil(Mth.clamp(totalPercentage, 0F, 1F) * 50);
int y = !heldOcular.isEmpty() && totalPercentage > 1F ? startY + 26 : startY; int y = !heldOcular.isEmpty() && totalPercentage > 1F ? startY + 26 : startY;
if (tHeight < 50) if (tHeight < 50)
AbstractGui.blit(stack, startX, y, 6, 12, 6, 50 - tHeight, 256, 256); AbstractGui.blit(stack, startX, y, 6, 12, 6, 50 - tHeight, 256, 256);
@ -315,13 +315,13 @@ public class ClientEvents {
AbstractGui.blit(stack, startX, y + 50 - tHeight, 0, 12 + 50 - tHeight, 6, tHeight, 256, 256); AbstractGui.blit(stack, startX, y + 50 - tHeight, 0, 12 + 50 - tHeight, 6, tHeight, 256, 256);
if (!heldOcular.isEmpty()) { if (!heldOcular.isEmpty()) {
int topHeight = MathHelper.ceil(MathHelper.clamp((totalPercentage - 1F) * 2F, 0F, 1F) * 25); int topHeight = Mth.ceil(Mth.clamp((totalPercentage - 1F) * 2F, 0F, 1F) * 25);
if (topHeight > 0) { if (topHeight > 0) {
if (topHeight < 25) if (topHeight < 25)
AbstractGui.blit(stack, startX, startY, 18, 12, 6, 25 - topHeight, 256, 256); AbstractGui.blit(stack, startX, startY, 18, 12, 6, 25 - topHeight, 256, 256);
AbstractGui.blit(stack, startX, startY + 25 - topHeight, 12, 12 + 25 - topHeight, 6, topHeight, 256, 256); AbstractGui.blit(stack, startX, startY + 25 - topHeight, 12, 12 + 25 - topHeight, 6, topHeight, 256, 256);
} }
int bottomHeight = MathHelper.floor(MathHelper.clamp((totalPercentage + 1F) * 2F - 1F, 0F, 1F) * 25); int bottomHeight = Mth.floor(Mth.clamp((totalPercentage + 1F) * 2F - 1F, 0F, 1F) * 25);
if (bottomHeight < 25) { if (bottomHeight < 25) {
AbstractGui.blit(stack, startX, startY + 51, 18, 12, 6, 25 - bottomHeight, 256, 256); AbstractGui.blit(stack, startX, startY + 51, 18, 12, 6, 25 - bottomHeight, 256, 256);
if (bottomHeight > 0) if (bottomHeight > 0)
@ -447,7 +447,7 @@ public class ClientEvents {
int x = res.getScaledWidth() / 2 - 40; int x = res.getScaledWidth() / 2 - 40;
int y = res.getScaledHeight() / 2 + yOffset; int y = res.getScaledHeight() / 2 + yOffset;
int width = MathHelper.ceil(stored / (float) max * 80); int width = Mth.ceil(stored / (float) max * 80);
mc.getTextureManager().bindTexture(OVERLAYS); mc.getTextureManager().bindTexture(OVERLAYS);
if (width < 80) if (width < 80)

View file

@ -9,7 +9,7 @@ import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.ISeedReader; import net.minecraft.level.ISeedReader;
import net.minecraft.level.gen.ChunkGenerator; import net.minecraft.level.gen.ChunkGenerator;
import net.minecraft.level.gen.ILevelGenerationReader; import net.minecraft.level.gen.ILevelGenerationReader;
@ -120,7 +120,7 @@ public class LevelGenAncientTree extends Feature<BaseTreeFeatureConfig> {
} }
private int getHighestCoord(BlockPos pos) { private int getHighestCoord(BlockPos pos) {
return Math.max(MathHelper.abs(pos.getX()), Math.max(MathHelper.abs(pos.getY()), MathHelper.abs(pos.getZ()))); return Math.max(Mth.abs(pos.getX()), Math.max(Mth.abs(pos.getY()), Mth.abs(pos.getZ())));
} }
private Axis getLogAxis(BlockPos pos, BlockPos goal) { private Axis getLogAxis(BlockPos pos, BlockPos goal) {

View file

@ -6,7 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.tileentity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.ISeedReader; import net.minecraft.level.ISeedReader;
import net.minecraft.level.gen.ChunkGenerator; import net.minecraft.level.gen.ChunkGenerator;
import net.minecraft.level.gen.Heightmap; import net.minecraft.level.gen.Heightmap;
@ -36,11 +36,11 @@ public class LevelGenAuraBloom extends Feature<NoFeatureConfig> {
int startX = pos.getX() + rand.nextInt(16); int startX = pos.getX() + rand.nextInt(16);
int startZ = pos.getZ() + rand.nextInt(16); int startZ = pos.getZ() + rand.nextInt(16);
boolean any = false; boolean any = false;
for (int i = MathHelper.nextInt(rand, 3, 8); i > 0; i--) { for (int i = Mth.nextInt(rand, 3, 8); i > 0; i--) {
int offX = startX + MathHelper.nextInt(rand, -5, 5); int offX = startX + Mth.nextInt(rand, -5, 5);
int offZ = startZ + MathHelper.nextInt(rand, -5, 5); int offZ = startZ + Mth.nextInt(rand, -5, 5);
if (this.nether) { if (this.nether) {
int y = MathHelper.nextInt(rand, 0, 128); int y = Mth.nextInt(rand, 0, 128);
for (int off = 0; off < 64; off++) { for (int off = 0; off < 64; off++) {
// try to find a good location in both directions of the random pos // try to find a good location in both directions of the random pos
if (this.tryPlace(levelIn, new BlockPos(offX, y - off, offZ)) || this.tryPlace(levelIn, new BlockPos(offX, y + off, offZ))) { if (this.tryPlace(levelIn, new BlockPos(offX, y - off, offZ)) || this.tryPlace(levelIn, new BlockPos(offX, y + off, offZ))) {

View file

@ -1,16 +1,16 @@
package de.ellpeck.naturesaura.gui; package de.ellpeck.naturesaura.gui;
import net.minecraft.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.inventory.container.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.SlotItemHandler;
public class ContainerEnderCrate extends Container { public class ContainerEnderCrate extends AbstractContainerMenu {
public ContainerEnderCrate(ContainerType<ContainerEnderCrate> type, int id, Player player, IItemHandler handler) { public ContainerEnderCrate(MenuType<ContainerEnderCrate> type, int id, Player player, IItemHandler handler) {
super(type, id); super(type, id);
int i = (3 - 4) * 18; int i = (3 - 4) * 18;
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
@ -18,37 +18,38 @@ public class ContainerEnderCrate extends Container {
this.addSlot(new SlotItemHandler(handler, k + j * 9, 8 + k * 18, 18 + j * 18)); this.addSlot(new SlotItemHandler(handler, k + j * 9, 8 + k * 18, 18 + j * 18));
for (int l = 0; l < 3; ++l) for (int l = 0; l < 3; ++l)
for (int j1 = 0; j1 < 9; ++j1) for (int j1 = 0; j1 < 9; ++j1)
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i)); this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 103 + l * 18 + i));
for (int i1 = 0; i1 < 9; ++i1) for (int i1 = 0; i1 < 9; ++i1)
this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 161 + i)); this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 161 + i));
} }
@Override @Override
public boolean canInteractWith(Player playerIn) { public boolean stillValid(Player playerIn) {
return true; return true;
} }
@Override @Override
public ItemStack transferStackInSlot(Player playerIn, int index) { public ItemStack quickMoveStack(Player player, int index) {
ItemStack itemstack = ItemStack.EMPTY; ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index); Slot slot = this.slots.get(index);
if (slot != null && slot.getHasStack()) { if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getStack(); ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy(); itemstack = itemstack1.copy();
if (index < 3 * 9) { if (index < 3 * 9) {
if (!this.mergeItemStack(itemstack1, 3 * 9, this.inventorySlots.size(), true)) if (!this.moveItemStackTo(itemstack1, 3 * 9, this.slots.size(), true))
return ItemStack.EMPTY; return ItemStack.EMPTY;
} else if (!this.mergeItemStack(itemstack1, 0, 3 * 9, false)) } else if (!this.moveItemStackTo(itemstack1, 0, 3 * 9, false))
return ItemStack.EMPTY; return ItemStack.EMPTY;
if (itemstack1.isEmpty()) if (itemstack1.isEmpty())
slot.putStack(ItemStack.EMPTY); slot.set(ItemStack.EMPTY);
else else
slot.onSlotChanged(); slot.setChanged();
} }
return itemstack; return itemstack;
} }
} }

View file

@ -1,10 +1,10 @@
package de.ellpeck.naturesaura.gui; package de.ellpeck.naturesaura.gui;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.world.inventory.MenuType;
@SuppressWarnings("FieldNamingConvention") @SuppressWarnings("FieldNamingConvention")
public final class ModContainers { public final class ModContainers {
public static ContainerType<ContainerEnderCrate> ENDER_CRATE; public static MenuType<ContainerEnderCrate> ENDER_CRATE;
public static ContainerType<ContainerEnderCrate> ENDER_ACCESS; public static MenuType<ContainerEnderCrate> ENDER_ACCESS;
} }

View file

@ -6,52 +6,51 @@ import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.IColorProvidingItem;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import net.minecraft.block.BlockState; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.block.DispenserBlock; import net.minecraft.core.NonNullList;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.entity.player.Player; import net.minecraft.network.chat.Component;
import net.minecraft.item.Item; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.item.ItemGroup; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.ItemStack; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.*; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.util.math.RayTraceContext; import net.minecraft.world.item.Item;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.text.ITextComponent; import net.minecraft.world.level.ClipContext;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.level.Level;
import net.minecraft.level.Level; import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import static net.minecraft.dispenser.DefaultDispenseItemBehavior.doDispense;
public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICustomItemModel { public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICustomItemModel {
public ItemAuraBottle(Item emptyBottle) { public ItemAuraBottle(Item emptyBottle) {
super("aura_bottle"); super("aura_bottle");
MinecraftForge.EVENT_BUS.register(new EventHandler()); MinecraftForge.EVENT_BUS.register(new EventHandler());
DispenserBlock.registerDispenseBehavior(emptyBottle, (source, stack) -> { DispenserBlock.registerBehavior(emptyBottle, (source, stack) -> {
Level level = source.getLevel(); Level level = source.getLevel();
BlockState state = source.getBlockState(); var state = source.getBlockState();
Direction facing = state.get(DispenserBlock.FACING); var facing = state.getValue(DispenserBlock.FACING);
BlockPos offset = source.getBlockPos().offset(facing); var offset = source.getPos().relative(facing);
BlockState offsetState = level.getBlockState(offset); var offsetState = level.getBlockState(offset);
ItemStack dispense = stack.split(1); var dispense = stack.split(1);
if (offsetState.getBlock().isAir(offsetState, level, offset)) { if (offsetState.isAir()) {
if (IAuraChunk.getAuraInArea(level, offset, 30) >= 100000) { if (IAuraChunk.getAuraInArea(level, offset, 30) >= 100000) {
dispense = setType(new ItemStack(ItemAuraBottle.this), IAuraType.forLevel(level)); dispense = setType(new ItemStack(ItemAuraBottle.this), IAuraType.forLevel(level));
BlockPos spot = IAuraChunk.getHighestSpot(level, offset, 30, offset); var spot = IAuraChunk.getHighestSpot(level, offset, 30, offset);
IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 20000); IAuraChunk.getAuraChunk(level, spot).drainAura(spot, 20000);
} }
} }
doDispense(level, dispense, 6, facing, DispenserBlock.getDispensePosition(source)); DefaultDispenseItemBehavior.spawnItem(level, dispense, 6, facing, DispenserBlock.getDispensePosition(source));
return stack; return stack;
}); });
} }
@ -59,7 +58,7 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
public static IAuraType getType(ItemStack stack) { public static IAuraType getType(ItemStack stack) {
if (!stack.hasTag()) if (!stack.hasTag())
return NaturesAuraAPI.TYPE_OTHER; return NaturesAuraAPI.TYPE_OTHER;
String type = stack.getTag().getString("stored_type"); var type = stack.getTag().getString("stored_type");
if (type.isEmpty()) if (type.isEmpty())
return NaturesAuraAPI.TYPE_OTHER; return NaturesAuraAPI.TYPE_OTHER;
return NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(type)); return NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(type));
@ -71,10 +70,10 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
} }
@Override @Override
public void fillItemGroup(ItemGroup tab, NonNullList<ItemStack> items) { public void fillItemCategory(CreativeModeTab tab, NonNullList<ItemStack> items) {
if (this.isInGroup(tab)) { if (this.allowdedIn(tab)) {
for (IAuraType type : NaturesAuraAPI.AURA_TYPES.values()) { for (var type : NaturesAuraAPI.AURA_TYPES.values()) {
ItemStack stack = new ItemStack(this); var stack = new ItemStack(this);
setType(stack, type); setType(stack, type);
items.add(stack); items.add(stack);
} }
@ -82,13 +81,13 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
} }
@Override @Override
public ITextComponent getDisplayName(ItemStack stack) { public Component getName(ItemStack stack) {
return new TranslationTextComponent(stack.getTranslationKey() + "." + getType(stack).getName()); return new TranslatableComponent(stack.getDescriptionId() + "." + getType(stack).getName());
} }
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IItemColor getItemColor() { public ItemColor getItemColor() {
return (stack, tintIndex) -> tintIndex > 0 ? getType(stack).getColor() : 0xFFFFFF; return (stack, tintIndex) -> tintIndex > 0 ? getType(stack).getColor() : 0xFFFFFF;
} }
@ -103,30 +102,29 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
@SubscribeEvent @SubscribeEvent
public void onRightClick(PlayerInteractEvent.RightClickItem event) { public void onRightClick(PlayerInteractEvent.RightClickItem event) {
ItemStack held = event.getItemStack(); var held = event.getItemStack();
if (held.isEmpty() || held.getItem() != ModItems.BOTTLE_TWO_THE_REBOTTLING) if (held.isEmpty() || held.getItem() != ModItems.BOTTLE_TWO_THE_REBOTTLING)
return; return;
Player player = event.getPlayer(); var player = event.getPlayer();
RayTraceResult ray = rayTrace(player.level, player, RayTraceContext.FluidMode.NONE); HitResult ray = getPlayerPOVHitResult(player.level, player, ClipContext.Fluid.NONE);
if (ray.getType() == RayTraceResult.Type.BLOCK) if (ray.getType() == HitResult.Type.BLOCK)
return; return;
BlockPos pos = player.getPosition(); var pos = player.blockPosition();
if (IAuraChunk.getAuraInArea(player.level, pos, 30) < 100000) if (IAuraChunk.getAuraInArea(player.level, pos, 30) < 100000)
return; return;
if (!player.level.isClientSide) { if (!player.level.isClientSide) {
held.shrink(1); held.shrink(1);
player.inventory.addItemStackToInventory( player.getInventory().add(setType(new ItemStack(ItemAuraBottle.this), IAuraType.forLevel(player.level)));
setType(new ItemStack(ItemAuraBottle.this), IAuraType.forLevel(player.level)));
BlockPos spot = IAuraChunk.getHighestSpot(player.level, pos, 30, pos); var spot = IAuraChunk.getHighestSpot(player.level, pos, 30, pos);
IAuraChunk.getAuraChunk(player.level, spot).drainAura(spot, 20000); IAuraChunk.getAuraChunk(player.level, spot).drainAura(spot, 20000);
player.level.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), player.level.playSound(null, player.getX(), player.getY(), player.getZ(),
SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, SoundCategory.PLAYERS, 1F, 1F); SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.PLAYERS, 1F, 1F);
} }
player.swingArm(event.getHand()); player.swing(event.getHand());
} }
} }

View file

@ -7,7 +7,7 @@ import net.minecraft.block.NetherWartBlock;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.util.InteractionResult; import net.minecraft.util.InteractionResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.gen.feature.IFeatureConfig; import net.minecraft.level.gen.feature.IFeatureConfig;
import net.minecraft.level.server.ServerLevel; import net.minecraft.level.server.ServerLevel;
@ -39,7 +39,7 @@ public class ItemCrimsonMeal extends ItemImpl {
} else if (level.getBlockState(pos.up()).isAir(level, pos.up()) && level.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) { } else if (level.getBlockState(pos.up()).isAir(level, pos.up()) && level.getBlockState(pos).getBlock() == Blocks.SOUL_SAND) {
if (!level.isClientSide) { if (!level.isClientSide) {
for (int i = level.rand.nextInt(5); i >= 0; i--) { for (int i = level.rand.nextInt(5); i >= 0; i--) {
BlockPos offset = pos.add(MathHelper.nextInt(level.rand, -3, 3), 1, MathHelper.nextInt(level.rand, -3, 3)); BlockPos offset = pos.add(Mth.nextInt(level.rand, -3, 3), 1, Mth.nextInt(level.rand, -3, 3));
if (level.getBlockState(offset.down()).getBlock() == Blocks.SOUL_SAND && level.getBlockState(offset).isAir(level, offset)) { if (level.getBlockState(offset.down()).getBlock() == Blocks.SOUL_SAND && level.getBlockState(offset).isAir(level, offset)) {
level.setBlockState(offset, Blocks.NETHER_WART.getDefaultState()); level.setBlockState(offset, Blocks.NETHER_WART.getDefaultState());
} }

View file

@ -3,7 +3,7 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
public class ItemImpl extends Item implements IModItem { public class ItemImpl extends Item implements IModItem {
@ -14,7 +14,7 @@ public class ItemImpl extends Item implements IModItem {
} }
public ItemImpl(String baseName, Item.Properties properties) { public ItemImpl(String baseName, Item.Properties properties) {
super(properties.group(NaturesAura.CREATIVE_TAB)); super(properties.tab(NaturesAura.CREATIVE_TAB));
this.baseName = baseName; this.baseName = baseName;
ModRegistry.add(this); ModRegistry.add(this);
} }

View file

@ -32,7 +32,7 @@ public class ItemLootFinder extends ItemImpl {
inst.setParticleCulling(false); inst.setParticleCulling(false);
BlockPos pos = playerIn.getPosition(); BlockPos pos = playerIn.getPosition();
Helper.getTileEntitiesInArea(levelIn, pos, 64, tile -> { Helper.getBlockEntitiesInArea(levelIn, pos, 64, tile -> {
if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent() || tile instanceof MobSpawnerBlockEntity) { if (tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).isPresent() || tile instanceof MobSpawnerBlockEntity) {
inst.spawnMagicParticle( inst.spawnMagicParticle(
tile.getPos().getX() + 0.5F, tile.getPos().getY() + 0.5F, tile.getPos().getZ() + 0.5F, tile.getPos().getX() + 0.5F, tile.getPos().getY() + 0.5F, tile.getPos().getZ() + 0.5F,

View file

@ -1,9 +1,10 @@
package de.ellpeck.naturesaura.items; package de.ellpeck.naturesaura.items;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
@SuppressWarnings("FieldNamingConvention") @SuppressWarnings("FieldNamingConvention")
public final class ModItems { public final class ModItems {
public static Item INFUSED_IRON_PICKAXE; public static Item INFUSED_IRON_PICKAXE;
public static Item INFUSED_IRON_AXE; public static Item INFUSED_IRON_AXE;
public static Item INFUSED_IRON_SHOVEL; public static Item INFUSED_IRON_SHOVEL;

View file

@ -8,24 +8,25 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.Player;
import net.minecraft.item.AxeItem;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel { public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
private final String baseName; private final String baseName;
public ItemAxe(String baseName, IItemTier material, float damage, float speed) { public ItemAxe(String baseName, Tier material, float damage, float speed) {
super(material, damage, speed, new Properties().group(NaturesAura.CREATIVE_TAB)); super(material, damage, speed, new Properties().tab(NaturesAura.CREATIVE_TAB));
this.baseName = baseName; this.baseName = baseName;
ModRegistry.add(this); ModRegistry.add(this);
} }
@ -38,7 +39,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@Override @Override
public float getDestroySpeed(ItemStack stack, BlockState state) { public float getDestroySpeed(ItemStack stack, BlockState state) {
if (state.getMaterial() == Material.LEAVES) { if (state.getMaterial() == Material.LEAVES) {
return this.efficiency; return this.speed;
} else { } else {
return super.getDestroySpeed(stack, state); return super.getDestroySpeed(stack, state);
} }

View file

@ -10,21 +10,21 @@ import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.Player;
import net.minecraft.item.IItemTier;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.item.PickaxeItem;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.InteractionResult; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.SoundCategory; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.SoundEvents; import net.minecraft.world.InteractionResult;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.level.Level; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -33,8 +33,8 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
private final String baseName; private final String baseName;
public ItemPickaxe(String baseName, IItemTier material, int damage, float speed) { public ItemPickaxe(String baseName, Tier material, int damage, float speed) {
super(material, damage, speed, new Properties().group(NaturesAura.CREATIVE_TAB)); super(material, damage, speed, new Properties().tab(NaturesAura.CREATIVE_TAB));
this.baseName = baseName; this.baseName = baseName;
ModRegistry.add(this); ModRegistry.add(this);
} }
@ -45,23 +45,23 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
} }
@Override @Override
public InteractionResult onItemUse(ItemUseContext context) { public InteractionResult useOn(UseOnContext context) {
if (this == ModItems.INFUSED_IRON_PICKAXE) { if (this == ModItems.INFUSED_IRON_PICKAXE) {
Player player = context.getPlayer(); Player player = context.getPlayer();
Level level = context.getLevel(); Level level = context.getLevel();
BlockPos pos = context.getPos(); BlockPos pos = context.getClickedPos();
ItemStack stack = player.getHeldItem(context.getHand()); ItemStack stack = player.getItemInHand(context.getHand());
BlockState state = level.getBlockState(pos); BlockState state = level.getBlockState(pos);
BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state); BlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state);
if (result != null) { if (result != null) {
if (!level.isClientSide) { if (!level.isClientSide) {
level.setBlockState(pos, result); level.setBlockAndUpdate(pos, result);
LevelData data = (LevelData) ILevelData.getLevelData(level); LevelData data = (LevelData) ILevelData.getLevelData(level);
data.addMossStone(pos); data.addMossStone(pos);
} }
level.playSound(player, pos, SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); level.playSound(player, pos, SoundEvents.STONE_PLACE, SoundSource.BLOCKS, 1.0F, 1.0F);
stack.damageItem(15, player, Player -> Player.sendBreakAnimation(context.getHand())); stack.hurtAndBreak(15, player, p -> p.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
@ -75,13 +75,13 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
return; return;
if (!isSelected || levelIn.isClientSide) if (!isSelected || levelIn.isClientSide)
return; return;
AxisAlignedBB bounds = new AxisAlignedBB(entityIn.getPosition()).grow(3.5F); AABB bounds = new AABB(entityIn.getOnPos()).inflate(3.5F);
for (ItemEntity item : levelIn.getEntitiesWithinAABB(ItemEntity.class, bounds)) { for (ItemEntity item : levelIn.getEntitiesOfClass(ItemEntity.class, bounds)) {
// only pick up freshly dropped items // only pick up freshly dropped items
if (item.ticksExisted >= 5 || !item.isAlive()) if (item.tickCount >= 5 || !item.isAlive())
continue; continue;
item.setPickupDelay(0); item.setPickUpDelay(0);
item.onCollideWithPlayer((Player) entityIn); item.playerTouch((Player) entityIn);
} }
} }
} }

View file

@ -7,58 +7,66 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.core.Direction;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.Player;
import net.minecraft.item.*;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.BlockEntity; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.*; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.InteractionHand;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.InteractionResult;
import net.minecraft.level.Level; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.Tier;
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.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel { public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel {
private final String baseName; private final String baseName;
public ItemShovel(String baseName, IItemTier material, float damage, float speed) { public ItemShovel(String baseName, Tier material, float damage, float speed) {
super(material, damage, speed, new Properties().group(NaturesAura.CREATIVE_TAB)); super(material, damage, speed, new Properties().tab(NaturesAura.CREATIVE_TAB));
this.baseName = baseName; this.baseName = baseName;
ModRegistry.add(this); ModRegistry.add(this);
} }
@Override @Override
public InteractionResult onItemUse(ItemUseContext context) { public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel(); Level level = context.getLevel();
Player player = context.getPlayer(); Player player = context.getPlayer();
ItemStack stack = player.getHeldItem(context.getHand()); ItemStack stack = player.getItemInHand(context.getHand());
BlockPos pos = context.getPos(); BlockPos pos = context.getClickedPos();
BlockState state = level.getBlockState(pos); BlockState state = level.getBlockState(pos);
if (this == ModItems.INFUSED_IRON_SHOVEL) { if (this == ModItems.INFUSED_IRON_SHOVEL) {
int damage = 0; int damage = 0;
if (state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.MYCELIUM) { if (state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.MYCELIUM) {
if (level.getBlockState(pos.up()).getMaterial() == Material.AIR) { if (level.getBlockState(pos.above()).getMaterial() == Material.AIR) {
level.setBlockState(pos, Blocks.GRASS_BLOCK.getDefaultState()); level.setBlockAndUpdate(pos, Blocks.GRASS_BLOCK.defaultBlockState());
damage = 5; damage = 5;
} }
} else { } else {
int range = player.isSneaking() ? 0 : 1; int range = player.isCrouching() ? 0 : 1;
for (int x = -range; x <= range; x++) { for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) { for (int y = -range; y <= range; y++) {
BlockPos actualPos = pos.add(x, 0, y); BlockPos actualPos = pos.offset(x, 0, y);
Direction facing = context.getFace(); Direction facing = context.getClickedFace();
if (player.canPlayerEdit(actualPos.offset(facing), facing, stack)) { if (player.mayUseItemAt(actualPos.relative(facing), facing, stack)) {
if (facing != Direction.DOWN if (facing != Direction.DOWN
&& level.getBlockState(actualPos.up()).getMaterial() == Material.AIR && level.getBlockState(actualPos.above()).getMaterial() == Material.AIR
&& level.getBlockState(actualPos).getBlock() == Blocks.GRASS_BLOCK) { && level.getBlockState(actualPos).getBlock() == Blocks.GRASS_BLOCK) {
if (!level.isClientSide) { if (!level.isClientSide)
level.setBlockState(actualPos, Blocks.GRASS_PATH.getDefaultState(), 11); level.setBlock(actualPos, Blocks.DIRT_PATH.defaultBlockState(), 11);
}
damage = 1; damage = 1;
} }
} }
@ -67,23 +75,23 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
} }
if (damage > 0) { if (damage > 0) {
level.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F); level.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
stack.damageItem(damage, player, Player -> Player.sendBreakAnimation(context.getHand())); stack.hurtAndBreak(damage, player, p -> p.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} else if (this == ModItems.SKY_SHOVEL) { } else if (this == ModItems.SKY_SHOVEL) {
if (this.getDestroySpeed(stack, state) <= 1) if (this.getDestroySpeed(stack, state) <= 1)
return super.onItemUse(context); return super.useOn(context);
Hand otherHand = context.getHand() == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND; InteractionHand otherHand = context.getHand() == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
ItemStack other = player.getHeldItem(otherHand); ItemStack other = player.getItemInHand(otherHand);
if (other.isEmpty() || !(other.getItem() instanceof BlockItem)) if (other.isEmpty() || !(other.getItem() instanceof BlockItem))
return super.onItemUse(context); return super.useOn(context);
level.removeBlock(pos, false); level.removeBlock(pos, false);
BlockEntity tile = state.hasBlockEntity() ? level.getBlockEntity(pos) : null; BlockEntity tile = state.hasBlockEntity() ? level.getBlockEntity(pos) : null;
Block.spawnDrops(state, level, pos, tile, null, ItemStack.EMPTY); Block.dropResources(state, level, pos, tile, null, ItemStack.EMPTY);
ItemUseContext newContext = new ItemUseContext(player, otherHand, new BlockRayTraceResult(context.getHitVec(), context.getFace(), context.getPos(), context.isInside())); UseOnContext newContext = new UseOnContext(player, otherHand, new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), context.isInside()));
other.onItemUse(newContext); other.useOn(newContext);
stack.damageItem(1, player, p -> p.sendBreakAnimation(context.getHand())); stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand()));
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
return InteractionResult.PASS; return InteractionResult.PASS;

View file

@ -5,23 +5,22 @@ import com.google.common.collect.ListMultimap;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.tiles.ItemStackHandlerNA;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpawnLamp; import de.ellpeck.naturesaura.blocks.tiles.BlockEntitySpawnLamp;
import de.ellpeck.naturesaura.blocks.tiles.ItemStackHandlerNA;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.item.ItemStack; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.LongNBT; import net.minecraft.nbt.Tag;
import net.minecraft.util.Direction; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -30,7 +29,7 @@ import java.util.*;
public class LevelData implements ILevelData { public class LevelData implements ILevelData {
public final ListMultimap<ResourceLocation, Tuple<Vector3d, Integer>> effectPowders = ArrayListMultimap.create(); public final ListMultimap<ResourceLocation, Tuple<Vec3, Integer>> effectPowders = ArrayListMultimap.create();
public final Long2ObjectOpenHashMap<AuraChunk> auraChunksWithSpots = new Long2ObjectOpenHashMap<>(); public final Long2ObjectOpenHashMap<AuraChunk> auraChunksWithSpots = new Long2ObjectOpenHashMap<>();
public final List<BlockPos> recentlyConvertedMossStones = new ArrayList<>(); public final List<BlockPos> recentlyConvertedMossStones = new ArrayList<>();
public final Set<BlockEntitySpawnLamp> spawnLamps = new HashSet<>(); public final Set<BlockEntitySpawnLamp> spawnLamps = new HashSet<>();
@ -47,7 +46,7 @@ public class LevelData implements ILevelData {
public CompoundTag serializeNBT() { public CompoundTag serializeNBT() {
CompoundTag compound = new CompoundTag(); CompoundTag compound = new CompoundTag();
ListNBT storages = new ListNBT(); ListTag storages = new ListTag();
for (Map.Entry<String, ItemStackHandlerNA> entry : this.enderStorages.entrySet()) { for (Map.Entry<String, ItemStackHandlerNA> entry : this.enderStorages.entrySet()) {
ItemStackHandlerNA handler = entry.getValue(); ItemStackHandlerNA handler = entry.getValue();
if (Helper.isEmpty(handler)) if (Helper.isEmpty(handler))
@ -58,9 +57,9 @@ public class LevelData implements ILevelData {
} }
compound.put("storages", storages); compound.put("storages", storages);
ListNBT moss = new ListNBT(); ListTag moss = new ListTag();
for (BlockPos pos : this.recentlyConvertedMossStones) for (BlockPos pos : this.recentlyConvertedMossStones)
moss.add(LongNBT.valueOf(pos.toLong())); moss.add(LongTag.valueOf(pos.asLong()));
compound.put("converted_moss", moss); compound.put("converted_moss", moss);
return compound; return compound;
@ -69,15 +68,15 @@ public class LevelData implements ILevelData {
@Override @Override
public void deserializeNBT(CompoundTag compound) { public void deserializeNBT(CompoundTag compound) {
this.enderStorages.clear(); this.enderStorages.clear();
for (INBT base : compound.getList("storages", 10)) { for (Tag base : compound.getList("storages", 10)) {
CompoundTag storageComp = (CompoundTag) base; CompoundTag storageComp = (CompoundTag) base;
ItemStackHandlerNA storage = this.getEnderStorage(storageComp.getString("name")); ItemStackHandlerNA storage = this.getEnderStorage(storageComp.getString("name"));
storage.deserializeNBT(storageComp); storage.deserializeNBT(storageComp);
} }
this.recentlyConvertedMossStones.clear(); this.recentlyConvertedMossStones.clear();
for (INBT base : compound.getList("converted_moss", Constants.NBT.TAG_LONG)) for (Tag base : compound.getList("converted_moss", Tag.TAG_LONG))
this.recentlyConvertedMossStones.add(BlockPos.fromLong(((LongNBT) base).getLong())); this.recentlyConvertedMossStones.add(BlockPos.of(((LongTag) base).getAsLong()));
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import net.minecraft.client.level.ClientLevel;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.ReuseableStream; import net.minecraft.util.ReuseableStream;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Mth;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.vector.Quaternion; import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
@ -97,9 +97,9 @@ public class ParticleMagic extends Particle {
@Override @Override
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) { public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
Vector3d vec3d = renderInfo.getProjectedView(); Vector3d vec3d = renderInfo.getProjectedView();
float f = (float) (MathHelper.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX()); float f = (float) (Mth.lerp(partialTicks, this.prevPosX, this.posX) - vec3d.getX());
float f1 = (float) (MathHelper.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY()); float f1 = (float) (Mth.lerp(partialTicks, this.prevPosY, this.posY) - vec3d.getY());
float f2 = (float) (MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ()); float f2 = (float) (Mth.lerp(partialTicks, this.prevPosZ, this.posZ) - vec3d.getZ());
Quaternion quaternion = renderInfo.getRotation(); Quaternion quaternion = renderInfo.getRotation();
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)}; 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; float f4 = 0.1F * this.particleScale;

View file

@ -1,9 +1,9 @@
package de.ellpeck.naturesaura.potion; package de.ellpeck.naturesaura.potion;
import net.minecraft.entity.LivingEntity; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.potion.EffectInstance; import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.potion.EffectType; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.util.DamageSource; import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingHealEvent; import net.minecraftforge.event.entity.living.LivingHealEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -15,13 +15,13 @@ public class PotionBreathless extends PotionImpl {
private final Random random = new Random(); private final Random random = new Random();
public PotionBreathless() { public PotionBreathless() {
super("breathless", EffectType.HARMFUL, 0); super("breathless", MobEffectCategory.HARMFUL, 0);
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent @SubscribeEvent
public void onHeal(LivingHealEvent event) { public void onHeal(LivingHealEvent event) {
EffectInstance effect = event.getEntityLiving().getActivePotionEffect(this); MobEffectInstance effect = event.getEntityLiving().getEffect(this);
if (effect == null) if (effect == null)
return; return;
float chance = (effect.getAmplifier() + 1) / 15F; float chance = (effect.getAmplifier() + 1) / 15F;
@ -31,13 +31,13 @@ public class PotionBreathless extends PotionImpl {
} }
@Override @Override
public boolean isReady(int duration, int amplifier) { public boolean isDurationEffectTick(int duration, int amplifier) {
int mod = 200 >> amplifier; int mod = 200 >> amplifier;
return mod > 0 && duration % mod == 0 && this.random.nextBoolean(); return mod > 0 && duration % mod == 0 && this.random.nextBoolean();
} }
@Override @Override
public void performEffect(LivingEntity entity, int amplifier) { public void applyEffectTick(LivingEntity entity, int amplifier) {
entity.attackEntityFrom(DamageSource.MAGIC, 1F); entity.hurt(DamageSource.MAGIC, 1F);
} }
} }

View file

@ -2,14 +2,14 @@ package de.ellpeck.naturesaura.potion;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.potion.Effect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.potion.EffectType; import net.minecraft.world.effect.MobEffectCategory;
public class PotionImpl extends Effect implements IModItem { public class PotionImpl extends MobEffect implements IModItem {
protected final String baseName; protected final String baseName;
protected PotionImpl(String baseName, EffectType type, int liquidColorIn) { protected PotionImpl(String baseName, MobEffectCategory type, int liquidColorIn) {
super(type, liquidColorIn); super(type, liquidColorIn);
this.baseName = baseName; this.baseName = baseName;

View file

@ -6,13 +6,13 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.items.ItemAuraBottle; import de.ellpeck.naturesaura.items.ItemAuraBottle;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.item.ItemStack; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.registries.ForgeRegistryEntry; import net.minecraftforge.registries.ForgeRegistryEntry;
@ -38,59 +38,59 @@ public class AltarRecipe extends ModRecipe {
} }
@Override @Override
public ItemStack getRecipeOutput() { public ItemStack getResultItem() {
return this.output; return this.output;
} }
@Override @Override
public IRecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return ModRecipes.ALTAR_SERIAIZER; return ModRecipes.ALTAR_SERIAIZER;
} }
@Override @Override
public IRecipeType<?> getType() { public RecipeType<?> getType() {
return ModRecipes.ALTAR_TYPE; return ModRecipes.ALTAR_TYPE;
} }
public ItemStack getDimensionBottle() { public ItemStack getDimensionBottle() {
ItemStack bottle = ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), this.requiredType); ItemStack bottle = ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), this.requiredType);
bottle.setDisplayName(new TranslationTextComponent("info." + NaturesAura.MOD_ID + ".required_aura_type." + this.requiredType.getName())); bottle.setHoverName(new TranslatableComponent("info." + NaturesAura.MOD_ID + ".required_aura_type." + this.requiredType.getName()));
return bottle; return bottle;
} }
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<AltarRecipe> { public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<AltarRecipe> {
@Override @Override
public AltarRecipe read(ResourceLocation recipeId, JsonObject json) { public AltarRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return new AltarRecipe( return new AltarRecipe(
recipeId, recipeId,
Ingredient.deserialize(json.getAsJsonObject("input")), Ingredient.fromJson(json.getAsJsonObject("input")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true), CraftingHelper.getItemStack(json.getAsJsonObject("output"), true),
NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(json.get("aura_type").getAsString())), NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(json.get("aura_type").getAsString())),
json.has("catalyst") ? Ingredient.deserialize(json.getAsJsonObject("catalyst")) : Ingredient.EMPTY, json.has("catalyst") ? Ingredient.fromJson(json.getAsJsonObject("catalyst")) : Ingredient.EMPTY,
json.get("aura").getAsInt(), json.get("aura").getAsInt(),
json.get("time").getAsInt()); json.get("time").getAsInt());
} }
@Nullable @Nullable
@Override @Override
public AltarRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public AltarRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new AltarRecipe( return new AltarRecipe(
recipeId, recipeId,
Ingredient.read(buffer), Ingredient.fromNetwork(buffer),
buffer.readItemStack(), buffer.readItem(),
NaturesAuraAPI.AURA_TYPES.get(buffer.readResourceLocation()), NaturesAuraAPI.AURA_TYPES.get(buffer.readResourceLocation()),
Ingredient.read(buffer), Ingredient.fromNetwork(buffer),
buffer.readInt(), buffer.readInt(),
buffer.readInt()); buffer.readInt());
} }
@Override @Override
public void write(PacketBuffer buffer, AltarRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, AltarRecipe recipe) {
recipe.input.write(buffer); recipe.input.toNetwork(buffer);
buffer.writeItemStack(recipe.output); buffer.writeItem(recipe.output);
buffer.writeResourceLocation(recipe.requiredType.getName()); buffer.writeResourceLocation(recipe.requiredType.getName());
recipe.catalyst.write(buffer); recipe.catalyst.toNetwork(buffer);
buffer.writeInt(recipe.aura); buffer.writeInt(recipe.aura);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);
} }

View file

@ -2,18 +2,21 @@ package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.entity.Entity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason; import net.minecraft.entity.SpawnReason;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.server.level.ServerLevel;
import net.minecraft.level.Level; import net.minecraft.world.entity.Entity;
import net.minecraft.level.server.ServerLevel; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry; import net.minecraftforge.registries.ForgeRegistryEntry;
@ -40,30 +43,31 @@ public class AnimalSpawnerRecipe extends ModRecipe {
// passed position is zero on the client, so we don't want to do initialization stuff for the entity // passed position is zero on the client, so we don't want to do initialization stuff for the entity
if (pos == BlockPos.ZERO) if (pos == BlockPos.ZERO)
return this.entity.create(level); return this.entity.create(level);
return this.entity.create((ServerLevel) level, null, null, null, pos, SpawnReason.SPAWNER, false, false); return this.entity.create((ServerLevel) level, null, null, null, pos, MobSpawnType.SPAWNER, false, false);
} }
@Override @Override
public ItemStack getRecipeOutput() { public ItemStack getResultItem() {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@Override @Override
public IRecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return ModRecipes.ANIMAL_SPAWNER_SERIALIZER; return ModRecipes.ANIMAL_SPAWNER_SERIALIZER;
} }
@Override @Override
public IRecipeType<?> getType() { public RecipeType<?> getType() {
return ModRecipes.ANIMAL_SPAWNER_TYPE; return ModRecipes.ANIMAL_SPAWNER_TYPE;
} }
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<AnimalSpawnerRecipe> { public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<AnimalSpawnerRecipe> {
@Override @Override
public AnimalSpawnerRecipe read(ResourceLocation recipeId, JsonObject json) { public AnimalSpawnerRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
List<Ingredient> ingredients = new ArrayList<>(); List<Ingredient> ingredients = new ArrayList<>();
for (JsonElement e : json.getAsJsonArray("ingredients")) for (JsonElement e : json.getAsJsonArray("ingredients"))
ingredients.add(Ingredient.deserialize(e)); ingredients.add(Ingredient.fromJson(e));
return new AnimalSpawnerRecipe(recipeId, return new AnimalSpawnerRecipe(recipeId,
ForgeRegistries.ENTITIES.getValue(new ResourceLocation(json.get("entity").getAsString())), ForgeRegistries.ENTITIES.getValue(new ResourceLocation(json.get("entity").getAsString())),
json.get("aura").getAsInt(), json.get("aura").getAsInt(),
@ -73,10 +77,10 @@ public class AnimalSpawnerRecipe extends ModRecipe {
@Nullable @Nullable
@Override @Override
public AnimalSpawnerRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public AnimalSpawnerRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
Ingredient[] ings = new Ingredient[buffer.readInt()]; Ingredient[] ings = new Ingredient[buffer.readInt()];
for (int i = 0; i < ings.length; i++) for (int i = 0; i < ings.length; i++)
ings[i] = Ingredient.read(buffer); ings[i] = Ingredient.fromNetwork(buffer);
return new AnimalSpawnerRecipe( return new AnimalSpawnerRecipe(
recipeId, recipeId,
ForgeRegistries.ENTITIES.getValue(buffer.readResourceLocation()), ForgeRegistries.ENTITIES.getValue(buffer.readResourceLocation()),
@ -86,10 +90,10 @@ public class AnimalSpawnerRecipe extends ModRecipe {
} }
@Override @Override
public void write(PacketBuffer buffer, AnimalSpawnerRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, AnimalSpawnerRecipe recipe) {
buffer.writeInt(recipe.ingredients.length); buffer.writeInt(recipe.ingredients.length);
for (Ingredient ing : recipe.ingredients) for (Ingredient ing : recipe.ingredients)
ing.write(buffer); ing.toNetwork(buffer);
buffer.writeResourceLocation(recipe.entity.getRegistryName()); buffer.writeResourceLocation(recipe.entity.getRegistryName());
buffer.writeInt(recipe.aura); buffer.writeInt(recipe.aura);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);

View file

@ -1,12 +1,12 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import net.minecraft.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.items.wrapper.RecipeWrapper; import net.minecraftforge.items.wrapper.RecipeWrapper;
public abstract class ModRecipe implements IRecipe<RecipeWrapper> { public abstract class ModRecipe implements Recipe<RecipeWrapper> {
public final ResourceLocation name; public final ResourceLocation name;
@ -21,12 +21,12 @@ public abstract class ModRecipe implements IRecipe<RecipeWrapper> {
} }
@Override @Override
public ItemStack getCraftingResult(RecipeWrapper inv) { public ItemStack assemble(RecipeWrapper inv) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@Override @Override
public boolean canFit(int width, int height) { public boolean canCraftInDimensions(int width, int height) {
return false; return false;
} }
@ -34,4 +34,5 @@ public abstract class ModRecipe implements IRecipe<RecipeWrapper> {
public ResourceLocation getId() { public ResourceLocation getId() {
return this.name; return this.name;
} }
} }

View file

@ -7,37 +7,36 @@ import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.misc.WeatherType; import de.ellpeck.naturesaura.api.misc.WeatherType;
import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.api.misc.WeightedOre;
import net.minecraft.block.Blocks; import net.minecraft.core.Registry;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.NBTDynamicOps; import net.minecraft.nbt.Tag;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.registry.Registry; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
import java.util.List; import java.util.List;
public final class ModRecipes { public final class ModRecipes {
public static final IRecipeType<AltarRecipe> ALTAR_TYPE = new RecipeType<>(); public static final RecipeType<AltarRecipe> ALTAR_TYPE = new RecipeType<>();
public static final IRecipeSerializer<AltarRecipe> ALTAR_SERIAIZER = new AltarRecipe.Serializer(); public static final RecipeSerializer<AltarRecipe> ALTAR_SERIAIZER = new AltarRecipe.Serializer();
public static final IRecipeType<AnimalSpawnerRecipe> ANIMAL_SPAWNER_TYPE = new RecipeType<>(); public static final RecipeType<AnimalSpawnerRecipe> ANIMAL_SPAWNER_TYPE = new RecipeType<>();
public static final IRecipeSerializer<AnimalSpawnerRecipe> ANIMAL_SPAWNER_SERIALIZER = new AnimalSpawnerRecipe.Serializer(); public static final RecipeSerializer<AnimalSpawnerRecipe> ANIMAL_SPAWNER_SERIALIZER = new AnimalSpawnerRecipe.Serializer();
public static final IRecipeType<OfferingRecipe> OFFERING_TYPE = new RecipeType<>(); public static final RecipeType<OfferingRecipe> OFFERING_TYPE = new RecipeType<>();
public static final IRecipeSerializer<OfferingRecipe> OFFERING_SERIALIZER = new OfferingRecipe.Serializer(); public static final RecipeSerializer<OfferingRecipe> OFFERING_SERIALIZER = new OfferingRecipe.Serializer();
public static final IRecipeType<TreeRitualRecipe> TREE_RITUAL_TYPE = new RecipeType<>(); public static final RecipeType<TreeRitualRecipe> TREE_RITUAL_TYPE = new RecipeType<>();
public static final IRecipeSerializer<TreeRitualRecipe> TREE_RITUAL_SERIALIZER = new TreeRitualRecipe.Serializer(); public static final RecipeSerializer<TreeRitualRecipe> TREE_RITUAL_SERIALIZER = new TreeRitualRecipe.Serializer();
public static void register(IForgeRegistry<IRecipeSerializer<?>> registry) { public static void register(IForgeRegistry<RecipeSerializer<?>> registry) {
register(registry, "altar", ALTAR_TYPE, ALTAR_SERIAIZER); register(registry, "altar", ALTAR_TYPE, ALTAR_SERIAIZER);
register(registry, "animal_spawner", ANIMAL_SPAWNER_TYPE, ANIMAL_SPAWNER_SERIALIZER); register(registry, "animal_spawner", ANIMAL_SPAWNER_TYPE, ANIMAL_SPAWNER_SERIALIZER);
register(registry, "offering", OFFERING_TYPE, OFFERING_SERIALIZER); register(registry, "offering", OFFERING_TYPE, OFFERING_SERIALIZER);
@ -46,17 +45,17 @@ public final class ModRecipes {
public static void init() { public static void init() {
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put( NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
Blocks.COBBLESTONE.getDefaultState(), Blocks.COBBLESTONE.defaultBlockState(),
Blocks.MOSSY_COBBLESTONE.getDefaultState()); Blocks.MOSSY_COBBLESTONE.defaultBlockState());
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put( NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
Blocks.STONE_BRICKS.getDefaultState(), Blocks.STONE_BRICKS.defaultBlockState(),
Blocks.MOSSY_STONE_BRICKS.getDefaultState()); Blocks.MOSSY_STONE_BRICKS.defaultBlockState());
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put( NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
Blocks.COBBLESTONE_WALL.getDefaultState(), Blocks.COBBLESTONE_WALL.defaultBlockState(),
Blocks.MOSSY_COBBLESTONE_WALL.getDefaultState()); Blocks.MOSSY_COBBLESTONE_WALL.defaultBlockState());
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put( NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
Blocks.STONE_BRICK_WALL.getDefaultState(), Blocks.STONE_BRICK_WALL.defaultBlockState(),
Blocks.MOSSY_STONE_BRICK_WALL.getDefaultState()); Blocks.MOSSY_STONE_BRICK_WALL.defaultBlockState());
ore(NaturesAuraAPI.OVERWORLD_ORES, "ores/coal", 5000); ore(NaturesAuraAPI.OVERWORLD_ORES, "ores/coal", 5000);
ore(NaturesAuraAPI.NETHER_ORES, "ores/nether/coal", 5000); ore(NaturesAuraAPI.NETHER_ORES, "ores/nether/coal", 5000);
@ -131,14 +130,14 @@ public final class ModRecipes {
list.add(new WeightedOre(res, weight)); list.add(new WeightedOre(res, weight));
} }
private static void register(IForgeRegistry<IRecipeSerializer<?>> registry, String name, IRecipeType<?> type, IRecipeSerializer<?> serializer) { private static void register(IForgeRegistry<RecipeSerializer<?>> registry, String name, RecipeType<?> type, RecipeSerializer<?> serializer) {
ResourceLocation res = new ResourceLocation(NaturesAura.MOD_ID, name); ResourceLocation res = new ResourceLocation(NaturesAura.MOD_ID, name);
Registry.register(Registry.RECIPE_TYPE, res, type); Registry.register(Registry.RECIPE_TYPE, res, type);
registry.register(serializer.setRegistryName(res)); registry.register(serializer.setRegistryName(res));
} }
public static JsonObject serializeStack(ItemStack stack) { public static JsonObject serializeStack(ItemStack stack) {
CompoundTag nbt = stack.write(new CompoundTag()); CompoundTag nbt = stack.save(new CompoundTag());
byte c = nbt.getByte("Count"); byte c = nbt.getByte("Count");
if (c != 1) { if (c != 1) {
nbt.putByte("count", c); nbt.putByte("count", c);
@ -146,19 +145,20 @@ public final class ModRecipes {
nbt.remove("Count"); nbt.remove("Count");
renameTag(nbt, "id", "item"); renameTag(nbt, "id", "item");
renameTag(nbt, "tag", "nbt"); renameTag(nbt, "tag", "nbt");
Dynamic<INBT> dyn = new Dynamic<>(NBTDynamicOps.INSTANCE, nbt); Dynamic<Tag> dyn = new Dynamic<>(NbtOps.INSTANCE, nbt);
return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject(); return dyn.convert(JsonOps.INSTANCE).getValue().getAsJsonObject();
} }
private static void renameTag(CompoundTag nbt, String oldName, String newName) { private static void renameTag(CompoundTag nbt, String oldName, String newName) {
INBT tag = nbt.get(oldName); Tag tag = nbt.get(oldName);
if (tag != null) { if (tag != null) {
nbt.remove(oldName); nbt.remove(oldName);
nbt.put(newName, tag); nbt.put(newName, tag);
} }
} }
private static class RecipeType<T extends IRecipe<?>> implements IRecipeType<T> { private static class RecipeType<T extends Recipe<?>> implements net.minecraft.world.item.crafting.RecipeType<T> {
@Override @Override
public String toString() { public String toString() {
return Registry.RECIPE_TYPE.getKey(this).toString(); return Registry.RECIPE_TYPE.getKey(this).toString();

View file

@ -1,12 +1,12 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.registries.ForgeRegistryEntry; import net.minecraftforge.registries.ForgeRegistryEntry;
@ -26,45 +26,46 @@ public class OfferingRecipe extends ModRecipe {
} }
@Override @Override
public ItemStack getRecipeOutput() { public ItemStack getResultItem() {
return this.output; return this.output;
} }
@Override @Override
public IRecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return ModRecipes.OFFERING_SERIALIZER; return ModRecipes.OFFERING_SERIALIZER;
} }
@Override @Override
public IRecipeType<?> getType() { public RecipeType<?> getType() {
return ModRecipes.OFFERING_TYPE; return ModRecipes.OFFERING_TYPE;
} }
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<OfferingRecipe> { public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<OfferingRecipe> {
@Override @Override
public OfferingRecipe read(ResourceLocation recipeId, JsonObject json) { public OfferingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
return new OfferingRecipe( return new OfferingRecipe(
recipeId, recipeId,
Ingredient.deserialize(json.get("input")), Ingredient.fromJson(json.get("input")),
Ingredient.deserialize(json.get("start_item")), Ingredient.fromJson(json.get("start_item")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true)); CraftingHelper.getItemStack(json.getAsJsonObject("output"), true));
} }
@Nullable @Nullable
@Override @Override
public OfferingRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public OfferingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
return new OfferingRecipe( return new OfferingRecipe(
recipeId, recipeId,
Ingredient.read(buffer), Ingredient.fromNetwork(buffer),
Ingredient.read(buffer), Ingredient.fromNetwork(buffer),
buffer.readItemStack()); buffer.readItem());
} }
@Override @Override
public void write(PacketBuffer buffer, OfferingRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, OfferingRecipe recipe) {
recipe.input.write(buffer); recipe.input.toNetwork(buffer);
recipe.startItem.write(buffer); recipe.startItem.toNetwork(buffer);
buffer.writeItemStack(recipe.output); buffer.writeItem(recipe.output);
} }
} }
} }

View file

@ -2,12 +2,12 @@ package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.registries.ForgeRegistryEntry; import net.minecraftforge.registries.ForgeRegistryEntry;
@ -31,29 +31,30 @@ public class TreeRitualRecipe extends ModRecipe {
} }
@Override @Override
public ItemStack getRecipeOutput() { public ItemStack getResultItem() {
return this.result; return this.result;
} }
@Override @Override
public IRecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return ModRecipes.TREE_RITUAL_SERIALIZER; return ModRecipes.TREE_RITUAL_SERIALIZER;
} }
@Override @Override
public IRecipeType<?> getType() { public RecipeType<?> getType() {
return ModRecipes.TREE_RITUAL_TYPE; return ModRecipes.TREE_RITUAL_TYPE;
} }
public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<TreeRitualRecipe> { public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<TreeRitualRecipe> {
@Override @Override
public TreeRitualRecipe read(ResourceLocation recipeId, JsonObject json) { public TreeRitualRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
List<Ingredient> ings = new ArrayList<>(); List<Ingredient> ings = new ArrayList<>();
for (JsonElement element : json.getAsJsonArray("ingredients")) for (JsonElement element : json.getAsJsonArray("ingredients"))
ings.add(Ingredient.deserialize(element)); ings.add(Ingredient.fromJson(element));
return new TreeRitualRecipe( return new TreeRitualRecipe(
recipeId, recipeId,
Ingredient.deserialize(json.getAsJsonObject("sapling")), Ingredient.fromJson(json.getAsJsonObject("sapling")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true), CraftingHelper.getItemStack(json.getAsJsonObject("output"), true),
json.get("time").getAsInt(), json.get("time").getAsInt(),
ings.toArray(new Ingredient[0])); ings.toArray(new Ingredient[0]));
@ -61,25 +62,25 @@ public class TreeRitualRecipe extends ModRecipe {
@Nullable @Nullable
@Override @Override
public TreeRitualRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public TreeRitualRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
Ingredient[] ings = new Ingredient[buffer.readInt()]; Ingredient[] ings = new Ingredient[buffer.readInt()];
for (int i = 0; i < ings.length; i++) for (int i = 0; i < ings.length; i++)
ings[i] = Ingredient.read(buffer); ings[i] = Ingredient.fromNetwork(buffer);
return new TreeRitualRecipe( return new TreeRitualRecipe(
recipeId, recipeId,
Ingredient.read(buffer), Ingredient.fromNetwork(buffer),
buffer.readItemStack(), buffer.readItem(),
buffer.readInt(), buffer.readInt(),
ings); ings);
} }
@Override @Override
public void write(PacketBuffer buffer, TreeRitualRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, TreeRitualRecipe recipe) {
buffer.writeInt(recipe.ingredients.length); buffer.writeInt(recipe.ingredients.length);
for (Ingredient ing : recipe.ingredients) for (Ingredient ing : recipe.ingredients)
ing.write(buffer); ing.toNetwork(buffer);
recipe.saplingType.write(buffer); recipe.saplingType.toNetwork(buffer);
buffer.writeItemStack(recipe.result); buffer.writeItem(recipe.result);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);
} }
} }

View file

@ -1,12 +1,12 @@
package de.ellpeck.naturesaura.reg; package de.ellpeck.naturesaura.reg;
import net.minecraft.client.renderer.color.IItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public interface IColorProvidingItem { public interface IColorProvidingItem {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
IItemColor getItemColor(); ItemColor getItemColor();
} }

View file

@ -1,22 +1,22 @@
package de.ellpeck.naturesaura.reg; package de.ellpeck.naturesaura.reg;
import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.item.IItemTier; import net.minecraft.world.item.Tier;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.util.LazyValue; import net.minecraftforge.common.util.Lazy;
import java.util.function.Supplier; import java.util.function.Supplier;
public enum ModItemTier implements IItemTier { public enum ModItemTier implements Tier {
INFUSED(2, 250, 6, 2, 16, () -> Ingredient.fromItems(ModItems.INFUSED_IRON)), INFUSED(2, 250, 6, 2, 16, () -> Ingredient.of(ModItems.INFUSED_IRON)),
SKY(3, 1500, 8, 3, 12, () -> Ingredient.fromItems(ModItems.SKY_INGOT)); SKY(3, 1500, 8, 3, 12, () -> Ingredient.of(ModItems.SKY_INGOT));
private final int harvestLevel; private final int harvestLevel;
private final int maxUses; private final int maxUses;
private final float efficiency; private final float efficiency;
private final float attackDamage; private final float attackDamage;
private final int enchantability; private final int enchantability;
private final LazyValue<Ingredient> repairMaterial; private final Lazy<Ingredient> repairMaterial;
ModItemTier(int harvestLevelIn, int maxUsesIn, float efficiencyIn, float attackDamageIn, int enchantabilityIn, Supplier<Ingredient> repairMaterialIn) { ModItemTier(int harvestLevelIn, int maxUsesIn, float efficiencyIn, float attackDamageIn, int enchantabilityIn, Supplier<Ingredient> repairMaterialIn) {
this.harvestLevel = harvestLevelIn; this.harvestLevel = harvestLevelIn;
@ -24,36 +24,36 @@ public enum ModItemTier implements IItemTier {
this.efficiency = efficiencyIn; this.efficiency = efficiencyIn;
this.attackDamage = attackDamageIn; this.attackDamage = attackDamageIn;
this.enchantability = enchantabilityIn; this.enchantability = enchantabilityIn;
this.repairMaterial = new LazyValue<>(repairMaterialIn); this.repairMaterial = Lazy.of(repairMaterialIn);
} }
@Override @Override
public int getMaxUses() { public int getUses() {
return this.maxUses; return this.maxUses;
} }
@Override @Override
public float getEfficiency() { public float getSpeed() {
return this.efficiency; return this.efficiency;
} }
@Override @Override
public float getAttackDamage() { public float getAttackDamageBonus() {
return this.attackDamage; return this.attackDamage;
} }
@Override @Override
public int getHarvestLevel() { public int getLevel() {
return this.harvestLevel; return this.harvestLevel;
} }
@Override @Override
public int getEnchantability() { public int getEnchantmentValue() {
return this.enchantability; return this.enchantability;
} }
@Override @Override
public Ingredient getRepairMaterial() { public Ingredient getRepairIngredient() {
return this.repairMaterial.getValue(); return this.repairMaterial.get();
} }
} }

View file

@ -4,19 +4,19 @@ import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.*; import de.ellpeck.naturesaura.blocks.*;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment; import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment;
import de.ellpeck.naturesaura.enchant.ModEnchantments; import de.ellpeck.naturesaura.enchant.ModEnchantments;
import de.ellpeck.naturesaura.entities.*; import de.ellpeck.naturesaura.entities.*;
import de.ellpeck.naturesaura.entities.render.RenderEffectInhibitor; import de.ellpeck.naturesaura.entities.render.RenderEffectInhibitor;
import de.ellpeck.naturesaura.entities.render.RenderMoverMinecart; import de.ellpeck.naturesaura.entities.render.RenderMoverMinecart;
import de.ellpeck.naturesaura.entities.render.RenderStub; import de.ellpeck.naturesaura.entities.render.RenderStub;
import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.gen.LevelGenAncientTree; import de.ellpeck.naturesaura.gen.LevelGenAncientTree;
import de.ellpeck.naturesaura.gen.LevelGenAuraBloom; import de.ellpeck.naturesaura.gen.LevelGenAuraBloom;
import de.ellpeck.naturesaura.gen.LevelGenNetherWartMushroom; import de.ellpeck.naturesaura.gen.LevelGenNetherWartMushroom;
import de.ellpeck.naturesaura.gen.ModFeatures;
import de.ellpeck.naturesaura.gui.ContainerEnderCrate; import de.ellpeck.naturesaura.gui.ContainerEnderCrate;
import de.ellpeck.naturesaura.gui.ModContainers; import de.ellpeck.naturesaura.gui.ModContainers;
import de.ellpeck.naturesaura.items.*; import de.ellpeck.naturesaura.items.*;
@ -25,7 +25,6 @@ import de.ellpeck.naturesaura.potion.ModPotions;
import de.ellpeck.naturesaura.potion.PotionBreathless; import de.ellpeck.naturesaura.potion.PotionBreathless;
import de.ellpeck.naturesaura.recipes.EnabledCondition; import de.ellpeck.naturesaura.recipes.EnabledCondition;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.FlowerPotBlock; import net.minecraft.block.FlowerPotBlock;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
@ -38,21 +37,24 @@ import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.potion.Effect;
import net.minecraft.tileentity.BlockEntity;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.LevelGenRegistries;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.level.gen.feature.Feature; import net.minecraft.level.gen.feature.Feature;
import net.minecraft.level.gen.feature.structure.Structure; import net.minecraft.level.gen.feature.structure.Structure;
import net.minecraft.tileentity.BlockEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.LevelGenRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.extensions.IForgeContainerType; import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.client.registry.IRenderFactory; import net.minecraftforge.fml.client.registry.IRenderFactory;
@ -158,7 +160,7 @@ public final class ModRegistry {
public static void registerItems(RegistryEvent.Register<Item> event) { public static void registerItems(RegistryEvent.Register<Item> event) {
for (IModItem block : ALL_ITEMS) { for (IModItem block : ALL_ITEMS) {
if (block instanceof Block && !(block instanceof INoItemBlock)) { if (block instanceof Block && !(block instanceof INoItemBlock)) {
BlockItem item = new BlockItem((Block) block, new Item.Properties().group(NaturesAura.CREATIVE_TAB)); BlockItem item = new BlockItem((Block) block, new Item.Properties().tab(NaturesAura.CREATIVE_TAB));
item.setRegistryName(block.getBaseName()); item.setRegistryName(block.getBaseName());
event.getRegistry().register(item); event.getRegistry().register(item);
} }
@ -243,7 +245,7 @@ public final class ModRegistry {
} }
@SubscribeEvent @SubscribeEvent
public static void registerPotions(RegistryEvent.Register<Effect> event) { public static void registerPotions(RegistryEvent.Register<MobEffect> event) {
event.getRegistry().registerAll( event.getRegistry().registerAll(
new PotionBreathless() new PotionBreathless()
); );
@ -251,16 +253,16 @@ public final class ModRegistry {
} }
@SubscribeEvent @SubscribeEvent
public static void registerContainers(RegistryEvent.Register<ContainerType<?>> event) { public static void registerContainers(RegistryEvent.Register<MenuType<?>> event) {
event.getRegistry().registerAll( event.getRegistry().registerAll(
IForgeContainerType.create((windowId, inv, data) -> { IForgeMenuType.create((windowId, inv, data) -> {
BlockEntity tile = inv.player.level.getBlockEntity(data.readBlockPos()); BlockEntity tile = inv.player.level.getBlockEntity(data.readBlockPos());
if (tile instanceof BlockEntityEnderCrate) if (tile instanceof BlockEntityEnderCrate crate)
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, windowId, inv.player, ((BlockEntityEnderCrate) tile).getItemHandler()); return new ContainerEnderCrate(ModContainers.ENDER_CRATE, windowId, inv.player, crate.getItemHandler());
return null; return null;
}).setRegistryName("ender_crate"), }).setRegistryName("ender_crate"),
IForgeContainerType.create((windowId, inv, data) -> { IForgeMenuType.create((windowId, inv, data) -> {
IItemHandler handler = ILevelData.getOverworldData(inv.player.level).getEnderStorage(data.readString()); IItemHandler handler = ILevelData.getOverworldData(inv.player.level).getEnderStorage(data.readUtf());
return new ContainerEnderCrate(ModContainers.ENDER_ACCESS, windowId, inv.player, handler); return new ContainerEnderCrate(ModContainers.ENDER_ACCESS, windowId, inv.player, handler);
}).setRegistryName("ender_access") }).setRegistryName("ender_access")
); );