Update to 21w14a, remove typetools, remove fractions in favor of 81000

This commit is contained in:
shedaniel
2021-04-09 22:45:04 +08:00
parent c56ca3cc6a
commit c2cb308655
27 changed files with 223 additions and 336 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -5,7 +5,7 @@
"minVersion": "0.7.11",
"client": [
],
"mixins": ["BlockLandingInvoker", "FluidTagsAccessor", "MixinLightningBolt"],
"mixins": ["MixinFallingBlockEntity", "FluidTagsAccessor", "MixinLightningBolt"],
"injectors": {
"maxShiftBy": 5,
"defaultRequire": 1