diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 5814dc963..ad65a17f5 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -46,8 +46,10 @@ import appeng.core.config.DoubleOption; import appeng.core.config.EnumOption; import appeng.core.config.IntegerOption; import appeng.core.config.StringListOption; +import appeng.core.config.StringOption; import appeng.core.settings.TickRates; import appeng.util.EnumCycler; +import com.google.common.base.Strings; import javax.annotation.Nullable; @@ -406,7 +408,7 @@ public final class AEConfig { } public float getImprovedFluidMultiplier() { - return commonConfig.improvedFluidMultiplier.get().floatValue(); + return (float) commonConfig.improvedFluidMultiplier.get(); } // Setters keep visibility as low as possible. @@ -625,7 +627,7 @@ public final class AEConfig { improvedFluidTag = inWorldPurification.addString("improvedFluidTag", "", "A fluid tag that identifies fluids that improve crystal purification speed. Does not affect purification with water/lava."); improvedFluidMultiplier = inWorldPurification - .addDouble("improvedFluidMultiplier", 2.0, 1.0, 10.0, "The speed multiplier to use when the crystals are submerged in the improved fluid.") + .addDouble("improvedFluidMultiplier", 2.0, 1.0, 10.0, "The speed multiplier to use when the crystals are submerged in the improved fluid."); } } diff --git a/src/main/java/appeng/core/config/ConfigSection.java b/src/main/java/appeng/core/config/ConfigSection.java index 6823c0c7d..46e8811fd 100644 --- a/src/main/java/appeng/core/config/ConfigSection.java +++ b/src/main/java/appeng/core/config/ConfigSection.java @@ -58,6 +58,14 @@ public class ConfigSection { return option; } + public StringOption addString(String id, String defaultValue) { + return addString(id, defaultValue, comment); + } + + public StringOption addString(String id, String defaultValue, String comment) { + return addOption(new StringOption(this, id, comment, defaultValue)); + } + public IntegerOption addInt(String id, int defaultValue) { return addInt(id, defaultValue, comment); } diff --git a/src/main/java/appeng/core/config/StringOption.java b/src/main/java/appeng/core/config/StringOption.java new file mode 100644 index 000000000..f20116a47 --- /dev/null +++ b/src/main/java/appeng/core/config/StringOption.java @@ -0,0 +1,63 @@ +package appeng.core.config; + +import com.google.common.base.Preconditions; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; + +public class StringOption extends BaseOption { + + private final String defaultValue; + private String currentValue; + + public StringOption(ConfigSection parent, String id, String comment, String defaultValue) { + super(parent, id, comment); + this.defaultValue = defaultValue; + this.currentValue = this.defaultValue; + } + + public String get() { + return currentValue; + } + + public void set(String value) { + Preconditions.checkNotNull(value); + if (value.equals(currentValue)) { + return; + } + currentValue = value; + parent.markDirty(); + } + + @Override + protected JsonElement write() { + return new JsonPrimitive(currentValue); + } + + @Override + protected void read(JsonElement element) { + if (!element.isJsonPrimitive()) { + throw new ConfigValidationException(this, "Expected a JSON primitive: " + element); + } + JsonPrimitive primitive = element.getAsJsonPrimitive(); + if (!primitive.isString()) { + throw new ConfigValidationException(this, "Expected a JSON string, but found: " + primitive); + } + + this.currentValue = primitive.getAsString(); + } + + @Override + public boolean isDifferentFromDefault() { + return !currentValue.equals(defaultValue); + } + + @Override + public String getDefaultAsString() { + return defaultValue; + } + + @Override + public String getCurrentValueAsString() { + return currentValue; + } +} diff --git a/src/main/java/appeng/entity/GrowingCrystalEntity.java b/src/main/java/appeng/entity/GrowingCrystalEntity.java index dfd3d7ff6..a3518d1c1 100644 --- a/src/main/java/appeng/entity/GrowingCrystalEntity.java +++ b/src/main/java/appeng/entity/GrowingCrystalEntity.java @@ -19,14 +19,14 @@ package appeng.entity; import net.minecraft.block.BlockState; -import net.minecraft.block.Material; import net.minecraft.block.entity.BlockEntity; import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import appeng.api.features.AEFeature; @@ -37,7 +37,6 @@ import appeng.core.AEConfig; import appeng.core.AppEng; import appeng.items.misc.CrystalSeedItem; import appeng.mixins.ItemEntityAccessor; -import appeng.util.Platform; public class GrowingCrystalEntity extends AEBaseItemEntity { @@ -46,7 +45,8 @@ public class GrowingCrystalEntity extends AEBaseItemEntity { // Growth tick progress per tick by number of adjacent accelerators // Expressed as 1/1000th of a growth tick, applied to progress_1000 // each time this entity ticks. - private static final int[] GROWTH_TICK_PROGRESS = { 1, // no accelerators + private static final int[] GROWTH_TICK_PROGRESS = { // + 1, // no accelerators 40, // 1 accelerator 92, // 2 accelerators 159, // 3 accelerators @@ -94,9 +94,9 @@ public class GrowingCrystalEntity extends AEBaseItemEntity { return; } - final int x = MathHelper.floor(this.getPosX()); + final int x = MathHelper.floor(this.getX()); final int y = MathHelper.floor((this.getBoundingBox().minY + this.getBoundingBox().maxY) / 2.0D); - final int z = MathHelper.floor(this.getPosZ()); + final int z = MathHelper.floor(this.getZ()); BlockPos pos = new BlockPos(x, y, z); final BlockState state = this.world.getBlockState(pos); @@ -111,7 +111,7 @@ public class GrowingCrystalEntity extends AEBaseItemEntity { final int progressPerTick = (int) Math.max(1, this.getSpeed(pos) * multiplier); - if (world.isRemote()) { + if (world.isClient()) { // On the client, we reuse the growth-tick-progress // as a tick-counter for particle effects int len = getTicksBetweenParticleEffects(progressPerTick); @@ -183,7 +183,7 @@ public class GrowingCrystalEntity extends AEBaseItemEntity { BlockPos.Mutable testPos = new BlockPos.Mutable(); for (Direction direction : Direction.values()) { - if (this.isPoweredAccelerator(testPos.func_239622_a_(pos, direction))) { + if (this.isPoweredAccelerator(testPos.set(pos, direction))) { count++; } } @@ -205,13 +205,13 @@ public class GrowingCrystalEntity extends AEBaseItemEntity { // automation based around dropping seeds between 5 CGAs, then catchiung // them on their way up. if (item.getItem() instanceof CrystalSeedItem) { - Vector3d v = this.getMotion(); + Vec3d v = this.getVelocity(); // Apply a much smaller acceleration to make them slowly sink double yAccel = this.hasNoGravity() ? 0 : -0.002; // Apply the x/z slow-down, and the y acceleration - this.setMotion(v.x * 0.99, v.y + yAccel, v.z * 0.99); + this.setVelocity(v.x * 0.99, v.y + yAccel, v.z * 0.99); return; } diff --git a/src/main/java/appeng/fluids/parts/FluidImportBusPart.java b/src/main/java/appeng/fluids/parts/FluidImportBusPart.java index 86f516c8c..5f1b14051 100644 --- a/src/main/java/appeng/fluids/parts/FluidImportBusPart.java +++ b/src/main/java/appeng/fluids/parts/FluidImportBusPart.java @@ -141,10 +141,10 @@ public class FluidImportBusPart extends SharedFluidBusPart { return TickRateModulation.IDLE; } catch (GridAccessException e) { - // skip - } + // skip } } + return TickRateModulation.SLEEP; } diff --git a/src/main/java/appeng/items/misc/CrystalSeedItem.java b/src/main/java/appeng/items/misc/CrystalSeedItem.java index 208495829..d2f2b1017 100644 --- a/src/main/java/appeng/items/misc/CrystalSeedItem.java +++ b/src/main/java/appeng/items/misc/CrystalSeedItem.java @@ -18,36 +18,39 @@ package appeng.items.misc; -import java.util.List; - -import javax.annotation.Nullable; - -import com.google.common.base.Preconditions; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.block.Material; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ItemEntity; -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; - import appeng.api.implementations.items.IGrowableCrystal; import appeng.core.AEConfig; import appeng.core.localization.ButtonToolTips; import appeng.entity.GrowingCrystalEntity; import appeng.hooks.AECustomEntityItem; import appeng.items.AEBaseItem; +import com.google.common.base.Preconditions; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.tag.TagRegistry; +import net.minecraft.block.BlockState; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; +import net.minecraft.item.ItemConvertible; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.tag.FluidTags; +import net.minecraft.tag.Tag; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.util.List; /** * This item reprents one of the seeds used to grow various forms of quartz by @@ -70,9 +73,15 @@ public class CrystalSeedItem extends AEBaseItem implements IGrowableCrystal, AEC */ private final ItemConvertible grownItem; + private final Tag improvedFluidTag; + public CrystalSeedItem(Settings properties, ItemConvertible grownItem) { super(properties); this.grownItem = Preconditions.checkNotNull(grownItem); + + String improvedFluidTagName = AEConfig.instance().getImprovedFluidTag(); + this.improvedFluidTag = improvedFluidTagName != null ? + TagRegistry.fluid(new Identifier(improvedFluidTagName)) : null; } @Nullable @@ -101,20 +110,17 @@ public class CrystalSeedItem extends AEBaseItem implements IGrowableCrystal, AEC public float getMultiplier(BlockState state, @Nullable World world, @Nullable BlockPos pos) { // Check for the improved fluid tag and return the improved multiplier - String improvedFluidTagName = AEConfig.instance().getImprovedFluidTag(); - if (improvedFluidTagName != null) { - ITag tag = FluidTags.getCollection().get(new ResourceLocation(improvedFluidTagName)); - if (tag != null && state.getFluidState().isTagged(tag)) { - return AEConfig.instance().getImprovedFluidMultiplier(); - } + FluidState fluidState = state.getFluidState(); + if (improvedFluidTag != null && fluidState.isIn(improvedFluidTag)) { + return AEConfig.instance().getImprovedFluidMultiplier(); } // Check for the normal supported fluid - if (world != null && world.func_234923_W_() == World.field_234919_h_) { + if (world != null && world.getRegistryKey() == World.NETHER) { // In the nether, use Lava as the "normal" fluid - return state.getFluidState().isTagged(FluidTags.LAVA) ? 1 : 0; + return fluidState.isIn(FluidTags.LAVA) ? 1 : 0; } else { - return state.getFluidState().isTagged(FluidTags.WATER) ? 1 : 0; + return fluidState.isIn(FluidTags.WATER) ? 1 : 0; } } diff --git a/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java b/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java index 2767c22de..9690a27c6 100644 --- a/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/QuantumCluster.java @@ -159,7 +159,7 @@ public class QuantumCluster implements ILocatable, IAECluster { // In future versions, we might actually want to delay the entire registration // until the center // tile begins ticking normally. - if (theWorld.isBlockLoaded(qc.center.getPos())) { + if (theWorld.isChunkLoaded(qc.center.getPos())) { final World cur = theWorld.getServer().getWorld(theWorld.getRegistryKey()); final BlockEntity te = theWorld.getBlockEntity(qc.center.getPos()); diff --git a/src/main/java/appeng/mixins/tags/FluidTagsAccessor.java b/src/main/java/appeng/mixins/tags/FluidTagsAccessor.java index dfe3098c0..931b23e90 100644 --- a/src/main/java/appeng/mixins/tags/FluidTagsAccessor.java +++ b/src/main/java/appeng/mixins/tags/FluidTagsAccessor.java @@ -1,6 +1,9 @@ package appeng.mixins.tags; +import net.minecraft.tag.RequiredTagList; +import net.minecraft.tag.TagGroup; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; import net.minecraft.fluid.Fluid; @@ -15,4 +18,9 @@ public interface FluidTagsAccessor { throw new AssertionError(); } + @Accessor("REQUIRED_TAGS") + static RequiredTagList getRequiredTags() { + throw new AssertionError(); + } + } diff --git a/src/main/java/appeng/parts/VoxelShapeCache.java b/src/main/java/appeng/parts/VoxelShapeCache.java index 52b28f3ac..2aff9b9f6 100644 --- a/src/main/java/appeng/parts/VoxelShapeCache.java +++ b/src/main/java/appeng/parts/VoxelShapeCache.java @@ -18,21 +18,20 @@ package appeng.parts; -import java.util.List; - import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import net.minecraft.util.function.BooleanBiFunction; +import net.minecraft.util.math.Box; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.shapes.IBooleanFunction; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; +import java.util.List; /** - * While creation of a {@link VoxelShape} with - * {@link VoxelShapes#create(AxisAlignedBB)} is fast enough, combining voxel - * shapes with {@link VoxelShapes#or(VoxelShape, VoxelShape)} or any other + * While creation of a {@link net.minecraft.util.shape.VoxelShape} with + * {@link net.minecraft.util.shape.VoxelShapes#cuboid(Box)} is fast enough, combining voxel + * shapes with {@link net.minecraft.util.shape.VoxelShapes#union(VoxelShape, VoxelShape)} or any other * combination method, as well as {@link VoxelShape#simplify()} are extremely * slow. For example: Creating a VoxelShape for a list of 5 bounding boxes * 10,000 times takes about 1.7 seconds. @@ -48,11 +47,11 @@ final class VoxelShapeCache { // are iterated over in a fixed order, meaning the order of bounding boxes // should // be the same for a same set of parts. - private static final LoadingCache, VoxelShape> CACHE = CacheBuilder.newBuilder()// + private static final LoadingCache, VoxelShape> CACHE = CacheBuilder.newBuilder()// .maximumSize(10000L)// - .build(new CacheLoader, VoxelShape>() { + .build(new CacheLoader, VoxelShape>() { @Override - public VoxelShape load(List key) { + public VoxelShape load(List key) { return create(key); } }); @@ -60,20 +59,20 @@ final class VoxelShapeCache { private VoxelShapeCache() { } - public static VoxelShape get(List boxes) { + public static VoxelShape get(List boxes) { return CACHE.getUnchecked(boxes); } - private static VoxelShape create(List boxes) { + private static VoxelShape create(List boxes) { if (boxes.isEmpty()) { return VoxelShapes.empty(); } int i = 0; - VoxelShape shape = VoxelShapes.create(boxes.get(i)); + VoxelShape shape = VoxelShapes.cuboid(boxes.get(i)); for (; i < boxes.size(); i++) { - AxisAlignedBB box = boxes.get(i); - shape = VoxelShapes.combine(shape, VoxelShapes.create(box), IBooleanFunction.OR); + Box box = boxes.get(i); + shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(box), BooleanBiFunction.OR); } return shape.simplify(); }