mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-30 21:05:56 -05:00
Update to 21w14a, remove typetools, remove fractions in favor of 81000
This commit is contained in:
@@ -8,7 +8,6 @@ dependencies {
|
||||
// We depend on fabric loader here to use the fabric @Environment annotations
|
||||
// Do NOT use other classes from fabric loader
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
implementation "net.jodah:typetools:0.6.2"
|
||||
}
|
||||
|
||||
architectury {
|
||||
|
||||
@@ -23,13 +23,10 @@ import com.google.common.reflect.AbstractInvocationHandler;
|
||||
import me.shedaniel.architectury.ForgeEvent;
|
||||
import me.shedaniel.architectury.ForgeEventCancellable;
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import net.jodah.typetools.TypeResolver;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
@@ -41,19 +38,6 @@ import java.util.function.Function;
|
||||
public final class EventFactory {
|
||||
private EventFactory() {}
|
||||
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
public static <T> Event<T> create(Function<T[], T> function) {
|
||||
Class<?>[] arguments = TypeResolver.resolveRawArguments(Function.class, function.getClass());
|
||||
T[] array;
|
||||
try {
|
||||
array = (T[]) Array.newInstance(arguments[1], 0);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return of(list -> function.apply(list.toArray(array)));
|
||||
}
|
||||
|
||||
public static <T> Event<T> of(Function<List<T>, T> function) {
|
||||
return new EventImpl<>(function);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import me.shedaniel.architectury.event.Event;
|
||||
import me.shedaniel.architectury.event.EventFactory;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.TextFilter;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -34,6 +36,16 @@ public interface ChatEvent {
|
||||
|
||||
interface Server {
|
||||
@NotNull
|
||||
InteractionResultHolder<Component> process(ServerPlayer player, String message, Component component);
|
||||
InteractionResult process(ServerPlayer player, TextFilter.FilteredText message, ChatComponent component);
|
||||
}
|
||||
|
||||
interface ChatComponent {
|
||||
Component getRaw();
|
||||
|
||||
Component getFiltered();
|
||||
|
||||
void setRaw(Component raw);
|
||||
|
||||
void setFiltered(Component filtered);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package me.shedaniel.architectury.fluid;
|
||||
|
||||
import me.shedaniel.architectury.hooks.FluidStackHooks;
|
||||
import me.shedaniel.architectury.utils.Fraction;
|
||||
import me.shedaniel.architectury.utils.NbtType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
@@ -33,15 +32,15 @@ import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class FluidStack {
|
||||
private static final FluidStack EMPTY = create(Fluids.EMPTY, Fraction.zero());
|
||||
private Fraction amount;
|
||||
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, Fraction amount, CompoundTag tag) {
|
||||
private FluidStack(Supplier<Fluid> fluid, long amount, CompoundTag tag) {
|
||||
this.fluid = Objects.requireNonNull(fluid);
|
||||
this.amount = Objects.requireNonNull(amount);
|
||||
this.amount = amount;
|
||||
this.tag = tag == null ? null : tag.copy();
|
||||
}
|
||||
|
||||
@@ -49,27 +48,27 @@ public final class FluidStack {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static FluidStack create(Fluid fluid, Fraction amount, @Nullable CompoundTag tag) {
|
||||
public static FluidStack create(Fluid fluid, long amount, @Nullable CompoundTag tag) {
|
||||
return create(() -> fluid, amount, tag);
|
||||
}
|
||||
|
||||
public static FluidStack create(Fluid fluid, Fraction amount) {
|
||||
public static FluidStack create(Fluid fluid, long amount) {
|
||||
return create(fluid, amount, null);
|
||||
}
|
||||
|
||||
public static FluidStack create(Supplier<Fluid> fluid, Fraction amount, @Nullable CompoundTag tag) {
|
||||
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, Fraction amount) {
|
||||
public static FluidStack create(Supplier<Fluid> fluid, long amount) {
|
||||
return create(fluid, amount, null);
|
||||
}
|
||||
|
||||
public static FluidStack create(FluidStack stack, Fraction amount) {
|
||||
public static FluidStack create(FluidStack stack, long amount) {
|
||||
return create(stack.getRawFluidSupplier(), amount, stack.getTag());
|
||||
}
|
||||
|
||||
public static Fraction bucketAmount() {
|
||||
public static long bucketAmount() {
|
||||
return FluidStackHooks.bucketAmount();
|
||||
}
|
||||
|
||||
@@ -87,23 +86,23 @@ public final class FluidStack {
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getRawFluid() == Fluids.EMPTY || !amount.isGreaterThan(Fraction.zero());
|
||||
return getRawFluid() == Fluids.EMPTY || amount <= 0;
|
||||
}
|
||||
|
||||
public Fraction getAmount() {
|
||||
return isEmpty() ? Fraction.zero() : amount;
|
||||
public long getAmount() {
|
||||
return isEmpty() ? 0 : amount;
|
||||
}
|
||||
|
||||
public void setAmount(Fraction amount) {
|
||||
this.amount = Objects.requireNonNull(amount);
|
||||
public void setAmount(long amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public void grow(Fraction amount) {
|
||||
setAmount(this.amount.add(amount));
|
||||
public void grow(long amount) {
|
||||
setAmount(this.amount + amount);
|
||||
}
|
||||
|
||||
public void shrink(Fraction amount) {
|
||||
setAmount(this.amount.minus(amount));
|
||||
public void shrink(long amount) {
|
||||
setAmount(this.amount - amount);
|
||||
}
|
||||
|
||||
public boolean hasTag() {
|
||||
@@ -162,7 +161,7 @@ public final class FluidStack {
|
||||
public final int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + getFluid().hashCode();
|
||||
code = 31 * code + amount.hashCode();
|
||||
code = 31 * code + Long.hashCode(amount);
|
||||
if (tag != null)
|
||||
code = 31 * code + tag.hashCode();
|
||||
return code;
|
||||
@@ -177,7 +176,7 @@ public final class FluidStack {
|
||||
}
|
||||
|
||||
public boolean isFluidStackEqual(FluidStack other) {
|
||||
return getFluid() == other.getFluid() && getAmount().equals(other.getAmount()) && isTagEqual(other);
|
||||
return getFluid() == other.getFluid() && getAmount() == other.getAmount() && isTagEqual(other);
|
||||
}
|
||||
|
||||
private boolean isTagEqual(FluidStack other) {
|
||||
|
||||
@@ -21,7 +21,6 @@ package me.shedaniel.architectury.hooks;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
import me.shedaniel.architectury.fluid.FluidStack;
|
||||
import me.shedaniel.architectury.utils.Fraction;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -83,10 +82,10 @@ public class FluidStackHooks {
|
||||
/**
|
||||
* Platform-specific bucket amount.
|
||||
* Forge: 1000
|
||||
* Fabric: 1
|
||||
* Fabric: 81000
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Fraction bucketAmount() {
|
||||
public static long bucketAmount() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,22 +21,35 @@ package me.shedaniel.architectury.mixin;
|
||||
|
||||
import me.shedaniel.architectury.event.events.BlockEvent;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.item.FallingBlockEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AnvilBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.ConcretePowderBlock;
|
||||
import net.minecraft.world.level.block.FallingBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin({FallingBlock.class, AnvilBlock.class, ConcretePowderBlock.class})
|
||||
public abstract class BlockLandingInvoker {
|
||||
@Inject(method = "onLand", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void handleLand(Level level, BlockPos pos, BlockState fallState, BlockState landOn, FallingBlockEntity entity, CallbackInfo ci) {
|
||||
BlockEvent.FALLING_LAND.invoker().onLand(level, pos, fallState, landOn, entity);
|
||||
@Mixin(FallingBlockEntity.class)
|
||||
public abstract class MixinFallingBlockEntity extends Entity {
|
||||
public MixinFallingBlockEntity(EntityType<?> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
private BlockState blockState;
|
||||
|
||||
@Inject(method = "tick", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/level/block/Fallable;onLand(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/item/FallingBlockEntity;)V"),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void handleLand(CallbackInfo ci, Block block, BlockPos blockPos2, boolean bl, boolean bl2, BlockState blockState) {
|
||||
BlockEvent.FALLING_LAND.invoker().onLand(this.level, blockPos2, this.blockState, blockState, (FallingBlockEntity) (Object) this);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public abstract class MixinLightningBolt extends Entity {
|
||||
by = 1
|
||||
), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
public void handleLightning(CallbackInfo ci, double d0, List<Entity> list) {
|
||||
if (this.removed || this.level.isClientSide) {
|
||||
if (this.isRemoved() || this.level.isClientSide) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.registry.entity;
|
||||
|
||||
import me.shedaniel.architectury.annotations.ExpectPlatform;
|
||||
@@ -5,6 +24,7 @@ import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
@@ -15,7 +35,7 @@ public final class EntityRenderers {
|
||||
private EntityRenderers() {}
|
||||
|
||||
@ExpectPlatform
|
||||
public static <T extends Entity> void register(EntityType<T> type, Function<EntityRenderDispatcher, EntityRenderer<T>> factory) {
|
||||
public static <T extends Entity> void register(EntityType<T> type, EntityRendererProvider<T> provider) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.utils;
|
||||
|
||||
import com.google.common.math.LongMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public final class Fraction extends Number implements Comparable<Fraction> {
|
||||
private static final Fraction[] SIMPLE_CACHE = new Fraction[2048];
|
||||
private static final Fraction ZERO = ofWhole(0);
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.###");
|
||||
private final long numerator;
|
||||
private final long denominator;
|
||||
private boolean simplified;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 2048; i++) {
|
||||
SIMPLE_CACHE[i] = new Fraction(i - 1024, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private Fraction(long numerator, long denominator) {
|
||||
if (denominator > 0) {
|
||||
this.numerator = numerator;
|
||||
this.denominator = denominator;
|
||||
} else if (denominator < 0) {
|
||||
this.numerator = -numerator;
|
||||
this.denominator = -denominator;
|
||||
} else {
|
||||
throw new ArithmeticException("/ by zero");
|
||||
}
|
||||
this.simplified = (this.numerator >= -1 && this.numerator <= 1) || this.denominator == 1;
|
||||
}
|
||||
|
||||
public static Fraction zero() {
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
public static Fraction ofWhole(long whole) {
|
||||
if (whole >= -1024 && whole < 1024) {
|
||||
Fraction cached = SIMPLE_CACHE[(int) whole + 1024];
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
return new Fraction(whole, 1);
|
||||
}
|
||||
|
||||
public static Fraction of(long numerator, long denominator) {
|
||||
if (denominator == 1)
|
||||
return ofWhole(numerator);
|
||||
if (denominator == -1)
|
||||
return ofWhole(-numerator);
|
||||
return new Fraction(numerator, denominator);
|
||||
}
|
||||
|
||||
public static Fraction of(long whole, long numerator, long denominator) {
|
||||
return of(numerator + whole * denominator, denominator);
|
||||
}
|
||||
|
||||
public static Fraction from(double value) {
|
||||
int whole = (int) value;
|
||||
double part = value - whole;
|
||||
int i = 1;
|
||||
|
||||
while (true) {
|
||||
double tem = part / (1D / i);
|
||||
long numerator = Math.round(tem);
|
||||
if (Math.abs(tem - numerator) < 0.00001) {
|
||||
return of(whole, numerator, i);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public long getNumerator() {
|
||||
return numerator;
|
||||
}
|
||||
|
||||
public long getDenominator() {
|
||||
return denominator;
|
||||
}
|
||||
|
||||
public Fraction add(Fraction other) {
|
||||
if (other.numerator == 0) return this;
|
||||
return of(numerator * other.denominator + other.numerator * denominator, denominator * other.denominator);
|
||||
}
|
||||
|
||||
public Fraction minus(Fraction other) {
|
||||
if (other.numerator == 0) return this;
|
||||
return of(numerator * other.denominator - other.numerator * denominator, denominator * other.denominator);
|
||||
}
|
||||
|
||||
public Fraction multiply(Fraction other) {
|
||||
if (other.numerator == other.denominator) return this;
|
||||
return of(numerator * other.numerator, denominator * other.denominator);
|
||||
}
|
||||
|
||||
public Fraction divide(Fraction other) {
|
||||
if (other.numerator == other.denominator) return this;
|
||||
return of(numerator * other.denominator, denominator * other.numerator);
|
||||
}
|
||||
|
||||
public Fraction inverse() {
|
||||
if (numerator == denominator)
|
||||
return this;
|
||||
Fraction fraction = of(denominator, numerator);
|
||||
fraction.simplified = fraction.simplified && this.simplified;
|
||||
return fraction;
|
||||
}
|
||||
|
||||
public Fraction simplify() {
|
||||
if (simplified)
|
||||
return this;
|
||||
if (numerator == 0)
|
||||
return ofWhole(0);
|
||||
long gcd = LongMath.gcd(Math.abs(numerator), denominator);
|
||||
Fraction fraction = of(numerator / gcd, denominator / gcd);
|
||||
fraction.simplified = true;
|
||||
return fraction;
|
||||
}
|
||||
|
||||
public boolean isGreaterThan(Fraction fraction) {
|
||||
return compareTo(fraction) > 0;
|
||||
}
|
||||
|
||||
public boolean isLessThan(Fraction fraction) {
|
||||
return compareTo(fraction) < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Fraction fraction = (Fraction) o;
|
||||
return numerator * fraction.denominator == denominator * fraction.numerator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Double.hashCode(doubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Fraction fraction) {
|
||||
return Long.compare(numerator * fraction.denominator, denominator * fraction.numerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() {
|
||||
return (int) longValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue() {
|
||||
return numerator / denominator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
return (float) numerator / denominator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue() {
|
||||
return (double) numerator / denominator;
|
||||
}
|
||||
|
||||
public String toDecimalString() {
|
||||
return DECIMAL_FORMAT.format(doubleValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (intValue() == doubleValue()) return toDecimalString();
|
||||
return String.format("%s (%d/%d)", toDecimalString(), numerator, denominator);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
"minVersion": "0.7.11",
|
||||
"client": [
|
||||
],
|
||||
"mixins": ["BlockLandingInvoker", "FluidTagsAccessor", "MixinLightningBolt"],
|
||||
"mixins": ["MixinFallingBlockEntity", "FluidTagsAccessor", "MixinLightningBolt"],
|
||||
"injectors": {
|
||||
"maxShiftBy": 5,
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -30,9 +30,7 @@ dependencies {
|
||||
mappings minecraft.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
|
||||
modCompileOnly "com.terraformersmc:modmenu:${rootProject.mod_menu_version}"
|
||||
implementation "net.jodah:typetools:0.6.2"
|
||||
shadowCommon "net.jodah:typetools:0.6.2"
|
||||
modCompileOnly("com.terraformersmc:modmenu:${rootProject.mod_menu_version}") { transitive false }
|
||||
|
||||
implementation(project(path: ":common")) {
|
||||
transitive = false
|
||||
@@ -53,7 +51,6 @@ processResources {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate "net.jodah.typetools", "me.shedaniel.architectury.shadowed.impl.net.jodah.typetools"
|
||||
configurations = [project.configurations.shadowCommon]
|
||||
classifier "shadow"
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package me.shedaniel.architectury.hooks.fabric;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.EntityCollisionContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EntityHooksImpl {
|
||||
@@ -30,13 +31,6 @@ public class EntityHooksImpl {
|
||||
|
||||
@Nullable
|
||||
public static Entity fromCollision(CollisionContext ctx) {
|
||||
return ((CollisionContextExtension) ctx).getEntity();
|
||||
}
|
||||
|
||||
public interface CollisionContextExtension {
|
||||
@Nullable
|
||||
default Entity getEntity() {
|
||||
return null;
|
||||
}
|
||||
return ctx instanceof EntityCollisionContext ? ((EntityCollisionContext) ctx).getEntity().orElse(null) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ package me.shedaniel.architectury.hooks.fabric;
|
||||
import me.shedaniel.architectury.fluid.FluidStack;
|
||||
import me.shedaniel.architectury.platform.Platform;
|
||||
import me.shedaniel.architectury.utils.Env;
|
||||
import me.shedaniel.architectury.utils.Fraction;
|
||||
import me.shedaniel.architectury.utils.NbtType;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
@@ -66,7 +65,7 @@ public class FluidStackHooksImpl {
|
||||
|
||||
public static FluidStack read(FriendlyByteBuf buf) {
|
||||
Fluid fluid = Objects.requireNonNull(Registry.FLUID.get(buf.readResourceLocation()));
|
||||
Fraction amount = Fraction.of(buf.readVarLong(), buf.readVarLong());
|
||||
long amount = buf.readVarLong();
|
||||
CompoundTag tag = buf.readNbt();
|
||||
if (fluid == Fluids.EMPTY) return FluidStack.empty();
|
||||
return FluidStack.create(fluid, amount, tag);
|
||||
@@ -74,8 +73,7 @@ public class FluidStackHooksImpl {
|
||||
|
||||
public static void write(FluidStack stack, FriendlyByteBuf buf) {
|
||||
buf.writeResourceLocation(Registry.FLUID.getKey(stack.getFluid()));
|
||||
buf.writeVarLong(stack.getAmount().getNumerator());
|
||||
buf.writeVarLong(stack.getAmount().getDenominator());
|
||||
buf.writeVarLong(stack.getAmount());
|
||||
buf.writeNbt(stack.getTag());
|
||||
}
|
||||
|
||||
@@ -88,9 +86,8 @@ public class FluidStackHooksImpl {
|
||||
if (fluid == null || fluid == Fluids.EMPTY) {
|
||||
return FluidStack.empty();
|
||||
}
|
||||
long numerator = tag.getLong("numerator");
|
||||
long denominator = tag.getLong("denominator");
|
||||
FluidStack stack = FluidStack.create(fluid, Fraction.of(numerator, denominator));
|
||||
long amount = tag.getLong("amount");
|
||||
FluidStack stack = FluidStack.create(fluid, amount);
|
||||
|
||||
if (tag.contains("tag", NbtType.COMPOUND)) {
|
||||
stack.setTag(tag.getCompound("tag"));
|
||||
@@ -100,16 +97,15 @@ public class FluidStackHooksImpl {
|
||||
|
||||
public static CompoundTag write(FluidStack stack, CompoundTag tag) {
|
||||
tag.putString("id", Registry.FLUID.getKey(stack.getFluid()).toString());
|
||||
tag.putLong("numerator", stack.getAmount().getNumerator());
|
||||
tag.putLong("denominator", stack.getAmount().getDenominator());
|
||||
tag.putLong("amount", stack.getAmount());
|
||||
if (stack.hasTag()) {
|
||||
tag.put("tag", stack.getTag());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static Fraction bucketAmount() {
|
||||
return Fraction.ofWhole(1);
|
||||
public static long bucketAmount() {
|
||||
return 81000;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.hooks.fabric;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.impl.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.ChatEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class ChatComponentImpl implements ChatEvent.ChatComponent {
|
||||
private Component raw;
|
||||
private Component filtered;
|
||||
|
||||
public ChatComponentImpl(Component raw, Component filtered) {
|
||||
this.raw = raw;
|
||||
this.filtered = filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRaw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getFiltered() {
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(Component raw) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFiltered(Component filtered) {
|
||||
this.filtered = filtered;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public interface MixinBlockEntityExtension extends BlockEntityClientSerializable
|
||||
default void fromClientTag(CompoundTag tag) {
|
||||
BlockEntity entity = (BlockEntity) this;
|
||||
if (entity.hasLevel()) {
|
||||
loadClientData(entity.getBlockState(), tag);
|
||||
((BlockEntityExtension) this).loadClientData(entity.getBlockState(), tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(CollisionContext.class)
|
||||
public interface MixinCollisionContext extends EntityHooksImpl.CollisionContextExtension {
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.hooks.fabric.EntityHooksImpl;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.EntityCollisionContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(EntityCollisionContext.class)
|
||||
public abstract class MixinEntityCollisionContext implements CollisionContext, EntityHooksImpl.CollisionContextExtension {
|
||||
|
||||
@Unique
|
||||
private Entity entity = null;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/entity/Entity;)V",
|
||||
at = @At("RETURN"))
|
||||
public void saveEntity(Entity entity, CallbackInfo ci) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.EntityEvent;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package me.shedaniel.architectury.mixin.fabric;
|
||||
|
||||
import me.shedaniel.architectury.event.events.ChatEvent;
|
||||
import me.shedaniel.architectury.impl.fabric.ChatComponentImpl;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
@@ -27,6 +28,7 @@ import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.network.TextFilter;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -36,6 +38,9 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public abstract class MixinServerGamePacketListenerImpl {
|
||||
@@ -48,17 +53,19 @@ public abstract class MixinServerGamePacketListenerImpl {
|
||||
@Shadow
|
||||
public abstract void disconnect(Component component);
|
||||
|
||||
@Inject(method = "handleChat(Ljava/lang/String;)V",
|
||||
@Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"),
|
||||
cancellable = true)
|
||||
private void handleChat(String message, CallbackInfo ci) {
|
||||
Component component = new TranslatableComponent("chat.type.text", this.player.getDisplayName(), message);
|
||||
InteractionResultHolder<Component> process = ChatEvent.SERVER.invoker().process(this.player, message, component);
|
||||
if (process.getResult() == InteractionResult.FAIL)
|
||||
target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V"),
|
||||
cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void handleChat(TextFilter.FilteredText message, CallbackInfo ci, String string, Component component, Component component2) {
|
||||
ChatComponentImpl chatComponent = new ChatComponentImpl(component2, component);
|
||||
InteractionResult process = ChatEvent.SERVER.invoker().process(this.player, message, chatComponent);
|
||||
if (process == InteractionResult.FAIL)
|
||||
ci.cancel();
|
||||
else if (process.getObject() != null && !process.getObject().equals(component)) {
|
||||
this.server.getPlayerList().broadcastMessage(component, ChatType.CHAT, this.player.getUUID());
|
||||
else if (!Objects.equals(chatComponent.getRaw(), component2) || !Objects.equals(chatComponent.getFiltered(), component)) {
|
||||
this.server.getPlayerList().broadcastMessage(chatComponent.getRaw(), (serverPlayer) -> {
|
||||
return this.player.shouldFilterMessageTo(serverPlayer) ? chatComponent.getFiltered() : chatComponent.getRaw();
|
||||
}, ChatType.CHAT, this.player.getUUID());
|
||||
|
||||
this.chatSpamTickCount += 20;
|
||||
if (this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) {
|
||||
|
||||
@@ -105,8 +105,8 @@ public class MixinMouseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onPress", at = @At(value = "FIELD",
|
||||
target = "Lnet/minecraft/client/Minecraft;overlay:Lnet/minecraft/client/gui/screens/Overlay;",
|
||||
@Inject(method = "onPress", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/Minecraft;getOverlay()Lnet/minecraft/client/gui/screens/Overlay;",
|
||||
ordinal = 0), cancellable = true)
|
||||
public void onRawMouseClicked(long handle, int button, int action, int mods, CallbackInfo info) {
|
||||
if (!info.isCancelled()) {
|
||||
|
||||
@@ -1,15 +1,35 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.registry.entity.fabric;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EntityRenderersImpl {
|
||||
public static <T extends Entity> void register(EntityType<T> type, Function<EntityRenderDispatcher, EntityRenderer<T>> factory) {
|
||||
EntityRendererRegistry.INSTANCE.register(type, (manager, context) -> factory.apply(manager));
|
||||
public static <T extends Entity> void register(EntityType<T> type, EntityRendererProvider<T> provider) {
|
||||
EntityRendererRegistry.INSTANCE.register(type, provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
"LivingDeathInvoker",
|
||||
"MixinBlockEntityExtension",
|
||||
"MixinBlockItem",
|
||||
"MixinCollisionContext",
|
||||
"MixinCommands",
|
||||
"MixinDedicatedServer",
|
||||
"MixinEntityCollisionContext",
|
||||
"MixinExplosion",
|
||||
"MixinFurnaceResultSlot",
|
||||
"MixinItemEntity",
|
||||
|
||||
@@ -25,8 +25,6 @@ dependencies {
|
||||
minecraft "com.mojang:minecraft:${rootProject.architectury.minecraft}"
|
||||
mappings loom.officialMojangMappings()
|
||||
forge "net.minecraftforge:forge:${rootProject.architectury.minecraft}-${rootProject.forge_version}"
|
||||
implementation "net.jodah:typetools:0.6.2"
|
||||
shadowCommon "net.jodah:typetools:0.6.2"
|
||||
|
||||
implementation(project(path: ":common")) {
|
||||
transitive = false
|
||||
@@ -47,7 +45,6 @@ processResources {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate "net.jodah.typetools", "me.shedaniel.architectury.shadowed.impl.net.jodah.typetools"
|
||||
exclude "fabric.mod.json"
|
||||
exclude "architectury-common.accessWidener"
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ public class FluidStackHooksImpl {
|
||||
return FluidStackHooksForge.toForge(stack).writeToNBT(tag);
|
||||
}
|
||||
|
||||
public static Fraction bucketAmount() {
|
||||
return Fraction.ofWhole(1000);
|
||||
public static long bucketAmount() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
||||
@@ -87,7 +87,6 @@ public class ClientOverlayMessageSink extends ConsoleMessageSink {
|
||||
}
|
||||
}
|
||||
|
||||
RenderSystem.disableAlphaTest();
|
||||
RenderSystem.disableBlend();
|
||||
matrices.popPose();
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public class DebugEvents {
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
ChatEvent.SERVER.register((player, message, component) -> {
|
||||
SINK.accept("Server chat received: " + message);
|
||||
return InteractionResultHolder.pass(component);
|
||||
SINK.accept("Server chat received: " + message.getRaw());
|
||||
return InteractionResult.PASS;
|
||||
});
|
||||
CommandPerformEvent.EVENT.register(event -> {
|
||||
SINK.accept("Server command performed: " + event.getResults().getReader().getString());
|
||||
|
||||
Reference in New Issue
Block a user