mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 20:06:59 -05:00
Refactor and 1.17-pre1 (#96)
* Fix #94 Signed-off-by: shedaniel <daniel@shedaniel.me> * Add Chunk data save and load events, closes #89 (#92) * Created Chunk save and load event. Closes #89 * Fixed missing licence * Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java * Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java * Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java * Supply ServerLevel in ChunkEvent.LOAD, style cleanup Signed-off-by: shedaniel <daniel@shedaniel.me> * Add "Data" suffix to Chunk IO Events and mark level as nullable for load * Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java * Bump to 1.16 Co-authored-by: shedaniel <daniel@shedaniel.me> Co-authored-by: Max <maxh2709@gmail.com> * Update pr.yml * Add NetworkManager hook for Entity spawn packets (#88) * New utility hook for creating a entity spawn packet. before every mod had to implement this in itself. * Apply suggestions from code review Co-authored-by: shedaniel <daniel@shedaniel.me> * Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java * Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java * Properly implement SpawnEntityPacket & Format style Signed-off-by: shedaniel <daniel@shedaniel.me> * Format Signed-off-by: shedaniel <daniel@shedaniel.me> * createEntitySpawnPacket -> createAddEntityPacket for mojmap consistency Signed-off-by: shedaniel <daniel@shedaniel.me> * Bump version to 1.17 Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: shedaniel <daniel@shedaniel.me> * Add Javadocs for all events (#91) * javadoc for ClientChatEvent * javadoc for ClientPlayerEvent * javadoc for ClientRawInputEvent * Added javadoc for ClientScreenInputEvent * Bit refactoring and removed javadoc @see to the caller methods * Add javadoc for BlockEvent * Add javadoc for ChatEvent * Add javadoc for CommandPerformEvent and CommandRegistrationEvent * Add javadoc for EntityEvent * Add javadoc for ExplosionEvent * Add javadoc for GuiEvent * Add javadoc for InteractionEvent * Add javadoc for LightningEvent, RecipeUpdateEvent & TextureStitchEvent * Add javadoc for LifecycleEvent & ClientLifecycleEvent * Add javadoc for TooltipEvent * Add javadoc for TickEvent and partly PlayerEvent * More javadoc for PlayerEvent * Finally all event have javadoc * Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/ChatEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/CommandRegistrationEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/client/ClientScreenInputEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/client/ClientScreenInputEvent.java Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Update common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Apply suggestions from code review Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> Co-authored-by: Max <maxh2709@gmail.com> * Apply suggestions from code review Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: shedaniel <daniel@shedaniel.me> * Applied some more reviews * Applied some more reviews * Applied suggestions * Reformat and apply some minor suggestions * Apply suggestions from review (first batch) * Remove double return javadoc * Apply suggestions from code review Co-authored-by: shedaniel <daniel@shedaniel.me> * Add "scaled" to mouse coordinates * Final touches Signed-off-by: shedaniel <daniel@shedaniel.me> * Remove invalid tips Signed-off-by: shedaniel <daniel@shedaniel.me> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com> Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: shedaniel <daniel@shedaniel.me> * Refactor Signed-off-by: shedaniel <daniel@shedaniel.me> * Update common/src/main/java/dev/architectury/event/events/common/InteractionEvent.java Co-authored-by: Max <maxh2709@gmail.com> * Apply suggestions from code review Co-authored-by: Max <maxh2709@gmail.com> * attack -> hurt Signed-off-by: shedaniel <daniel@shedaniel.me> * Update @param for InteractionEvent#FARMLAND_TRAMPLE Signed-off-by: shedaniel <daniel@shedaniel.me> * world -> level Signed-off-by: shedaniel <daniel@shedaniel.me> * Relocate hooks Signed-off-by: shedaniel <daniel@shedaniel.me> * Organize imports Signed-off-by: shedaniel <daniel@shedaniel.me> * Registry -> Registrar Please voice out your opinion!! Signed-off-by: shedaniel <daniel@shedaniel.me> * Some more renames itemOptional -> optionalItem RegistryBuilder -> RegistrarBuilder RegistryOption -> RegistrarOption Not forcing RegistryEntry on new registries, vanilla types don't have them Signed-off-by: shedaniel <daniel@shedaniel.me> * Java 16-ification Signed-off-by: shedaniel <daniel@shedaniel.me> * Optimise imports after the var change Signed-off-by: shedaniel <daniel@shedaniel.me> * Un-minimize architectury-common.mixins.json Signed-off-by: shedaniel <daniel@shedaniel.me> Co-authored-by: canitzp <12819060+canitzp@users.noreply.github.com> Co-authored-by: Max <maxh2709@gmail.com> Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
This commit is contained in:
201
common/src/main/java/dev/architectury/fluid/FluidStack.java
Normal file
201
common/src/main/java/dev/architectury/fluid/FluidStack.java
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.fluid;
|
||||
|
||||
import dev.architectury.hooks.fluid.FluidStackHooks;
|
||||
import dev.architectury.utils.NbtType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class FluidStack {
|
||||
private static final FluidStack EMPTY = create(Fluids.EMPTY, 0);
|
||||
private long amount;
|
||||
@Nullable
|
||||
private CompoundTag tag;
|
||||
private Supplier<Fluid> fluid;
|
||||
|
||||
private FluidStack(Supplier<Fluid> fluid, long amount, CompoundTag tag) {
|
||||
this.fluid = Objects.requireNonNull(fluid);
|
||||
this.amount = amount;
|
||||
this.tag = tag == null ? null : tag.copy();
|
||||
}
|
||||
|
||||
public static FluidStack empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static FluidStack create(Fluid fluid, long amount, @Nullable CompoundTag tag) {
|
||||
return create(() -> fluid, amount, tag);
|
||||
}
|
||||
|
||||
public static FluidStack create(Fluid fluid, long amount) {
|
||||
return create(fluid, amount, null);
|
||||
}
|
||||
|
||||
public static FluidStack create(Supplier<Fluid> fluid, long amount, @Nullable CompoundTag tag) {
|
||||
return new FluidStack(fluid, amount, tag);
|
||||
}
|
||||
|
||||
public static FluidStack create(Supplier<Fluid> fluid, long amount) {
|
||||
return create(fluid, amount, null);
|
||||
}
|
||||
|
||||
public static FluidStack create(FluidStack stack, long amount) {
|
||||
return create(stack.getRawFluidSupplier(), amount, stack.getTag());
|
||||
}
|
||||
|
||||
public static long bucketAmount() {
|
||||
return FluidStackHooks.bucketAmount();
|
||||
}
|
||||
|
||||
public final Fluid getFluid() {
|
||||
return isEmpty() ? Fluids.EMPTY : getRawFluid();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final Fluid getRawFluid() {
|
||||
return fluid.get();
|
||||
}
|
||||
|
||||
public final Supplier<Fluid> getRawFluidSupplier() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getRawFluid() == Fluids.EMPTY || amount <= 0;
|
||||
}
|
||||
|
||||
public long getAmount() {
|
||||
return isEmpty() ? 0 : amount;
|
||||
}
|
||||
|
||||
public void setAmount(long amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void grow(long amount) {
|
||||
setAmount(this.amount + amount);
|
||||
}
|
||||
|
||||
public void shrink(long amount) {
|
||||
setAmount(this.amount - amount);
|
||||
}
|
||||
|
||||
public boolean hasTag() {
|
||||
return tag != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CompoundTag getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(@Nullable CompoundTag tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public CompoundTag getOrCreateTag() {
|
||||
if (tag == null)
|
||||
setTag(new CompoundTag());
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CompoundTag getChildTag(String childName) {
|
||||
if (tag == null)
|
||||
return null;
|
||||
return tag.getCompound(childName);
|
||||
}
|
||||
|
||||
public CompoundTag getOrCreateChildTag(String childName) {
|
||||
getOrCreateTag();
|
||||
var child = tag.getCompound(childName);
|
||||
if (!tag.contains(childName, NbtType.COMPOUND)) {
|
||||
tag.put(childName, child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
public void removeChildTag(String childName) {
|
||||
if (tag != null)
|
||||
tag.remove(childName);
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
return FluidStackHooks.getName(this);
|
||||
}
|
||||
|
||||
public String getTranslationKey() {
|
||||
return FluidStackHooks.getTranslationKey(this);
|
||||
}
|
||||
|
||||
public FluidStack copy() {
|
||||
return new FluidStack(fluid, amount, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
var code = 1;
|
||||
code = 31 * code + getFluid().hashCode();
|
||||
code = 31 * code + Long.hashCode(amount);
|
||||
if (tag != null)
|
||||
code = 31 * code + tag.hashCode();
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof FluidStack)) {
|
||||
return false;
|
||||
}
|
||||
return isFluidStackEqual((FluidStack) o);
|
||||
}
|
||||
|
||||
public boolean isFluidStackEqual(FluidStack other) {
|
||||
return getFluid() == other.getFluid() && getAmount() == other.getAmount() && isTagEqual(other);
|
||||
}
|
||||
|
||||
private boolean isTagEqual(FluidStack other) {
|
||||
return tag == null ? other.tag == null : other.tag != null && tag.equals(other.tag);
|
||||
}
|
||||
|
||||
public static FluidStack read(FriendlyByteBuf buf) {
|
||||
return FluidStackHooks.read(buf);
|
||||
}
|
||||
|
||||
public static FluidStack read(CompoundTag tag) {
|
||||
return FluidStackHooks.read(tag);
|
||||
}
|
||||
|
||||
public void write(FriendlyByteBuf buf) {
|
||||
FluidStackHooks.write(this, buf);
|
||||
}
|
||||
|
||||
public CompoundTag write(CompoundTag tag) {
|
||||
return FluidStackHooks.write(this, tag);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user