From a6d512356ca6bdcea6d5112095c7edc313cd490f Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 23 Feb 2025 14:42:39 -0500 Subject: [PATCH 1/3] Remove unused imports --- .../java/com/simibubi/create/AllKeys.java | 8 +- .../peripherals/StationPeripheral.java | 19 ++-- .../contraptions/pulley/RopePulleyVisual.java | 2 - .../equipment/toolbox/ToolboxBlock.java | 8 +- .../create/content/fluids/VirtualFluid.java | 3 +- .../kinetics/base/OrientedRotatingVisual.java | 5 +- .../crank/ValveHandleBlockEntity.java | 17 ++-- .../kinetics/drill/DrillActorVisual.java | 25 +++--- .../kinetics/gearbox/GearboxVisual.java | 88 +++++++++---------- .../kinetics/mechanicalArm/ArmVisual.java | 11 ++- .../content/kinetics/mixer/MixerVisual.java | 14 ++- .../encased/EncasedCogVisual.java | 6 -- .../sequencer/SequencedGearshiftScreen.java | 7 +- .../content/logistics/box/PackageVisual.java | 2 - .../attribute/SingletonItemAttribute.java | 10 +-- .../AllItemAttributeLegacyDeserializers.java | 1 - .../StandardTraitsLegacyDeserializer.java | 1 - .../StockKeeperCategoryScreen.java | 47 +++++----- .../content/processing/basin/BasinRecipe.java | 1 - .../burner/ScrollTransformedInstance.java | 5 +- .../ThresholdSwitchScreen.java | 29 +++--- .../schematics/ServerSchematicLoader.java | 31 ++++--- .../client/ClientSchematicLoader.java | 12 +-- .../foundation/block/CopperBlockSet.java | 43 ++++----- .../scrollValue/ScrollValueBehaviour.java | 4 +- .../create/foundation/data/MetalBarsGen.java | 6 +- .../foundation/fluid/FluidIngredient.java | 2 +- .../command/DumpRailwaysCommand.java | 45 +++++----- .../gametest/tests/TestMisc.java | 5 +- .../ponder/scenes/ElevatorScenes.java | 23 +++-- .../ponder/scenes/RedstoneScenes.java | 7 +- 31 files changed, 223 insertions(+), 264 deletions(-) diff --git a/src/main/java/com/simibubi/create/AllKeys.java b/src/main/java/com/simibubi/create/AllKeys.java index a3a39a6319..b4b99de6a4 100644 --- a/src/main/java/com/simibubi/create/AllKeys.java +++ b/src/main/java/com/simibubi/create/AllKeys.java @@ -1,9 +1,6 @@ package com.simibubi.create; -import com.simibubi.create.AllSoundEvents.SoundEntry; -import com.tterrag.registrate.providers.ProviderType; - -import net.minecraftforge.data.loading.DatagenModLoader; +import java.util.function.BiConsumer; import org.lwjgl.glfw.GLFW; @@ -12,13 +9,12 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; + import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import java.util.function.BiConsumer; - @EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) public enum AllKeys { diff --git a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java index aa1cd09d54..3f40a9f210 100644 --- a/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java +++ b/src/main/java/com/simibubi/create/compat/computercraft/implementation/peripherals/StationPeripheral.java @@ -4,8 +4,6 @@ import java.util.Map; import javax.annotation.Nullable; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import org.jetbrains.annotations.NotNull; import com.simibubi.create.AllPackets; @@ -29,6 +27,7 @@ import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NumericTag; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; +import net.minecraft.network.chat.Component; import net.minecraftforge.network.PacketDistributor; @@ -130,7 +129,7 @@ public class StationPeripheral extends SyncedPeripheral { @LuaFunction(mainThread = true) public final void setTrainName(String name) throws LuaException { Train train = getTrainOrThrow(); - train.name = Component.literal(name); + train.name = Component.literal(name); AllPackets.getChannel().send(PacketDistributor.ALL.noArg(), new TrainEditPacket.TrainEditReturnPacket(train.id, name, train.icon.getId(), train.mapColorIndex)); } @@ -211,8 +210,8 @@ public class StationPeripheral extends SyncedPeripheral { for (String compoundKey : compoundTag.getAllKeys()) { table.put( - StringHelper.camelCaseToSnakeCase(compoundKey), - fromNBTTag(compoundKey, compoundTag.get(compoundKey)) + StringHelper.camelCaseToSnakeCase(compoundKey), + fromNBTTag(compoundKey, compoundTag.get(compoundKey)) ); } @@ -256,11 +255,11 @@ public class StationPeripheral extends SyncedPeripheral { throw new LuaException("table key is not of type string"); compound.put( - // Items serialize their resource location as "id" and not as "Id". - // This check is needed to see if the 'i' should be left lowercase or not. - // Items store "count" in the same compound tag, so we can check for its presence to see if this is a serialized item - compoundKey.equals("id") && v.containsKey("count") ? "id" : StringHelper.snakeCaseToCamelCase(compoundKey), - toNBTTag(compoundKey, v.get(compoundKey)) + // Items serialize their resource location as "id" and not as "Id". + // This check is needed to see if the 'i' should be left lowercase or not. + // Items store "count" in the same compound tag, so we can check for its presence to see if this is a serialized item + compoundKey.equals("id") && v.containsKey("count") ? "id" : StringHelper.snakeCaseToCamelCase(compoundKey), + toNBTTag(compoundKey, v.get(compoundKey)) ); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/pulley/RopePulleyVisual.java b/src/main/java/com/simibubi/create/content/contraptions/pulley/RopePulleyVisual.java index aceb7c5402..de5dbb3cf0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/pulley/RopePulleyVisual.java +++ b/src/main/java/com/simibubi/create/content/contraptions/pulley/RopePulleyVisual.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.contraptions.pulley; -import com.simibubi.create.AllBlocks; import com.simibubi.create.AllPartialModels; import com.simibubi.create.AllSpriteShifts; import com.simibubi.create.content.processing.burner.ScrollInstance; @@ -13,7 +12,6 @@ import dev.engine_room.flywheel.lib.instance.InstanceTypes; import dev.engine_room.flywheel.lib.instance.TransformedInstance; import dev.engine_room.flywheel.lib.model.Models; import net.createmod.catnip.render.SpriteShiftEntry; -import net.createmod.ponder.render.VirtualRenderHelper; public class RopePulleyVisual extends AbstractPulleyVisual { public RopePulleyVisual(VisualizationContext context, PulleyBlockEntity blockEntity, float partialTick) { diff --git a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java index 7afa382f60..bd181780e5 100644 --- a/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlock.java @@ -38,7 +38,7 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -import net.minecraftforge.common.capabilities.ForgeCapabilities; + import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.network.NetworkHooks; @@ -120,7 +120,7 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa @Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, LevelAccessor world, - BlockPos pos, BlockPos neighbourPos) { + BlockPos pos, BlockPos neighbourPos) { if (state.getValue(WATERLOGGED)) world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); return state; @@ -133,7 +133,7 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, - BlockHitResult ray) { + BlockHitResult ray) { if (player == null || player.isCrouching()) return InteractionResult.PASS; @@ -164,7 +164,7 @@ public class ToolboxBlock extends HorizontalDirectionalBlock implements SimpleWa FluidState ifluidstate = context.getLevel() .getFluidState(context.getClickedPos()); return super.getStateForPlacement(context).setValue(FACING, context.getHorizontalDirection() - .getOpposite()) + .getOpposite()) .setValue(WATERLOGGED, Boolean.valueOf(ifluidstate.getType() == Fluids.WATER)); } diff --git a/src/main/java/com/simibubi/create/content/fluids/VirtualFluid.java b/src/main/java/com/simibubi/create/content/fluids/VirtualFluid.java index af4c358f11..abb637d12e 100644 --- a/src/main/java/com/simibubi/create/content/fluids/VirtualFluid.java +++ b/src/main/java/com/simibubi/create/content/fluids/VirtualFluid.java @@ -1,13 +1,12 @@ package com.simibubi.create.content.fluids; -import com.simibubi.create.content.fluids.potion.PotionFluid; - import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; + import net.minecraftforge.fluids.ForgeFlowingFluid; public class VirtualFluid extends ForgeFlowingFluid { diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/OrientedRotatingVisual.java b/src/main/java/com/simibubi/create/content/kinetics/base/OrientedRotatingVisual.java index ee358d9280..2d25b7d0da 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/OrientedRotatingVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/OrientedRotatingVisual.java @@ -19,14 +19,13 @@ import dev.engine_room.flywheel.lib.visualization.SimpleBlockEntityVisualizer; import net.minecraft.core.Direction; import net.minecraft.core.Direction.AxisDirection; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.block.state.properties.Property; public class OrientedRotatingVisual extends KineticBlockEntityVisual { protected final RotatingInstance rotatingModel; /** - * @param from The source model orientation to rotate away from. - * @param to The orientation to rotate to. + * @param from The source model orientation to rotate away from. + * @param to The orientation to rotate to. * @param model The model to spin. */ public OrientedRotatingVisual(VisualizationContext context, T blockEntity, float partialTick, Direction from, Direction to, Model model) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java index 91946bf1dc..06c56b71d9 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlockEntity.java @@ -2,11 +2,8 @@ package com.simibubi.create.content.kinetics.crank; import java.util.List; -import org.jetbrains.annotations.Nullable; - import com.google.common.collect.ImmutableList; import com.simibubi.create.AllBlocks; -import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.kinetics.base.KineticBlockEntity; import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer; import com.simibubi.create.content.kinetics.transmission.sequencer.SequencedGearshiftBlockEntity.SequenceContext; @@ -19,12 +16,9 @@ import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsFormatt import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour; import com.simibubi.create.foundation.utility.CreateLang; -import dev.engine_room.flywheel.api.model.Model; -import dev.engine_room.flywheel.lib.model.Models; +import net.createmod.catnip.math.VecHelper; import net.createmod.catnip.render.CachedBuffers; import net.createmod.catnip.render.SuperByteBuffer; -import net.createmod.catnip.math.VecHelper; -import net.createmod.ponder.render.VirtualRenderHelper; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -106,7 +100,7 @@ public class ValveHandleBlockEntity extends HandCrankBlockEntity { return (inUse > 0 && totalUseTicks > 0 ? Mth.lerp(Math.min(totalUseTicks, totalUseTicks - inUse + partialTicks) / (float) totalUseTicks, - startAngle, targetAngle) + startAngle, targetAngle) : targetAngle) * Mth.DEG_TO_RAD * (backwards ? -1 : 1) * step; } @@ -143,7 +137,8 @@ public class ValveHandleBlockEntity extends HandCrankBlockEntity { } @Override - protected void copySequenceContextFrom(KineticBlockEntity sourceBE) {} + protected void copySequenceContextFrom(KineticBlockEntity sourceBE) { + } @Override @OnlyIn(Dist.CLIENT) @@ -167,8 +162,8 @@ public class ValveHandleBlockEntity extends HandCrankBlockEntity { @Override public ValueSettingsBoard createBoard(Player player, BlockHitResult hitResult) { - ImmutableList rows = ImmutableList.of(Component.literal("\u27f3") - .withStyle(ChatFormatting.BOLD), + ImmutableList rows = ImmutableList.of(Component.literal("\u27f3") + .withStyle(ChatFormatting.BOLD), Component.literal("\u27f2") .withStyle(ChatFormatting.BOLD)); return new ValueSettingsBoard(label, 180, 45, rows, new ValueSettingsFormatter(this::formatValue)); diff --git a/src/main/java/com/simibubi/create/content/kinetics/drill/DrillActorVisual.java b/src/main/java/com/simibubi/create/content/kinetics/drill/DrillActorVisual.java index 38b5258f36..dab62f632b 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/drill/DrillActorVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/drill/DrillActorVisual.java @@ -3,8 +3,6 @@ package com.simibubi.create.content.kinetics.drill; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.contraptions.behaviour.MovementContext; import com.simibubi.create.content.contraptions.render.ActorVisual; -import com.simibubi.create.content.kinetics.base.RotatingInstance; -import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.virtualWorld.VirtualRenderWorld; import dev.engine_room.flywheel.api.visualization.VisualizationContext; @@ -12,30 +10,29 @@ import dev.engine_room.flywheel.lib.instance.InstanceTypes; import dev.engine_room.flywheel.lib.instance.TransformedInstance; import dev.engine_room.flywheel.lib.model.Models; import net.createmod.catnip.animation.AnimationTickHolder; -import net.createmod.catnip.math.VecHelper; import net.createmod.catnip.math.AngleHelper; +import net.createmod.catnip.math.VecHelper; import net.minecraft.core.Direction; -import net.minecraft.util.Mth; import net.minecraft.world.level.block.state.BlockState; public class DrillActorVisual extends ActorVisual { - TransformedInstance drillHead; - private final Direction facing; + TransformedInstance drillHead; + private final Direction facing; private double rotation; private double previousRotation; - public DrillActorVisual(VisualizationContext visualizationContext, VirtualRenderWorld contraption, MovementContext context) { - super(visualizationContext, contraption, context); + public DrillActorVisual(VisualizationContext visualizationContext, VirtualRenderWorld contraption, MovementContext context) { + super(visualizationContext, contraption, context); - BlockState state = context.state; + BlockState state = context.state; - facing = state.getValue(DrillBlock.FACING); + facing = state.getValue(DrillBlock.FACING); drillHead = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(AllPartialModels.DRILL_HEAD)) - .createInstance(); - } + .createInstance(); + } @Override public void tick() { @@ -53,7 +50,7 @@ public class DrillActorVisual extends ActorVisual { } @Override - public void beginFrame() { + public void beginFrame() { drillHead.setIdentityTransform() .translate(context.localPos) .center() @@ -61,7 +58,7 @@ public class DrillActorVisual extends ActorVisual { .rotateZDegrees((float) getRotation()) .uncenter() .setChanged(); - } + } protected double getRotation() { return AngleHelper.angleLerp(AnimationTickHolder.getPartialTicks(), previousRotation, rotation); diff --git a/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java b/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java index 96f1a6e0f6..9adba87df8 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/gearbox/GearboxVisual.java @@ -10,7 +10,6 @@ import com.simibubi.create.content.kinetics.base.RotatingInstance; import com.simibubi.create.foundation.render.AllInstanceTypes; import dev.engine_room.flywheel.api.instance.Instance; -import dev.engine_room.flywheel.api.instance.Instancer; import dev.engine_room.flywheel.api.visualization.VisualizationContext; import dev.engine_room.flywheel.lib.instance.AbstractInstance; import dev.engine_room.flywheel.lib.instance.FlatLit; @@ -18,20 +17,19 @@ import dev.engine_room.flywheel.lib.model.Models; import net.createmod.catnip.data.Iterate; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.block.state.properties.BlockStateProperties; public class GearboxVisual extends KineticBlockEntityVisual { - protected final EnumMap keys = new EnumMap<>(Direction.class); - protected Direction sourceFacing; + protected final EnumMap keys = new EnumMap<>(Direction.class); + protected Direction sourceFacing; - public GearboxVisual(VisualizationContext context, GearboxBlockEntity blockEntity, float partialTick) { - super(context, blockEntity, partialTick); + public GearboxVisual(VisualizationContext context, GearboxBlockEntity blockEntity, float partialTick) { + super(context, blockEntity, partialTick); final Direction.Axis boxAxis = blockState.getValue(BlockStateProperties.AXIS); - updateSourceFacing(); + updateSourceFacing(); var instancer = instancerProvider().instancer(AllInstanceTypes.ROTATING, Models.partial(AllPartialModels.SHAFT_HALF)); @@ -48,58 +46,58 @@ public class GearboxVisual extends KineticBlockEntityVisual .rotateToFace(Direction.SOUTH, direction) .setChanged(); - keys.put(direction, instance); - } - } + keys.put(direction, instance); + } + } - private float getSpeed(Direction direction) { - float speed = blockEntity.getSpeed(); + private float getSpeed(Direction direction) { + float speed = blockEntity.getSpeed(); - if (speed != 0 && sourceFacing != null) { - if (sourceFacing.getAxis() == direction.getAxis()) - speed *= sourceFacing == direction ? 1 : -1; - else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) - speed *= -1; - } - return speed; - } + if (speed != 0 && sourceFacing != null) { + if (sourceFacing.getAxis() == direction.getAxis()) + speed *= sourceFacing == direction ? 1 : -1; + else if (sourceFacing.getAxisDirection() == direction.getAxisDirection()) + speed *= -1; + } + return speed; + } - protected void updateSourceFacing() { - if (blockEntity.hasSource()) { - BlockPos source = blockEntity.source.subtract(pos); - sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ()); - } else { - sourceFacing = null; - } - } + protected void updateSourceFacing() { + if (blockEntity.hasSource()) { + BlockPos source = blockEntity.source.subtract(pos); + sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ()); + } else { + sourceFacing = null; + } + } - @Override - public void update(float pt) { - updateSourceFacing(); - for (Map.Entry key : keys.entrySet()) { - Direction direction = key.getKey(); - Direction.Axis axis = direction.getAxis(); + @Override + public void update(float pt) { + updateSourceFacing(); + for (Map.Entry key : keys.entrySet()) { + Direction direction = key.getKey(); + Direction.Axis axis = direction.getAxis(); key.getValue() .setup(blockEntity, axis, getSpeed(direction)) .setChanged(); } - } + } - @Override - public void updateLight(float partialTick) { - relight(keys.values().toArray(FlatLit[]::new)); - } + @Override + public void updateLight(float partialTick) { + relight(keys.values().toArray(FlatLit[]::new)); + } - @Override - protected void _delete() { - keys.values().forEach(AbstractInstance::delete); - keys.clear(); - } + @Override + protected void _delete() { + keys.values().forEach(AbstractInstance::delete); + keys.clear(); + } @Override public void collectCrumblingInstances(Consumer consumer) { keys.values() - .forEach(consumer); + .forEach(consumer); } } diff --git a/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java b/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java index 01dfc45fc6..bc0852a06c 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/mechanicalArm/ArmVisual.java @@ -23,7 +23,6 @@ import net.createmod.catnip.data.Iterate; import net.createmod.catnip.theme.Color; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.core.Direction; import net.minecraft.util.Mth; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; @@ -121,10 +120,10 @@ public class ArmVisual extends SingleAxisRotatingVisual implemen int color = Color.rainbowColor(ticks * 100) .getRGB(); updateAngles(baseAngle, lowerArmAngle, upperArmAngle, headAngle, color); - } + } private void animateArm() { - updateAngles(this.baseAngle, this.lowerArmAngle - 135, this.upperArmAngle - 90, this.headAngle, 0xFFFFFF); + updateAngles(this.baseAngle, this.lowerArmAngle - 135, this.upperArmAngle - 90, this.headAngle, 0xFFFFFF); } private void updateAngles(float baseAngle, float lowerArmAngle, float upperArmAngle, float headAngle, int color) { @@ -163,7 +162,7 @@ public class ArmVisual extends SingleAxisRotatingVisual implemen boolean hasItem = !item.isEmpty(); boolean isBlockItem = hasItem && (item.getItem() instanceof BlockItem) && itemRenderer.getModel(item, Minecraft.getInstance().level, null, 0) - .isGui3d(); + .isGui3d(); for (int index : Iterate.zeroAndOne) { poseStack.pushPose(); @@ -182,7 +181,7 @@ public class ArmVisual extends SingleAxisRotatingVisual implemen public void update(float pt) { super.update(pt); instancerProvider().instancer(InstanceTypes.TRANSFORMED, Models.partial(blockEntity.goggles ? AllPartialModels.ARM_CLAW_BASE_GOGGLES : AllPartialModels.ARM_CLAW_BASE)) - .stealInstance(claw); + .stealInstance(claw); } @Override @@ -193,7 +192,7 @@ public class ArmVisual extends SingleAxisRotatingVisual implemen } @Override - protected void _delete() { + protected void _delete() { super._delete(); models.forEach(AbstractInstance::delete); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java b/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java index a810d473d5..37479997f2 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java +++ b/src/main/java/com/simibubi/create/content/kinetics/mixer/MixerVisual.java @@ -5,11 +5,9 @@ import java.util.function.Consumer; import com.simibubi.create.AllPartialModels; import com.simibubi.create.content.kinetics.base.RotatingInstance; import com.simibubi.create.content.kinetics.base.SingleAxisRotatingVisual; -import com.simibubi.create.content.kinetics.simpleRelays.encased.EncasedCogVisual; import com.simibubi.create.foundation.render.AllInstanceTypes; import dev.engine_room.flywheel.api.instance.Instance; -import dev.engine_room.flywheel.api.model.Model; import dev.engine_room.flywheel.api.visual.DynamicVisual; import dev.engine_room.flywheel.api.visualization.VisualizationContext; import dev.engine_room.flywheel.lib.instance.InstanceTypes; @@ -34,7 +32,7 @@ public class MixerVisual extends SingleAxisRotatingVisual { diff --git a/src/main/java/com/simibubi/create/content/kinetics/transmission/sequencer/SequencedGearshiftScreen.java b/src/main/java/com/simibubi/create/content/kinetics/transmission/sequencer/SequencedGearshiftScreen.java index 7cf35589e5..7a67f21037 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/transmission/sequencer/SequencedGearshiftScreen.java +++ b/src/main/java/com/simibubi/create/content/kinetics/transmission/sequencer/SequencedGearshiftScreen.java @@ -17,7 +17,6 @@ import net.createmod.catnip.gui.element.GuiGameElement; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.ItemStack; public class SequencedGearshiftScreen extends AbstractSimiScreen { @@ -169,7 +168,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { if (def.hasValueParameter) { String text = def.formatValue(instruction.value); int stringWidth = font.width(text); - label(graphics, 90 + (12 - stringWidth / 2), yOffset - 1, Component.literal(text)); + label(graphics, 90 + (12 - stringWidth / 2), yOffset - 1, Component.literal(text)); } if (def.hasSpeedParameter) label(graphics, 127, yOffset - 1, instruction.speedModifier.label); @@ -180,9 +179,9 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { } private void renderAdditional(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks, int guiLeft, int guiTop, - AllGuiTextures background) { + AllGuiTextures background) { GuiGameElement.of(renderedItem).at(guiLeft + background.getWidth() + 6, guiTop + background.getHeight() - 56, 100) + .GuiRenderBuilder>at(guiLeft + background.getWidth() + 6, guiTop + background.getHeight() - 56, 100) .scale(5) .render(graphics); } diff --git a/src/main/java/com/simibubi/create/content/logistics/box/PackageVisual.java b/src/main/java/com/simibubi/create/content/logistics/box/PackageVisual.java index 40790b6906..7401735952 100644 --- a/src/main/java/com/simibubi/create/content/logistics/box/PackageVisual.java +++ b/src/main/java/com/simibubi/create/content/logistics/box/PackageVisual.java @@ -8,12 +8,10 @@ import dev.engine_room.flywheel.lib.instance.InstanceTypes; import dev.engine_room.flywheel.lib.instance.TransformedInstance; import dev.engine_room.flywheel.lib.model.Models; import dev.engine_room.flywheel.lib.model.baked.PartialModel; -import dev.engine_room.flywheel.lib.transform.Translate; import dev.engine_room.flywheel.lib.visual.AbstractEntityVisual; import dev.engine_room.flywheel.lib.visual.SimpleDynamicVisual; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; - import net.minecraft.world.phys.Vec3; import net.minecraftforge.registries.ForgeRegistries; diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/SingletonItemAttribute.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/SingletonItemAttribute.java index 81c5f53c61..3d797be983 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/SingletonItemAttribute.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/SingletonItemAttribute.java @@ -4,14 +4,12 @@ import java.util.List; import java.util.function.BiPredicate; import java.util.function.Function; -import com.mojang.serialization.Codec; +import org.jetbrains.annotations.NotNull; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import org.jetbrains.annotations.NotNull; - public final class SingletonItemAttribute implements ItemAttribute { private final Type type; private final BiPredicate predicate; @@ -34,10 +32,12 @@ public final class SingletonItemAttribute implements ItemAttribute { } @Override - public void save(CompoundTag nbt) {} // NO-OP + public void save(CompoundTag nbt) { + } // NO-OP @Override - public void load(CompoundTag nbt) {} // NO-OP + public void load(CompoundTag nbt) { + } // NO-OP @Override public String getTranslationKey() { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/AllItemAttributeLegacyDeserializers.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/AllItemAttributeLegacyDeserializers.java index 332bc1126c..53cc3a8572 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/AllItemAttributeLegacyDeserializers.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/AllItemAttributeLegacyDeserializers.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.logistics.item.filter.attribute.legacydeserializers; import java.util.function.Function; -import java.util.function.Supplier; import org.jetbrains.annotations.ApiStatus; diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/StandardTraitsLegacyDeserializer.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/StandardTraitsLegacyDeserializer.java index 24e8eeadeb..0511ebd9df 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/StandardTraitsLegacyDeserializer.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/attribute/legacydeserializers/StandardTraitsLegacyDeserializer.java @@ -1,7 +1,6 @@ package com.simibubi.create.content.logistics.item.filter.attribute.legacydeserializers; import java.util.Map; -import java.util.function.Supplier; import com.google.common.collect.ImmutableBiMap; import com.simibubi.create.content.logistics.item.filter.attribute.AllItemAttributeTypes; diff --git a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperCategoryScreen.java b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperCategoryScreen.java index 065f43d617..5f2b23f360 100644 --- a/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperCategoryScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/stockTicker/StockKeeperCategoryScreen.java @@ -7,8 +7,6 @@ import java.util.Optional; import javax.annotation.Nullable; -import net.minecraft.network.chat.MutableComponent; - import org.lwjgl.glfw.GLFW; import com.google.common.collect.ImmutableList; @@ -25,10 +23,10 @@ import com.simibubi.create.foundation.gui.widget.IconButton; import com.simibubi.create.foundation.gui.widget.ScrollInput; import com.simibubi.create.foundation.utility.CreateLang; -import net.createmod.catnip.gui.UIRenderHelper; -import net.createmod.catnip.gui.element.GuiGameElement; import net.createmod.catnip.animation.LerpedFloat; import net.createmod.catnip.animation.LerpedFloat.Chaser; +import net.createmod.catnip.gui.UIRenderHelper; +import net.createmod.catnip.gui.element.GuiGameElement; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; @@ -41,6 +39,7 @@ import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; + import net.minecraftforge.items.SlotItemHandler; public class StockKeeperCategoryScreen extends AbstractSimiContainerScreen @@ -92,7 +91,7 @@ public class StockKeeperCategoryScreen extends AbstractSimiContainerScreen 20 ? "..." : ""), + .getString(20) + .stripTrailing() + + (entry.getHoverName() + .getString() + .length() > 20 ? "..." : ""), 35, 5, 0x656565, false); matrixStack.popPose(); @@ -418,7 +417,7 @@ public class StockKeeperCategoryScreen extends AbstractSimiContainerScreenat(leftPos + AllGuiTextures.STOCK_KEEPER_CATEGORY.getWidth() + 12, + .GuiRenderBuilder>at(leftPos + AllGuiTextures.STOCK_KEEPER_CATEGORY.getWidth() + 12, topPos + imageHeight - 39, -190) .scale(3) .render(graphics); @@ -431,14 +430,14 @@ public class StockKeeperCategoryScreen extends AbstractSimiContainerScreenat(x + background.getWidth() + 6, y + background.getHeight() - 56, -200) + .GuiRenderBuilder>at(x + background.getWidth() + 6, y + background.getHeight() - 56, -200) .scale(5) .render(graphics); @@ -183,7 +182,7 @@ public class ThresholdSwitchScreen extends AbstractSimiScreen { ItemStack displayItem = blockEntity.getDisplayItemForScreen(); GuiGameElement.of(displayItem.isEmpty() ? new ItemStack(Items.BARRIER) : displayItem).at(itemX, itemY, 0) + .GuiRenderBuilder>at(itemX, itemY, 0) .render(graphics); int torchX = x + 23; @@ -202,7 +201,7 @@ public class ThresholdSwitchScreen extends AbstractSimiScreen { for (boolean power : Iterate.trueAndFalse) { GuiGameElement.of(Blocks.REDSTONE_TORCH.defaultBlockState() - .setValue(RedstoneTorchBlock.LIT, blockEntity.isInverted() ^ power)) + .setValue(RedstoneTorchBlock.LIT, blockEntity.isInverted() ^ power)) .scale(20) .render(graphics); ms.translate(0, 26, 0); diff --git a/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java b/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java index 80459e1e6c..b02abb1787 100644 --- a/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java +++ b/src/main/java/com/simibubi/create/content/schematics/ServerSchematicLoader.java @@ -27,7 +27,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.level.Level; @@ -92,9 +91,9 @@ public class ServerSchematicLoader { public void handleNewUpload(ServerPlayer player, String schematic, long size, BlockPos pos) { String playerPath = getSchematicPath() + "/" + player.getGameProfile() - .getName(); + .getName(); String playerSchematicId = player.getGameProfile() - .getName() + "/" + schematic; + .getName() + "/" + schematic; FilesHelper.createFolderIfMissing(playerPath); // Unsupported Format @@ -104,11 +103,11 @@ public class ServerSchematicLoader { } Path playerSchematicsPath = Paths.get(getSchematicPath(), player.getGameProfile() - .getName()) - .toAbsolutePath(); + .getName()) + .toAbsolutePath(); Path uploadPath = playerSchematicsPath.resolve(schematic) - .normalize(); + .normalize(); if (!uploadPath.startsWith(playerSchematicsPath)) { Create.LOGGER.warn("Attempted Schematic Upload with directory escape: {}", playerSchematicId); return; @@ -140,8 +139,8 @@ public class ServerSchematicLoader { if (count >= getConfig().maxSchematics.get()) { Stream list2 = Files.list(Paths.get(playerPath)); Optional lastFilePath = list2.filter(f -> !Files.isDirectory(f)) - .min(Comparator.comparingLong(f -> f.toFile() - .lastModified())); + .min(Comparator.comparingLong(f -> f.toFile() + .lastModified())); list2.close(); if (lastFilePath.isPresent()) { Files.deleteIfExists(lastFilePath.get()); @@ -164,9 +163,9 @@ public class ServerSchematicLoader { protected boolean validateSchematicSizeOnServer(ServerPlayer player, long size) { Integer maxFileSize = getConfig().maxTotalSchematicSize.get(); if (size > maxFileSize * 1000) { - player.sendSystemMessage(CreateLang.translateDirect("schematics.uploadTooLarge") + player.sendSystemMessage(CreateLang.translateDirect("schematics.uploadTooLarge") .append(Component.literal(" (" + size / 1000 + " KB)."))); - player.sendSystemMessage(CreateLang.translateDirect("schematics.maxAllowedSize") + player.sendSystemMessage(CreateLang.translateDirect("schematics.maxAllowedSize") .append(Component.literal(" " + maxFileSize + " KB"))); return false; } @@ -179,7 +178,7 @@ public class ServerSchematicLoader { public void handleWriteRequest(ServerPlayer player, String schematic, byte[] data) { String playerSchematicId = player.getGameProfile() - .getName() + "/" + schematic; + .getName() + "/" + schematic; if (activeUploads.containsKey(playerSchematicId)) { SchematicUploadEntry entry = activeUploads.get(playerSchematicId); @@ -249,7 +248,7 @@ public class ServerSchematicLoader { public void handleFinishedUpload(ServerPlayer player, String schematic) { String playerSchematicId = player.getGameProfile() - .getName() + "/" + schematic; + .getName() + "/" + schematic; if (activeUploads.containsKey(playerSchematicId)) { try { @@ -294,10 +293,10 @@ public class ServerSchematicLoader { } Path schematicPath = Paths.get(getSchematicPath()) - .toAbsolutePath(); + .toAbsolutePath(); Path path = schematicPath.resolve(playerSchematicId) - .normalize(); + .normalize(); if (!path.startsWith(schematicPath)) { Create.LOGGER.warn("Attempted Schematic Upload with directory escape: {}", playerSchematicId); return; @@ -314,8 +313,8 @@ public class ServerSchematicLoader { return; SchematicExportResult result = SchematicExport.saveSchematic( - playerSchematics, schematic, true, - world, pos, pos.offset(bounds).offset(-1, -1, -1) + playerSchematics, schematic, true, + world, pos, pos.offset(bounds).offset(-1, -1, -1) ); if (result != null) player.setItemInHand(InteractionHand.MAIN_HAND, diff --git a/src/main/java/com/simibubi/create/content/schematics/client/ClientSchematicLoader.java b/src/main/java/com/simibubi/create/content/schematics/client/ClientSchematicLoader.java index 57c05df729..e03b38290a 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/ClientSchematicLoader.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/ClientSchematicLoader.java @@ -26,7 +26,7 @@ import com.simibubi.create.infrastructure.config.AllConfigs; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; + import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -162,12 +162,12 @@ public class ClientSchematicLoader { try { Files.list(Paths.get("schematics/")) - .filter(f -> !Files.isDirectory(f) && f.getFileName().toString().endsWith(".nbt")).forEach(path -> { - if (Files.isDirectory(path)) - return; + .filter(f -> !Files.isDirectory(f) && f.getFileName().toString().endsWith(".nbt")).forEach(path -> { + if (Files.isDirectory(path)) + return; - availableSchematics.add(Component.literal(path.getFileName().toString())); - }); + availableSchematics.add(Component.literal(path.getFileName().toString())); + }); } catch (NoSuchFileException e) { // No Schematics created yet } catch (IOException e) { diff --git a/src/main/java/com/simibubi/create/foundation/block/CopperBlockSet.java b/src/main/java/com/simibubi/create/foundation/block/CopperBlockSet.java index 43ef9d0505..24704b5467 100644 --- a/src/main/java/com/simibubi/create/foundation/block/CopperBlockSet.java +++ b/src/main/java/com/simibubi/create/foundation/block/CopperBlockSet.java @@ -7,8 +7,6 @@ import java.util.Map; import java.util.Objects; import java.util.function.Supplier; -import net.minecraft.tags.ItemTags; - import org.apache.commons.lang3.ArrayUtils; import com.simibubi.create.foundation.data.TagGen; @@ -23,9 +21,9 @@ import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.nullness.NonNullBiConsumer; import com.tterrag.registrate.util.nullness.NonNullFunction; -import net.createmod.catnip.platform.CatnipServices; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.lang.Lang; +import net.createmod.catnip.platform.CatnipServices; import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.ShapelessRecipeBuilder; import net.minecraft.resources.ResourceLocation; @@ -41,6 +39,7 @@ import net.minecraft.world.level.block.WeatheringCopperSlabBlock; import net.minecraft.world.level.block.WeatheringCopperStairBlock; import net.minecraft.world.level.block.state.BlockBehaviour.Properties; import net.minecraft.world.level.block.state.BlockState; + import net.minecraftforge.client.model.generators.ModelProvider; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; @@ -49,6 +48,7 @@ public class CopperBlockSet { protected static final int WEATHER_STATE_COUNT = WEATHER_STATES.length; protected static final Map> BASE_BLOCKS = new EnumMap<>(WeatherState.class); + static { BASE_BLOCKS.put(WeatherState.UNAFFECTED, () -> Blocks.COPPER_BLOCK); BASE_BLOCKS.put(WeatherState.EXPOSED, () -> Blocks.EXPOSED_COPPER); @@ -57,7 +57,7 @@ public class CopperBlockSet { } public static final Variant[] DEFAULT_VARIANTS = - new Variant[] { BlockVariant.INSTANCE, SlabVariant.INSTANCE, StairVariant.INSTANCE }; + new Variant[]{BlockVariant.INSTANCE, SlabVariant.INSTANCE, StairVariant.INSTANCE}; protected final String name; protected final String generalDirectory; // Leave empty for root folder @@ -84,7 +84,7 @@ public class CopperBlockSet { } public CopperBlockSet(AbstractRegistrate registrate, String name, String endTextureName, Variant[] variants, - NonNullBiConsumer, RegistrateRecipeProvider> mainBlockRecipe, String generalDirectory, NonNullBiConsumer onRegister) { + NonNullBiConsumer, RegistrateRecipeProvider> mainBlockRecipe, String generalDirectory, NonNullBiConsumer onRegister) { this.name = name; this.generalDirectory = generalDirectory; this.endTextureName = endTextureName; @@ -116,7 +116,7 @@ public class CopperBlockSet { } protected BlockEntry createEntry(AbstractRegistrate registrate, Variant variant, - WeatherState state, boolean waxed) { + WeatherState state, boolean waxed) { String name = ""; if (waxed) { name += "waxed_"; @@ -211,20 +211,21 @@ public class CopperBlockSet { NonNullFunction getFactory(CopperBlockSet blocks, WeatherState state, boolean waxed); default void generateLootTable(RegistrateBlockLootTables lootTable, T block, CopperBlockSet blocks, - WeatherState state, boolean waxed) { + WeatherState state, boolean waxed) { lootTable.dropSelf(block); } void generateRecipes(BlockEntry blockVariant, DataGenContext ctx, RegistrateRecipeProvider prov); void generateBlockState(DataGenContext ctx, RegistrateBlockstateProvider prov, CopperBlockSet blocks, - WeatherState state, boolean waxed); + WeatherState state, boolean waxed); } public static class BlockVariant implements Variant { public static final BlockVariant INSTANCE = new BlockVariant(); - protected BlockVariant() {} + protected BlockVariant() { + } @Override public String getSuffix() { @@ -242,7 +243,7 @@ public class CopperBlockSet { @Override public void generateBlockState(DataGenContext ctx, RegistrateBlockstateProvider prov, - CopperBlockSet blocks, WeatherState state, boolean waxed) { + CopperBlockSet blocks, WeatherState state, boolean waxed) { Block block = ctx.get(); String path = CatnipServices.REGISTRIES.getKeyOrThrow(block) .getPath(); @@ -256,21 +257,23 @@ public class CopperBlockSet { // End texture and base texture aren't equal, so we should use cube_column. ResourceLocation endTexture = prov.modLoc(baseLoc + blocks.getEndTextureName()); prov.simpleBlock(block, prov.models() - .cubeColumn(path, texture, endTexture)); + .cubeColumn(path, texture, endTexture)); } } @Override public void generateRecipes(BlockEntry blockVariant, DataGenContext ctx, - RegistrateRecipeProvider prov) {} + RegistrateRecipeProvider prov) { + } } public static class SlabVariant implements Variant { public static final SlabVariant INSTANCE = new SlabVariant(); - protected SlabVariant() {} + protected SlabVariant() { + } @Override public String getSuffix() { @@ -279,7 +282,7 @@ public class CopperBlockSet { @Override public NonNullFunction getFactory(CopperBlockSet blocks, WeatherState state, - boolean waxed) { + boolean waxed) { if (waxed) { return SlabBlock::new; } else { @@ -289,13 +292,13 @@ public class CopperBlockSet { @Override public void generateLootTable(RegistrateBlockLootTables lootTable, SlabBlock block, CopperBlockSet blocks, - WeatherState state, boolean waxed) { + WeatherState state, boolean waxed) { lootTable.add(block, lootTable.createSlabItemTable(block)); } @Override public void generateBlockState(DataGenContext ctx, RegistrateBlockstateProvider prov, - CopperBlockSet blocks, WeatherState state, boolean waxed) { + CopperBlockSet blocks, WeatherState state, boolean waxed) { ResourceLocation fullModel = prov.modLoc(ModelProvider.BLOCK_FOLDER + "/" + getWeatherStatePrefix(state) + blocks.getName()); @@ -308,7 +311,7 @@ public class CopperBlockSet { @Override public void generateRecipes(BlockEntry blockVariant, DataGenContext ctx, - RegistrateRecipeProvider prov) { + RegistrateRecipeProvider prov) { prov.slab(DataIngredient.items(blockVariant.get()), RecipeCategory.BUILDING_BLOCKS, ctx::get, null, true); } } @@ -329,7 +332,7 @@ public class CopperBlockSet { @Override public NonNullFunction getFactory(CopperBlockSet blocks, WeatherState state, - boolean waxed) { + boolean waxed) { if (!blocks.hasVariant(parent)) { throw new IllegalStateException( "Cannot add StairVariant '" + toString() + "' without parent Variant '" + parent.toString() + "'!"); @@ -353,7 +356,7 @@ public class CopperBlockSet { @Override public void generateBlockState(DataGenContext ctx, RegistrateBlockstateProvider prov, - CopperBlockSet blocks, WeatherState state, boolean waxed) { + CopperBlockSet blocks, WeatherState state, boolean waxed) { String baseLoc = ModelProvider.BLOCK_FOLDER + "/" + blocks.generalDirectory + getWeatherStatePrefix(state); ResourceLocation texture = prov.modLoc(baseLoc + blocks.getName()); ResourceLocation endTexture = prov.modLoc(baseLoc + blocks.getEndTextureName()); @@ -362,7 +365,7 @@ public class CopperBlockSet { @Override public void generateRecipes(BlockEntry blockVariant, DataGenContext ctx, - RegistrateRecipeProvider prov) { + RegistrateRecipeProvider prov) { prov.stairs(DataIngredient.items(blockVariant.get()), RecipeCategory.BUILDING_BLOCKS, ctx::get, null, true); } } diff --git a/src/main/java/com/simibubi/create/foundation/blockEntity/behaviour/scrollValue/ScrollValueBehaviour.java b/src/main/java/com/simibubi/create/foundation/blockEntity/behaviour/scrollValue/ScrollValueBehaviour.java index 08cc4c4ce4..063a4508d8 100644 --- a/src/main/java/com/simibubi/create/foundation/blockEntity/behaviour/scrollValue/ScrollValueBehaviour.java +++ b/src/main/java/com/simibubi/create/foundation/blockEntity/behaviour/scrollValue/ScrollValueBehaviour.java @@ -16,13 +16,13 @@ import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsFormatt import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; + import net.minecraftforge.common.util.FakePlayer; public class ScrollValueBehaviour extends BlockEntityBehaviour implements ValueSettingsBehaviour { @@ -156,7 +156,7 @@ public class ScrollValueBehaviour extends BlockEntityBehaviour implements ValueS @Override public ValueSettingsBoard createBoard(Player player, BlockHitResult hitResult) { - return new ValueSettingsBoard(label, max, 10, ImmutableList.of(Component.literal("Value")), + return new ValueSettingsBoard(label, max, 10, ImmutableList.of(Component.literal("Value")), new ValueSettingsFormatter(ValueSettings::format)); } diff --git a/src/main/java/com/simibubi/create/foundation/data/MetalBarsGen.java b/src/main/java/com/simibubi/create/foundation/data/MetalBarsGen.java index 86e73e8148..e5128ccc55 100644 --- a/src/main/java/com/simibubi/create/foundation/data/MetalBarsGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/MetalBarsGen.java @@ -9,7 +9,6 @@ import static net.minecraft.world.level.block.state.properties.BlockStatePropert import java.util.function.Supplier; import com.simibubi.create.AllTags.AllBlockTags; -import com.simibubi.create.Create; import com.tterrag.registrate.providers.DataGenContext; import com.tterrag.registrate.providers.RegistrateBlockstateProvider; import com.tterrag.registrate.util.DataIngredient; @@ -24,6 +23,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.IronBarsBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.material.MapColor; + import net.minecraftforge.client.model.generators.ModelFile; public class MetalBarsGen { @@ -112,7 +112,7 @@ public class MetalBarsGen { } private static ModelFile barsSubModel(RegistrateBlockstateProvider p, String name, String suffix, - boolean specialEdge) { + boolean specialEdge) { ResourceLocation barsTexture = p.modLoc("block/bars/" + name + "_bars"); ResourceLocation edgeTexture = specialEdge ? p.modLoc("block/bars/" + name + "_bars_edge") : barsTexture; return p.models() @@ -123,7 +123,7 @@ public class MetalBarsGen { } public static BlockEntry createBars(String name, boolean specialEdge, - Supplier ingredient, MapColor color) { + Supplier ingredient, MapColor color) { return REGISTRATE.block(name + "_bars", IronBarsBlock::new) .addLayer(() -> RenderType::cutoutMipped) .initialProperties(() -> Blocks.IRON_BARS) diff --git a/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java b/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java index eda25288c3..e2d86eac92 100644 --- a/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java +++ b/src/main/java/com/simibubi/create/foundation/fluid/FluidIngredient.java @@ -2,7 +2,6 @@ package com.simibubi.create.foundation.fluid; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -23,6 +22,7 @@ import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; import net.minecraft.world.level.material.FlowingFluid; import net.minecraft.world.level.material.Fluid; + import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.registries.ForgeRegistries; diff --git a/src/main/java/com/simibubi/create/infrastructure/command/DumpRailwaysCommand.java b/src/main/java/com/simibubi/create/infrastructure/command/DumpRailwaysCommand.java index 935dac69c5..66d64b5916 100644 --- a/src/main/java/com/simibubi/create/infrastructure/command/DumpRailwaysCommand.java +++ b/src/main/java/com/simibubi/create/infrastructure/command/DumpRailwaysCommand.java @@ -22,7 +22,6 @@ import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentUtils; import net.minecraft.network.chat.HoverEvent; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; @@ -49,8 +48,8 @@ public class DumpRailwaysCommand { CommandSourceStack source = ctx.getSource(); fillReport(source.getLevel(), source.getPosition(), (s, f) -> source.sendSuccess(() -> { - return Component.literal(s).withStyle(st -> st.withColor(f)); - }, false), + return Component.literal(s).withStyle(st -> st.withColor(f)); + }, false), (c) -> source.sendSuccess(() -> c, false)); return 1; }); @@ -58,7 +57,7 @@ public class DumpRailwaysCommand { // https://www.compart.com/en/unicode/search?q=box+drawings+light#characters ┬ ├ └ ─ static void fillReport(ServerLevel level, Vec3 location, BiConsumer chat, - Consumer chatRaw) { + Consumer chatRaw) { GlobalRailwayManager railways = Create.RAILWAYS; @@ -85,7 +84,7 @@ public class DumpRailwaysCommand { chat.accept(graph.id.toString() .substring(0, 5) + " with " + graph.getNodes() - .size() + .size() + " Nodes", white); Collection signals = graph.getPoints(EdgePointType.SIGNAL); if (!signals.isEmpty()) @@ -113,9 +112,9 @@ public class DumpRailwaysCommand { chat.accept("", white); for (Train train : nearestTrains) { chat.accept(String.format("┬%1$s: %2$s, %3$d Wagons", - train.id.toString().substring(0, 5), - train.name.getString(), - train.carriages.size() + train.id.toString().substring(0, 5), + train.name.getString(), + train.carriages.size() ), bright); if (train.derailed) chat.accept("├─Derailed", orange); @@ -135,9 +134,9 @@ public class DumpRailwaysCommand { ScheduleRuntime runtime = train.runtime; if (runtime.getSchedule() != null) { chat.accept("├─Schedule, Entry " + runtime.currentEntry + ", " - + (runtime.paused ? "Paused" + + (runtime.paused ? "Paused" : runtime.state.name() - .replaceAll("_", " ")), + .replaceAll("_", " ")), runtime.paused ? darkBlue : blue); } else chat.accept("├─Idle, No Schedule", darkBlue); @@ -163,29 +162,29 @@ public class DumpRailwaysCommand { } private static Component createDeleteButton(Train train) { - return Component.literal("└─").withStyle(style -> style.withColor(blue)).append( + return Component.literal("└─").withStyle(style -> style.withColor(blue)).append( ComponentUtils.wrapInSquareBrackets( - Component.literal("Remove").withStyle(style -> style.withColor(orange)) + Component.literal("Remove").withStyle(style -> style.withColor(orange)) ).withStyle(style -> { - return style - .withColor(blue) - .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/c train remove " + train.id.toString())) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Click to remove ").append(train.name))); - } + return style + .withColor(blue) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/c train remove " + train.id.toString())) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Click to remove ").append(train.name))); + } ) ); } private static Component createTeleportButton(Train train) { - return Component.literal("├─").withStyle(style -> style.withColor(darkBlue)).append( + return Component.literal("├─").withStyle(style -> style.withColor(darkBlue)).append( ComponentUtils.wrapInSquareBrackets( Component.literal("Teleport").withStyle(style -> style.withColor(orange)) ).withStyle(style -> { - return style - .withColor(darkBlue) - .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/c train tp " + train.id.toString())) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Click to teleport to ").append(train.name))); - } + return style + .withColor(darkBlue) + .withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/c train tp " + train.id.toString())) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Click to teleport to ").append(train.name))); + } ) ); } diff --git a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestMisc.java b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestMisc.java index 2d2487f0c5..46d0697e88 100644 --- a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestMisc.java +++ b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestMisc.java @@ -12,7 +12,6 @@ import com.simibubi.create.infrastructure.gametest.CreateGameTestHelper; import com.simibubi.create.infrastructure.gametest.GameTestGroup; import net.minecraft.core.BlockPos; -import net.minecraft.core.registries.Registries; import net.minecraft.gametest.framework.GameTest; import net.minecraft.nbt.NbtUtils; import net.minecraft.server.level.ServerLevel; @@ -36,8 +35,8 @@ public class TestMisc { BlockPos redEndTop = helper.absolutePos(new BlockPos(5, 4, 7)); ServerLevel level = helper.getLevel(); SchematicExport.saveSchematic( - SchematicExport.SCHEMATICS.resolve("uploaded/Deployer"), "schematicannon_gametest", true, - level, whiteEndBottom, redEndTop + SchematicExport.SCHEMATICS.resolve("uploaded/Deployer"), "schematicannon_gametest", true, + level, whiteEndBottom, redEndTop ); ItemStack schematic = SchematicItem.create(level, "schematicannon_gametest.nbt", "Deployer"); diff --git a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/ElevatorScenes.java b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/ElevatorScenes.java index 0577d4197b..0a3e6b5b34 100644 --- a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/ElevatorScenes.java +++ b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/ElevatorScenes.java @@ -18,7 +18,6 @@ import net.createmod.ponder.api.scene.Selection; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.phys.AABB; @@ -150,7 +149,7 @@ public class ElevatorScenes { scene.idle(75); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(3, 6, 2), Direction.NORTH), Pointing.RIGHT, 60) - .rightClick(); + .rightClick(); scene.idle(7); scene.effects().indicateSuccess(util.grid().at(3, 6, 2)); scene.world().toggleRedstonePower(util.select().position(1, 13, 2)); @@ -173,7 +172,7 @@ public class ElevatorScenes { scene.idle(80); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(1, 1, 2), Direction.UP), Pointing.DOWN, 60) - .rightClick(); + .rightClick(); scene.idle(7); scene.overlay().showOutlineWithText(util.select().position(1, 1, 2), 60) .placeNearTarget() @@ -241,7 +240,7 @@ public class ElevatorScenes { scene.idle(10); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(4, 2, 2), Direction.UP), Pointing.DOWN, 60) - .scroll(); + .scroll(); scene.idle(15); scene.overlay().showText(90) .placeNearTarget() @@ -250,7 +249,7 @@ public class ElevatorScenes { scene.idle(85); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(4, 2, 2), Direction.UP), Pointing.DOWN, 10) - .rightClick(); + .rightClick(); scene.idle(7); scene.world().cycleBlockProperty(midContact, ElevatorContactBlock.POWERING); scene.world().cycleBlockProperty(topContact, ElevatorContactBlock.CALLING); @@ -266,7 +265,7 @@ public class ElevatorScenes { scene.idle(15); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(3, 6, 2), Direction.NORTH), Pointing.RIGHT, 60) - .rightClick(); + .rightClick(); scene.idle(7); scene.effects().indicateSuccess(util.grid().at(3, 6, 2)); scene.world().movePulley(pulleyPos, -1, 0); @@ -282,7 +281,7 @@ public class ElevatorScenes { scene.idle(20); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(3, 6, 2), Direction.NORTH), Pointing.RIGHT, 60) - .rightClick(); + .rightClick(); scene.idle(7); scene.effects().indicateSuccess(util.grid().at(3, 6, 2)); scene.world().movePulley(pulleyPos, 1, 0); @@ -361,14 +360,14 @@ public class ElevatorScenes { scene.world().showSectionAndMerge(util.select().position(nixiePos), Direction.DOWN, camLink); scene.idle(15); scene.overlay().showControls(util.vector().blockSurface(util.grid().at(4, 1, 0), Direction.UP), Pointing.DOWN, 15) - .rightClick() - .withItem(AllBlocks.DISPLAY_LINK.asStack()); + .rightClick() + .withItem(AllBlocks.DISPLAY_LINK.asStack()); scene.world().toggleRedstonePower(util.select().position(1, 14, 2)); scene.idle(15); scene.world().showSectionAndMerge(util.select().position(linkPos), Direction.DOWN, camLink); scene.world().flashDisplayLink(linkPos); scene.world().modifyBlockEntityNBT(util.select().position(nixiePos), NixieTubeBlockEntity.class, nbt -> { - Component component = Component.literal("0F"); + Component component = Component.literal("0F"); nbt.putString("RawCustomText", component.getString()); nbt.putString("CustomText", Component.Serializer.toJson(component)); }); @@ -399,7 +398,7 @@ public class ElevatorScenes { scene.world().flashDisplayLink(linkPos); scene.world().modifyBlockEntityNBT(util.select().position(nixiePos), NixieTubeBlockEntity.class, nbt -> { - Component component = Component.literal("1F"); + Component component = Component.literal("1F"); nbt.putString("RawCustomText", component.getString()); nbt.putString("CustomText", Component.Serializer.toJson(component)); }); @@ -415,7 +414,7 @@ public class ElevatorScenes { scene.world().flashDisplayLink(linkPos); scene.world().modifyBlockEntityNBT(util.select().position(nixiePos), NixieTubeBlockEntity.class, nbt -> { - Component component = Component.literal("2F"); + Component component = Component.literal("2F"); nbt.putString("RawCustomText", component.getString()); nbt.putString("CustomText", Component.Serializer.toJson(component)); }); diff --git a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/RedstoneScenes.java b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/RedstoneScenes.java index 409b23991d..e34a053b09 100644 --- a/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/RedstoneScenes.java +++ b/src/main/java/com/simibubi/create/infrastructure/ponder/scenes/RedstoneScenes.java @@ -30,7 +30,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -507,10 +506,10 @@ public class RedstoneScenes { scene.title("analog_lever", "Controlling signals using the Analog Lever"); scene.configureBasePlate(0, 0, 5); - BlockPos[] wireLocations = new BlockPos[] { util.grid().at(2, 1, 1), util.grid().at(2, 1, 0), util.grid().at(1, 1, 0), + BlockPos[] wireLocations = new BlockPos[]{util.grid().at(2, 1, 1), util.grid().at(2, 1, 0), util.grid().at(1, 1, 0), util.grid().at(0, 1, 0), util.grid().at(0, 1, 1), util.grid().at(0, 1, 2), util.grid().at(0, 1, 3), util.grid().at(0, 1, 4), util.grid().at(1, 1, 4), util.grid().at(2, 1, 4), util.grid().at(3, 1, 4), - util.grid().at(4, 1, 4), util.grid().at(4, 1, 3), util.grid().at(4, 1, 2), util.grid().at(4, 1, 1) }; + util.grid().at(4, 1, 4), util.grid().at(4, 1, 3), util.grid().at(4, 1, 2), util.grid().at(4, 1, 1)}; Selection leverSelection = util.select().fromTo(2, 1, 2, 2, 2, 2); Selection lamp = util.select().position(4, 1, 0); @@ -638,7 +637,7 @@ public class RedstoneScenes { .withItem(clipboard); scene.idle(7); - Component component = Component.literal("CREATE"); + Component component = Component.literal("CREATE"); for (int i = 0; i < 3; i++) { final int index = i; scene.world().modifyBlockEntityNBT(util.select().position(3 - i, 1, 3), NixieTubeBlockEntity.class, nbt -> { From 2bd0034f01ab2517ccf3d6eeebee6ef9ff7d00cf Mon Sep 17 00:00:00 2001 From: TropheusJ <60247969+TropheusJ@users.noreply.github.com> Date: Sun, 23 Feb 2025 17:43:20 -0500 Subject: [PATCH 2/3] Stress Values API (#18) --- .../java/com/simibubi/create/AllBlocks.java | 100 +++++++------- .../create/api/stress/BlockStressValues.java | 50 +++++++ .../bearing/WindmillBearingBlock.java | 6 - .../content/fluids/tank/BoilerData.java | 2 +- .../content/kinetics/BlockStressDefaults.java | 68 --------- .../content/kinetics/BlockStressValues.java | 116 ---------------- .../kinetics/base/KineticBlockEntity.java | 2 +- .../kinetics/crank/HandCrankBlock.java | 6 - .../kinetics/crank/ValveHandleBlock.java | 9 +- .../steamEngine/PoweredShaftBlockEntity.java | 3 +- .../waterwheel/LargeWaterWheelBlock.java | 5 - .../kinetics/waterwheel/WaterWheelBlock.java | 5 - .../foundation/data/BuilderTransformers.java | 13 +- .../create/foundation/item/KineticStats.java | 13 +- .../infrastructure/config/AllConfigs.java | 7 +- .../create/infrastructure/config/CStress.java | 129 ++++++++---------- 16 files changed, 184 insertions(+), 350 deletions(-) create mode 100644 src/main/java/com/simibubi/create/api/stress/BlockStressValues.java delete mode 100644 src/main/java/com/simibubi/create/content/kinetics/BlockStressDefaults.java delete mode 100644 src/main/java/com/simibubi/create/content/kinetics/BlockStressValues.java diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 9fabbbf106..97dd7540a3 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -19,6 +19,7 @@ import static com.simibubi.create.foundation.data.TagGen.tagBlockAndItem; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.api.behaviour.interaction.ConductorBlockInteractionBehavior; +import com.simibubi.create.api.stress.BlockStressValues; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsBlock; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovement; import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovingInteraction; @@ -110,7 +111,6 @@ import com.simibubi.create.content.fluids.tank.FluidTankGenerator; import com.simibubi.create.content.fluids.tank.FluidTankItem; import com.simibubi.create.content.fluids.tank.FluidTankModel; import com.simibubi.create.content.fluids.tank.FluidTankMovementBehavior; -import com.simibubi.create.content.kinetics.BlockStressDefaults; import com.simibubi.create.content.kinetics.belt.BeltBlock; import com.simibubi.create.content.kinetics.belt.BeltGenerator; import com.simibubi.create.content.kinetics.belt.BeltModel; @@ -270,6 +270,7 @@ import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.item.UncontainableBlockItem; import com.simibubi.create.foundation.utility.ColorHandlers; import com.simibubi.create.foundation.utility.DyeHelper; +import com.simibubi.create.infrastructure.config.CStress; import com.tterrag.registrate.providers.RegistrateRecipeProvider; import com.tterrag.registrate.providers.loot.RegistrateBlockLootTables; import com.tterrag.registrate.util.DataIngredient; @@ -365,7 +366,7 @@ public class AllBlocks { public static final BlockEntry SHAFT = REGISTRATE.block("shaft", ShaftBlock::new) .initialProperties(SharedProperties::stone) .properties(p -> p.mapColor(MapColor.METAL).forceSolidOff()) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(pickaxeOnly()) .blockstate(BlockStateGen.axisBlockProvider(false)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) @@ -376,7 +377,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .properties(p -> p.sound(SoundType.WOOD) .mapColor(MapColor.DIRT)) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.axisBlockProvider(false)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) @@ -390,7 +391,7 @@ public class AllBlocks { .properties(p -> p.sound(SoundType.WOOD) .mapColor(MapColor.DIRT)) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(BlockStateGen.axisBlockProvider(false)) .onRegister(CreateRegistrate.blockModel(() -> BracketedKineticBlockModel::new)) .item(CogwheelBlockItem::new) @@ -456,7 +457,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .properties(p -> p.noOcclusion() .mapColor(MapColor.PODZOL)) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .onRegister(CreateRegistrate.connectedTextures(() -> new EncasedCTBehaviour(AllSpriteShifts.ANDESITE_CASING))) .onRegister(CreateRegistrate.casingConnectivity((block, cc) -> cc.make(block, AllSpriteShifts.ANDESITE_CASING, @@ -471,7 +472,7 @@ public class AllBlocks { .properties(p -> p.noOcclusion() .mapColor(MapColor.PODZOL)) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p))) .item() @@ -483,7 +484,7 @@ public class AllBlocks { .properties(p -> p.noOcclusion() .mapColor(MapColor.PODZOL)) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, AssetLookup.forPowered(c, p))) .item() @@ -495,7 +496,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .properties(p -> p.noOcclusion() .mapColor(MapColor.PODZOL)) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> p.models() .getExistingFile(p.modLoc("block/" + c.getName() + "/" + suffix))).generate(c, p)) @@ -508,7 +509,7 @@ public class AllBlocks { .initialProperties(SharedProperties::stone) .properties(p -> p.noOcclusion() .mapColor(MapColor.NETHER)) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .transform(axeOrPickaxe()) .blockstate((c, p) -> new ChainDriveGenerator((state, suffix) -> { String powered = state.getValue(ChainGearshiftBlock.POWERED) ? "_powered" : ""; @@ -530,7 +531,7 @@ public class AllBlocks { .addLayer(() -> RenderType::cutoutMipped) .transform(axeOrPickaxe()) .blockstate(new BeltGenerator()::generate) - .transform(BlockStressDefaults.setImpact(0)) + .transform(CStress.setNoImpact()) .transform(displaySource(AllDisplaySources.ITEM_NAMES)) .onRegister(CreateRegistrate.blockModel(() -> BeltModel::new)) .register(); @@ -541,7 +542,8 @@ public class AllBlocks { .properties(p -> p.noOcclusion() .mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setImpact(1)) + .transform(CStress.setImpact(1)) + .transform(CStress.setImpact(1)) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .item() .transform(customItemModel()) @@ -555,8 +557,8 @@ public class AllBlocks { .tag(AllBlockTags.SAFE_NBT.tag) .transform(pickaxeOnly()) .blockstate(new CreativeMotorGenerator()::generate) - .transform(BlockStressDefaults.setCapacity(16384.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(() -> Couple.create(0, 256))) + .transform(CStress.setCapacity(16384.0)) + .onRegister(BlockStressValues.setGeneratorSpeed(256, true)) .item() .properties(p -> p.rarity(Rarity.EPIC)) .transform(customItemModel()) @@ -570,8 +572,8 @@ public class AllBlocks { .blockstate( (c, p) -> BlockStateGen.directionalBlockIgnoresWaterlogged(c, p, s -> AssetLookup.partialBaseModel(c, p))) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setCapacity(32.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(WaterWheelBlock::getSpeedRange)) + .transform(CStress.setCapacity(32)) + .onRegister(BlockStressValues.setGeneratorSpeed(8)) .item() .transform(customItemModel()) .register(); @@ -585,8 +587,8 @@ public class AllBlocks { .blockstate((c, p) -> axisBlock(c, p, s -> s.getValue(LargeWaterWheelBlock.EXTENSION) ? AssetLookup.partialBaseModel(c, p, "extension") : AssetLookup.partialBaseModel(c, p))) - .transform(BlockStressDefaults.setCapacity(128.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(LargeWaterWheelBlock::getSpeedRange)) + .transform(CStress.setCapacity(128.0)) + .onRegister(BlockStressValues.setGeneratorSpeed(4)) .item(LargeWaterWheelBlockItem::new) .transform(customItemModel()) .register(); @@ -608,7 +610,7 @@ public class AllBlocks { .blockstate(BlockStateGen.directionalBlockProvider(true)) .addLayer(() -> RenderType::cutoutMipped) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setImpact(2.0)) + .transform(CStress.setImpact(2.0)) .item() .transform(customItemModel()) .register(); @@ -629,7 +631,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.standardModel(c, p))) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .simpleItem() .register(); @@ -638,8 +640,8 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.directionalBlockProvider(true)) - .transform(BlockStressDefaults.setCapacity(8.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(HandCrankBlock::getSpeedRange)) + .transform(CStress.setCapacity(8.0)) + .onRegister(BlockStressValues.setGeneratorSpeed(32)) .tag(AllBlockTags.BRITTLE.tag) .onRegister(ItemUseOverrides::addBlock) .item() @@ -669,7 +671,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.METAL)) .transform(pickaxeOnly()) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(customItemModel()) .register(); @@ -682,7 +684,7 @@ public class AllBlocks { .transform(pickaxeOnly()) .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, s -> AssetLookup.partialBaseModel(c, p))) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setImpact(8.0)) + .transform(CStress.setImpact(8.0)) .item() .transform(customItemModel()) .register(); @@ -706,7 +708,7 @@ public class AllBlocks { .mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.horizontalBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(8.0)) + .transform(CStress.setImpact(8.0)) .item(AssemblyOperatorBlockItem::new) .transform(customItemModel()) .register(); @@ -719,7 +721,7 @@ public class AllBlocks { .transform(axeOrPickaxe()) .blockstate((c, p) -> p.simpleBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item(AssemblyOperatorBlockItem::new) .transform(customItemModel()) .register(); @@ -793,7 +795,7 @@ public class AllBlocks { .mapColor(MapColor.COLOR_GRAY)) .transform(axeOrPickaxe()) .blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p), 180)) - .transform(BlockStressDefaults.setImpact(2.0)) + .transform(CStress.setImpact(2.0)) .transform(displaySource(AllDisplaySources.ITEM_NAMES)) .item(EjectorItem::new) .transform(customItemModel()) @@ -831,7 +833,7 @@ public class AllBlocks { .initialProperties(SharedProperties::wooden) .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(new GaugeGenerator()::generate) .transform(displaySource(AllDisplaySources.KINETIC_SPEED)) .item() @@ -842,7 +844,7 @@ public class AllBlocks { .initialProperties(SharedProperties::wooden) .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(new GaugeGenerator()::generate) .transform(displaySource(AllDisplaySources.KINETIC_STRESS)) .item() @@ -923,7 +925,7 @@ public class AllBlocks { .transform(pickaxeOnly()) .blockstate(BlockStateGen.directionalBlockProviderIgnoresWaterlogged(true)) .onRegister(CreateRegistrate.blockModel(() -> PipeAttachmentModel::withoutAO)) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(customItemModel()) .register(); @@ -955,7 +957,7 @@ public class AllBlocks { REGISTRATE.block("copper_valve_handle", ValveHandleBlock::copper) .transform(pickaxeOnly()) .transform(BuilderTransformers.valveHandle(null)) - .transform(BlockStressDefaults.setCapacity(8.0)) + .transform(CStress.setCapacity(8.0)) .register(); public static final DyedBlockList DYED_VALVE_HANDLES = new DyedBlockList<>(colour -> { @@ -1016,7 +1018,7 @@ public class AllBlocks { .addLayer(() -> RenderType::cutoutMipped) .transform(pickaxeOnly()) .blockstate(BlockStateGen.horizontalBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(customItemModel()) .register(); @@ -1055,8 +1057,8 @@ public class AllBlocks { .initialProperties(SharedProperties::copperMetal) .transform(pickaxeOnly()) .blockstate((c, p) -> p.horizontalFaceBlock(c.get(), AssetLookup.partialBaseModel(c, p))) - .transform(BlockStressDefaults.setCapacity(1024.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(SteamEngineBlock::getSpeedRange)) + .transform(CStress.setCapacity(1024.0)) + .onRegister(BlockStressValues.setGeneratorSpeed(64, true)) .item() .transform(customItemModel()) .register(); @@ -1162,7 +1164,7 @@ public class AllBlocks { existing.getLocation()) .texture("2", p.modLoc("block/" + c.getName() + powered + flipped)); })) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .item() .transform(customItemModel("_", "block_single")) .register(); @@ -1172,8 +1174,8 @@ public class AllBlocks { .transform(axeOrPickaxe()) .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(BuilderTransformers.bearing("windmill", "gearbox")) - .transform(BlockStressDefaults.setCapacity(512.0)) - .transform(BlockStressDefaults.setGeneratorSpeed(WindmillBearingBlock::getSpeedRange)) + .transform(CStress.setCapacity(512.0)) + .onRegister(BlockStressValues.setGeneratorSpeed(16, true)) .tag(AllBlockTags.SAFE_NBT.tag) .register(); @@ -1182,7 +1184,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .transform(BuilderTransformers.bearing("mechanical", "gearbox")) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .tag(AllBlockTags.SAFE_NBT.tag) .onRegister(movementBehaviour(new StabilizedBearingMovementBehaviour())) .register(); @@ -1192,7 +1194,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN)) .transform(axeOrPickaxe()) .transform(BuilderTransformers.bearing("clockwork", "brass_gearbox")) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .tag(AllBlockTags.SAFE_NBT.tag) .register(); @@ -1204,7 +1206,7 @@ public class AllBlocks { .transform(axeOrPickaxe()) .tag(AllBlockTags.SAFE_NBT.tag) .blockstate(BlockStateGen.horizontalAxisBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(customItemModel()) .register(); @@ -1233,7 +1235,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.TERRACOTTA_BROWN)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.horizontalBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(customItemModel()) .register(); @@ -1337,7 +1339,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.directionalBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .onRegister(movementBehaviour(new DrillMovementBehaviour())) .item() .tag(AllItemTags.CONTRAPTION_CONTROLLED.tag) @@ -1350,7 +1352,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate(new SawGenerator()::generate) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .onRegister(movementBehaviour(new SawMovementBehaviour())) .addLayer(() -> RenderType::cutoutMipped) .item() @@ -1363,7 +1365,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.PODZOL)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.directionalAxisBlockProvider()) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .onRegister(movementBehaviour(new DeployerMovementBehaviour())) .onRegister(interactionBehaviour(new DeployerMovingInteraction())) .item(AssemblyOperatorBlockItem::new) @@ -1538,7 +1540,7 @@ public class AllBlocks { .mapColor(MapColor.TERRACOTTA_YELLOW)) .transform(axeOrPickaxe()) .blockstate(BlockStateGen.horizontalBlockProvider(true)) - .transform(BlockStressDefaults.setImpact(2.0)) + .transform(CStress.setImpact(2.0)) .onRegister(CreateRegistrate.connectedTextures(CrafterCTBehaviour::new)) .addLayer(() -> RenderType::cutoutMipped) .item() @@ -1552,7 +1554,7 @@ public class AllBlocks { .transform(axeOrPickaxe()) .tag(AllBlockTags.SAFE_NBT.tag) .properties(BlockBehaviour.Properties::noOcclusion) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(new SequencedGearshiftGenerator()::generate) .item() .transform(customItemModel()) @@ -1563,7 +1565,7 @@ public class AllBlocks { .properties(p -> p.noOcclusion() .mapColor(MapColor.TERRACOTTA_YELLOW)) .transform(axeOrPickaxe()) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(BlockStateGen.axisBlockProvider(true)) .item() .transform(customItemModel()) @@ -1575,7 +1577,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.TERRACOTTA_YELLOW)) .transform(axeOrPickaxe()) .tag(AllBlockTags.SAFE_NBT.tag) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .blockstate(BlockStateGen.horizontalAxisBlockProvider(true)) .item() .transform(customItemModel()) @@ -1592,7 +1594,7 @@ public class AllBlocks { .modelFile(AssetLookup.partialBaseModel(c, p)) .rotationX(s.getValue(ArmBlock.CEILING) ? 180 : 0) .build())) - .transform(BlockStressDefaults.setImpact(2.0)) + .transform(CStress.setImpact(2.0)) .item(ArmItem::new) .transform(customItemModel()) .register(); @@ -2026,7 +2028,7 @@ public class AllBlocks { .properties(p -> p.mapColor(MapColor.COLOR_GRAY)) .addLayer(() -> RenderType::cutoutMipped) .transform(pickaxeOnly()) - .transform(BlockStressDefaults.setImpact(0)) + .transform(CStress.setNoImpact()) .blockstate((c, p) -> p.horizontalBlock(c.get(), AssetLookup.partialBaseModel(c, p))) .transform(displayTarget(AllDisplayTargets.DISPLAY_BOARD)) .lang("Display Board") diff --git a/src/main/java/com/simibubi/create/api/stress/BlockStressValues.java b/src/main/java/com/simibubi/create/api/stress/BlockStressValues.java new file mode 100644 index 0000000000..47c137aa87 --- /dev/null +++ b/src/main/java/com/simibubi/create/api/stress/BlockStressValues.java @@ -0,0 +1,50 @@ +package com.simibubi.create.api.stress; + +import java.util.function.DoubleSupplier; + +import com.simibubi.create.api.registry.SimpleRegistry; +import com.tterrag.registrate.util.nullness.NonNullConsumer; + +import net.minecraft.world.level.block.Block; + +public class BlockStressValues { + /** + * Registry for suppliers of stress impacts. Determine the base impact at 1 RPM. + */ + public static final SimpleRegistry IMPACTS = SimpleRegistry.create(); + /** + * Registry for suppliers of stress capacities. Determine the base capacity at 1 RPM. + */ + public static final SimpleRegistry CAPACITIES = SimpleRegistry.create(); + /** + * Registry for generator RPM values. This is only used for tooltips; actual functionality is determined by the block. + */ + public static final SimpleRegistry RPM = SimpleRegistry.create(); + + public static double getImpact(Block block) { + DoubleSupplier supplier = IMPACTS.get(block); + return supplier == null ? 0 : supplier.getAsDouble(); + } + + public static double getCapacity(Block block) { + DoubleSupplier supplier = CAPACITIES.get(block); + return supplier == null ? 0 : supplier.getAsDouble(); + } + + /** + * Shortcut for when a generator always generates the same RPM. + */ + public static NonNullConsumer setGeneratorSpeed(int value) { + return block -> RPM.register(block, new GeneratedRpm(value, false)); + } + + /** + * Utility for Registrate. Registers the given RPM generation info to blocks passed to the returned consumer. + */ + public static NonNullConsumer setGeneratorSpeed(int value, boolean mayGenerateLess) { + return block -> RPM.register(block, new GeneratedRpm(value, mayGenerateLess)); + } + + public record GeneratedRpm(int value, boolean mayGenerateLess) { + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/bearing/WindmillBearingBlock.java b/src/main/java/com/simibubi/create/content/contraptions/bearing/WindmillBearingBlock.java index 24676fd4c9..11bd891e30 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/bearing/WindmillBearingBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/bearing/WindmillBearingBlock.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.bearing; import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.foundation.block.IBE; -import net.createmod.catnip.data.Couple; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -51,9 +50,4 @@ public class WindmillBearingBlock extends BearingBlock implements IBE getBlockEntityType() { return AllBlockEntityTypes.WINDMILL_BEARING.get(); } - - public static Couple getSpeedRange() { - return Couple.create(1, 16); - } - } diff --git a/src/main/java/com/simibubi/create/content/fluids/tank/BoilerData.java b/src/main/java/com/simibubi/create/content/fluids/tank/BoilerData.java index e0750e75d6..6dfd085c10 100644 --- a/src/main/java/com/simibubi/create/content/fluids/tank/BoilerData.java +++ b/src/main/java/com/simibubi/create/content/fluids/tank/BoilerData.java @@ -11,9 +11,9 @@ import org.jetbrains.annotations.NotNull; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllSoundEvents; import com.simibubi.create.api.boiler.BoilerHeater; +import com.simibubi.create.api.stress.BlockStressValues; import com.simibubi.create.content.decoration.steamWhistle.WhistleBlock; import com.simibubi.create.content.decoration.steamWhistle.WhistleBlockEntity; -import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.content.kinetics.steamEngine.SteamEngineBlock; import com.simibubi.create.foundation.advancement.AdvancementBehaviour; import com.simibubi.create.foundation.advancement.AllAdvancements; diff --git a/src/main/java/com/simibubi/create/content/kinetics/BlockStressDefaults.java b/src/main/java/com/simibubi/create/content/kinetics/BlockStressDefaults.java deleted file mode 100644 index 8acbf2156c..0000000000 --- a/src/main/java/com/simibubi/create/content/kinetics/BlockStressDefaults.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.simibubi.create.content.kinetics; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Supplier; - -import com.tterrag.registrate.builders.BlockBuilder; -import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; - -import net.createmod.catnip.data.Couple; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; - -public class BlockStressDefaults { - - /** - * Increment this number if all stress entries should be forced to update in the - * next release. Worlds from the previous version will overwrite potentially - * changed values with the new defaults. - */ - public static final int FORCED_UPDATE_VERSION = 2; - - public static final Map DEFAULT_IMPACTS = new ConcurrentHashMap<>(); - public static final Map DEFAULT_CAPACITIES = new ConcurrentHashMap<>(); - public static final Map>> GENERATOR_SPEEDS = new ConcurrentHashMap<>(); - - public static void setDefaultImpact(ResourceLocation blockId, double impact) { - DEFAULT_IMPACTS.put(blockId, impact); - } - - public static void setDefaultCapacity(ResourceLocation blockId, double capacity) { - DEFAULT_CAPACITIES.put(blockId, capacity); - } - - public static void setGeneratorSpeed(ResourceLocation blockId, Supplier> provider) { - GENERATOR_SPEEDS.put(blockId, provider); - } - - public static NonNullUnaryOperator> setNoImpact() { - return setImpact(0); - } - - public static NonNullUnaryOperator> setImpact(double impact) { - return b -> { - setDefaultImpact(new ResourceLocation(b.getOwner() - .getModid(), b.getName()), impact); - return b; - }; - } - - public static NonNullUnaryOperator> setCapacity(double capacity) { - return b -> { - setDefaultCapacity(new ResourceLocation(b.getOwner() - .getModid(), b.getName()), capacity); - return b; - }; - } - - public static NonNullUnaryOperator> setGeneratorSpeed( - Supplier> provider) { - return b -> { - setGeneratorSpeed(new ResourceLocation(b.getOwner() - .getModid(), b.getName()), provider); - return b; - }; - } - -} diff --git a/src/main/java/com/simibubi/create/content/kinetics/BlockStressValues.java b/src/main/java/com/simibubi/create/content/kinetics/BlockStressValues.java deleted file mode 100644 index d0b6d24b61..0000000000 --- a/src/main/java/com/simibubi/create/content/kinetics/BlockStressValues.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.simibubi.create.content.kinetics; - -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; - -import net.createmod.catnip.platform.CatnipServices; -import net.createmod.catnip.data.Couple; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; - -public class BlockStressValues { - - private static final Map PROVIDERS = new HashMap<>(); - - public static void registerProvider(String namespace, IStressValueProvider provider) { - PROVIDERS.put(namespace, provider); - } - - @Nullable - public static IStressValueProvider getProvider(String namespace) { - return PROVIDERS.get(namespace); - } - - @Nullable - public static IStressValueProvider getProvider(Block block) { - return getProvider(CatnipServices.REGISTRIES.getKeyOrThrow(block) - .getNamespace()); - } - - public static double getImpact(Block block) { - ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block); - IStressValueProvider provider = getProvider(blockId.getNamespace()); - if (provider != null) { - return provider.getImpact(block); - } - Double defaultImpact = BlockStressDefaults.DEFAULT_IMPACTS.get(blockId); - if (defaultImpact != null) { - return defaultImpact; - } - return 0; - } - - public static double getCapacity(Block block) { - ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block); - IStressValueProvider provider = getProvider(blockId.getNamespace()); - if (provider != null) { - return provider.getCapacity(block); - } - Double defaultCapacity = BlockStressDefaults.DEFAULT_CAPACITIES.get(blockId); - if (defaultCapacity != null) { - return defaultCapacity; - } - return 0; - } - - public static boolean hasImpact(Block block) { - ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block); - IStressValueProvider provider = getProvider(blockId.getNamespace()); - if (provider != null) { - return provider.hasImpact(block); - } - return BlockStressDefaults.DEFAULT_IMPACTS.containsKey(blockId); - } - - public static boolean hasCapacity(Block block) { - ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block); - IStressValueProvider provider = getProvider(blockId.getNamespace()); - if (provider != null) { - return provider.hasCapacity(block); - } - return BlockStressDefaults.DEFAULT_CAPACITIES.containsKey(blockId); - } - - @Nullable - public static Couple getGeneratedRPM(Block block) { - ResourceLocation blockId = CatnipServices.REGISTRIES.getKeyOrThrow(block); - IStressValueProvider provider = getProvider(blockId.getNamespace()); - if (provider != null) { - return provider.getGeneratedRPM(block); - } - return null; - } - - public interface IStressValueProvider { - /** - * Gets the stress impact of a block. - * - * @param block The block. - * @return the stress impact value of the block, or 0 if it does not have one. - */ - double getImpact(Block block); - - /** - * Gets the stress capacity of a block. - * - * @param block The block. - * @return the stress capacity value of the block, or 0 if it does not have one. - */ - double getCapacity(Block block); - - boolean hasImpact(Block block); - - boolean hasCapacity(Block block); - - /** - * - * @param block - * @return min, max generated RPM; null if block does not have a stress capacity - */ - @Nullable - Couple getGeneratedRPM(Block block); - } - -} diff --git a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntity.java index 9f0ac2d03c..bab6c06ea9 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/base/KineticBlockEntity.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; import com.simibubi.create.Create; import com.simibubi.create.api.equipment.goggles.IHaveGoggleInformation; import com.simibubi.create.api.equipment.goggles.IHaveHoveringInformation; -import com.simibubi.create.content.kinetics.BlockStressValues; +import com.simibubi.create.api.stress.BlockStressValues; import com.simibubi.create.content.kinetics.KineticNetwork; import com.simibubi.create.content.kinetics.RotationPropagator; import com.simibubi.create.content.kinetics.base.IRotate.SpeedLevel; diff --git a/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankBlock.java b/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankBlock.java index c6395a26c9..2639e3d6ab 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankBlock.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crank/HandCrankBlock.java @@ -9,7 +9,6 @@ import com.simibubi.create.foundation.block.IBE; import com.simibubi.create.foundation.block.ProperWaterloggedBlock; import com.simibubi.create.infrastructure.config.AllConfigs; -import net.createmod.catnip.data.Couple; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; @@ -150,9 +149,4 @@ public class HandCrankBlock extends DirectionalKineticBlock public boolean isPathfindable(BlockState state, BlockGetter reader, BlockPos pos, PathComputationType type) { return false; } - - public static Couple getSpeedRange() { - return Couple.create(32, 32); - } - } diff --git a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlock.java b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlock.java index ff795cf77f..e8d168db91 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlock.java +++ b/src/main/java/com/simibubi/create/content/kinetics/crank/ValveHandleBlock.java @@ -8,7 +8,6 @@ import com.simibubi.create.AllItems; import com.simibubi.create.AllShapes; import com.simibubi.create.foundation.utility.BlockHelper; -import net.createmod.catnip.data.Couple; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -22,6 +21,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; + import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -32,7 +32,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber; public class ValveHandleBlock extends HandCrankBlock { public final DyeColor color; - + public static ValveHandleBlock copper(Properties properties) { return new ValveHandleBlock(properties, null); } @@ -111,9 +111,4 @@ public class ValveHandleBlock extends HandCrankBlock { public int getRotationSpeed() { return 32; } - - public static Couple getSpeedRange() { - return Couple.create(32, 32); - } - } diff --git a/src/main/java/com/simibubi/create/content/kinetics/steamEngine/PoweredShaftBlockEntity.java b/src/main/java/com/simibubi/create/content/kinetics/steamEngine/PoweredShaftBlockEntity.java index 33c46cfd09..50c02d6bc0 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/steamEngine/PoweredShaftBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/kinetics/steamEngine/PoweredShaftBlockEntity.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.kinetics.steamEngine; import java.util.List; -import com.simibubi.create.content.kinetics.BlockStressValues; +import com.simibubi.create.api.stress.BlockStressValues; import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity; import net.createmod.catnip.platform.CatnipServices; @@ -16,6 +16,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; + import net.minecraftforge.registries.ForgeRegistries; public class PoweredShaftBlockEntity extends GeneratingKineticBlockEntity { diff --git a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/LargeWaterWheelBlock.java b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/LargeWaterWheelBlock.java index a9cd1fc302..a2701b9f10 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/LargeWaterWheelBlock.java +++ b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/LargeWaterWheelBlock.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock; import com.simibubi.create.foundation.block.IBE; -import net.createmod.catnip.data.Couple; import net.createmod.catnip.data.Iterate; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -164,10 +163,6 @@ public class LargeWaterWheelBlock extends RotatedPillarKineticBlock implements I return 2.25f; } - public static Couple getSpeedRange() { - return Couple.create(4, 4); - } - @Override public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return false; diff --git a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelBlock.java b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelBlock.java index e52c6113de..cffe2b78b4 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelBlock.java +++ b/src/main/java/com/simibubi/create/content/kinetics/waterwheel/WaterWheelBlock.java @@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.kinetics.base.DirectionalKineticBlock; import com.simibubi.create.foundation.block.IBE; -import net.createmod.catnip.data.Couple; import net.createmod.catnip.data.Iterate; import net.createmod.catnip.levelWrappers.WrappedLevel; import net.minecraft.core.BlockPos; @@ -127,10 +126,6 @@ public class WaterWheelBlock extends DirectionalKineticBlock implements IBE getSpeedRange() { - return Couple.create(8, 8); - } - @Override public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return false; diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index 54f04c8197..49809df8a6 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -20,6 +20,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.Create; +import com.simibubi.create.api.stress.BlockStressValues; import com.simibubi.create.content.contraptions.behaviour.DoorMovingInteraction; import com.simibubi.create.content.contraptions.behaviour.TrapdoorMovingInteraction; import com.simibubi.create.content.contraptions.piston.MechanicalPistonGenerator; @@ -31,7 +32,6 @@ import com.simibubi.create.content.decoration.encasing.CasingBlock; import com.simibubi.create.content.decoration.encasing.EncasedCTBehaviour; import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock; import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorMovementBehaviour; -import com.simibubi.create.content.kinetics.BlockStressDefaults; import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock; import com.simibubi.create.content.kinetics.crank.ValveHandleBlock; import com.simibubi.create.content.kinetics.simpleRelays.encased.EncasedCogCTBehaviour; @@ -51,6 +51,7 @@ import com.simibubi.create.foundation.block.ItemUseOverrides; import com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry; import com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour; import com.simibubi.create.foundation.item.ItemDescription; +import com.simibubi.create.infrastructure.config.CStress; import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.ItemBuilder; import com.tterrag.registrate.providers.RegistrateRecipeProvider; @@ -226,7 +227,7 @@ public class BuilderTransformers { Supplier drop) { return b.initialProperties(SharedProperties::stone) .properties(BlockBehaviour.Properties::noOcclusion) - .transform(BlockStressDefaults.setNoImpact()) + .transform(CStress.setNoImpact()) .loot((p, lb) -> p.dropOther(lb, drop.get())); } @@ -235,7 +236,7 @@ public class BuilderTransformers { .blockstate((c, p) -> p.horizontalBlock(c.get(), p.models() .getExistingFile(p.modLoc("block/cuckoo_clock/block")))) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setImpact(1.0)) + .transform(CStress.setImpact(1)) .item() .transform(ModelGen.customItemModel("cuckoo_clock", "item")); } @@ -299,7 +300,7 @@ public class BuilderTransformers { .texture("3", p.modLoc("block/valve_handle/valve_handle_" + variant))); }) .tag(AllBlockTags.BRITTLE.tag, AllBlockTags.VALVE_HANDLES.tag) - .transform(BlockStressDefaults.setGeneratorSpeed(ValveHandleBlock::getSpeedRange)) + .onRegister(BlockStressValues.setGeneratorSpeed(32)) .onRegister(ItemUseOverrides::addBlock) .item() .tag(AllItemTags.VALVE_HANDLES.tag) @@ -380,7 +381,7 @@ public class BuilderTransformers { .properties(p -> p.noOcclusion()) .blockstate(new MechanicalPistonGenerator(type)::generate) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .item() .transform(ModelGen.customItemModel("mechanical_piston", type.getSerializedName(), "item")); } @@ -441,7 +442,7 @@ public class BuilderTransformers { return b -> b.blockstate((c, p) -> p.horizontalBlock(c.getEntry(), AssetLookup.partialBaseModel(c, p))) .transform(pickaxeOnly()) .addLayer(() -> RenderType::cutoutMipped) - .transform(BlockStressDefaults.setImpact(4.0)) + .transform(CStress.setImpact(4.0)) .loot((lt, block) -> { Builder builder = LootTable.lootTable(); LootItemCondition.Builder survivesExplosion = ExplosionCondition.survivesExplosion(); diff --git a/src/main/java/com/simibubi/create/foundation/item/KineticStats.java b/src/main/java/com/simibubi/create/foundation/item/KineticStats.java index 70cbb183cc..d9fc2280fb 100644 --- a/src/main/java/com/simibubi/create/foundation/item/KineticStats.java +++ b/src/main/java/com/simibubi/create/foundation/item/KineticStats.java @@ -9,8 +9,9 @@ import java.util.List; import org.jetbrains.annotations.Nullable; import com.simibubi.create.AllBlocks; +import com.simibubi.create.api.stress.BlockStressValues; +import com.simibubi.create.api.stress.BlockStressValues.GeneratedRpm; import com.simibubi.create.content.equipment.goggles.GogglesItem; -import com.simibubi.create.content.kinetics.BlockStressValues; import com.simibubi.create.content.kinetics.base.IRotate; import com.simibubi.create.content.kinetics.base.IRotate.StressImpact; import com.simibubi.create.content.kinetics.crank.ValveHandleBlock; @@ -19,7 +20,6 @@ import com.simibubi.create.foundation.utility.CreateLang; import com.simibubi.create.infrastructure.config.AllConfigs; import com.simibubi.create.infrastructure.config.CKinetics; -import net.createmod.catnip.data.Couple; import net.createmod.catnip.lang.Lang; import net.createmod.catnip.lang.LangBuilder; import net.minecraft.network.chat.CommonComponents; @@ -80,7 +80,7 @@ public class KineticStats implements TooltipModifier { boolean hasStressImpact = StressImpact.isEnabled() && showStressImpact && BlockStressValues.getImpact(block) > 0; - boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.hasCapacity(block); + boolean hasStressCapacity = StressImpact.isEnabled() && BlockStressValues.getCapacity(block) > 0; if (hasStressImpact) { CreateLang.translate("tooltip.stressImpact") @@ -110,7 +110,7 @@ public class KineticStats implements TooltipModifier { .addTo(list); double capacity = BlockStressValues.getCapacity(block); - Couple generatedRPM = BlockStressValues.getGeneratedRPM(block); + GeneratedRpm generatedRPM = BlockStressValues.RPM.get(block); StressImpact impactId = capacity >= config.highCapacity.get() ? StressImpact.HIGH : (capacity >= config.mediumCapacity.get() ? StressImpact.MEDIUM : StressImpact.LOW); @@ -126,11 +126,10 @@ public class KineticStats implements TooltipModifier { .addTo(list); if (generatedRPM != null) { - LangBuilder amount = CreateLang.number(capacity * generatedRPM.getSecond()) + LangBuilder amount = CreateLang.number(capacity * generatedRPM.value()) .add(suUnit); CreateLang.text(" -> ") - .add(!generatedRPM.getFirst() - .equals(generatedRPM.getSecond()) ? CreateLang.translate("tooltip.up_to", amount) : amount) + .add(generatedRPM.mayGenerateLess() ? CreateLang.translate("tooltip.up_to", amount) : amount) .style(DARK_GRAY) .addTo(list); } diff --git a/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java b/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java index 0312732839..28ecc292d5 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/AllConfigs.java @@ -7,9 +7,10 @@ import java.util.function.Supplier; import org.apache.commons.lang3.tuple.Pair; -import com.simibubi.create.content.kinetics.BlockStressValues; +import com.simibubi.create.api.stress.BlockStressValues; import net.createmod.catnip.config.ConfigBase; + import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; @@ -63,7 +64,9 @@ public class AllConfigs { for (Entry pair : CONFIGS.entrySet()) context.registerConfig(pair.getKey(), pair.getValue().specification); - BlockStressValues.registerProvider(context.getActiveNamespace(), server().kinetics.stressValues); + CStress stress = server().kinetics.stressValues; + BlockStressValues.IMPACTS.registerProvider(stress::getImpact); + BlockStressValues.CAPACITIES.registerProvider(stress::getCapacity); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/infrastructure/config/CStress.java b/src/main/java/com/simibubi/create/infrastructure/config/CStress.java index 4d5a3f104b..4c5a930f28 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/CStress.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/CStress.java @@ -2,105 +2,94 @@ package com.simibubi.create.infrastructure.config; import java.util.HashMap; import java.util.Map; -import java.util.function.Supplier; +import java.util.function.DoubleSupplier; + +import org.jetbrains.annotations.Nullable; import com.simibubi.create.Create; -import com.simibubi.create.content.kinetics.BlockStressDefaults; -import com.simibubi.create.content.kinetics.BlockStressValues.IStressValueProvider; +import com.tterrag.registrate.builders.BlockBuilder; +import com.tterrag.registrate.util.nullness.NonNullUnaryOperator; +import it.unimi.dsi.fastutil.objects.Object2DoubleMap; +import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; import net.createmod.catnip.config.ConfigBase; import net.createmod.catnip.platform.CatnipServices; -import net.createmod.catnip.data.Couple; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; + import net.minecraftforge.common.ForgeConfigSpec.Builder; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; -public class CStress extends ConfigBase implements IStressValueProvider { +public class CStress extends ConfigBase { + // bump this version to reset configured values. + private static final int VERSION = 2; - private final Map> capacities = new HashMap<>(); - private final Map> impacts = new HashMap<>(); + // IDs need to be used since configs load before registration + + private static final Object2DoubleMap DEFAULT_IMPACTS = new Object2DoubleOpenHashMap<>(); + private static final Object2DoubleMap DEFAULT_CAPACITIES = new Object2DoubleOpenHashMap<>(); + + protected final Map> capacities = new HashMap<>(); + protected final Map> impacts = new HashMap<>(); @Override public void registerAll(Builder builder) { builder.comment(".", Comments.su, Comments.impact) .push("impact"); - BlockStressDefaults.DEFAULT_IMPACTS.forEach((r, i) -> { - if (r.getNamespace() - .equals(Create.ID)) - getImpacts().put(r, builder.define(r.getPath(), i)); - }); + DEFAULT_IMPACTS.forEach((id, value) -> this.impacts.put(id, builder.define(id.getPath(), value))); builder.pop(); builder.comment(".", Comments.su, Comments.capacity) .push("capacity"); - BlockStressDefaults.DEFAULT_CAPACITIES.forEach((r, i) -> { - if (r.getNamespace() - .equals(Create.ID)) - getCapacities().put(r, builder.define(r.getPath(), i)); - }); + DEFAULT_CAPACITIES.forEach((id, value) -> this.capacities.put(id, builder.define(id.getPath(), value))); builder.pop(); } - @Override - public double getImpact(Block block) { - block = redirectValues(block); - ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block); - ConfigValue value = getImpacts().get(key); - if (value != null) - return value.get(); - return 0; - } - - @Override - public double getCapacity(Block block) { - block = redirectValues(block); - ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block); - ConfigValue value = getCapacities().get(key); - if (value != null) - return value.get(); - return 0; - } - - @Override - public Couple getGeneratedRPM(Block block) { - block = redirectValues(block); - ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block); - Supplier> supplier = BlockStressDefaults.GENERATOR_SPEEDS.get(key); - if (supplier == null) - return null; - return supplier.get(); - } - - @Override - public boolean hasImpact(Block block) { - block = redirectValues(block); - ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block); - return getImpacts().containsKey(key); - } - - @Override - public boolean hasCapacity(Block block) { - block = redirectValues(block); - ResourceLocation key = CatnipServices.REGISTRIES.getKeyOrThrow(block); - return getCapacities().containsKey(key); - } - - protected Block redirectValues(Block block) { - return block; - } - @Override public String getName() { - return "stressValues.v" + BlockStressDefaults.FORCED_UPDATE_VERSION; + return "stressValues.v" + VERSION; } - public Map> getImpacts() { - return impacts; + @Nullable + public DoubleSupplier getImpact(Block block) { + ResourceLocation id = CatnipServices.REGISTRIES.getKeyOrThrow(block); + ConfigValue value = this.impacts.get(id); + return value == null ? null : value::get; } - public Map> getCapacities() { - return capacities; + @Nullable + public DoubleSupplier getCapacity(Block block) { + ResourceLocation id = CatnipServices.REGISTRIES.getKeyOrThrow(block); + ConfigValue value = this.capacities.get(id); + return value == null ? null : value::get; + } + + public static NonNullUnaryOperator> setNoImpact() { + return setImpact(0); + } + + public static NonNullUnaryOperator> setImpact(double value) { + return builder -> { + assertFromCreate(builder); + ResourceLocation id = Create.asResource(builder.getName()); + DEFAULT_IMPACTS.put(id, value); + return builder; + }; + } + + public static NonNullUnaryOperator> setCapacity(double value) { + return builder -> { + assertFromCreate(builder); + ResourceLocation id = Create.asResource(builder.getName()); + DEFAULT_CAPACITIES.put(id, value); + return builder; + }; + } + + private static void assertFromCreate(BlockBuilder builder) { + if (!builder.getOwner().getModid().equals(Create.ID)) { + throw new IllegalStateException("Non-Create blocks cannot be added to Create's config."); + } } private static class Comments { From a50fb9dac0bf5270b8a182d0ad0428ed297785e5 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Sun, 23 Feb 2025 20:07:54 -0500 Subject: [PATCH 3/3] Convert Potato Cannon projectile types into a dynamic registry (#19) --- changelog.md | 3 + .../eaed56ca9d9781c7626be345dd9f2c9a1fad638e | 27 +- .../create/potato_projectile/type/apple.json | 10 + .../potato_projectile/type/baked_potato.json | 14 + .../potato_projectile/type/beetroot.json | 13 + .../potato_projectile/type/blaze_cake.json | 15 + .../create/potato_projectile/type/cake.json | 11 + .../create/potato_projectile/type/carrot.json | 17 + .../type/chocolate_berry.json | 11 + .../potato_projectile/type/chorus_fruit.json | 14 + .../type/enchanted_golden_apple.json | 51 +++ .../potato_projectile/type/fallback.json | 4 + .../create/potato_projectile/type/fish.json | 19 + .../type/glistering_melon.json | 18 + .../potato_projectile/type/glow_berry.json | 18 + .../potato_projectile/type/golden_apple.json | 13 + .../potato_projectile/type/golden_carrot.json | 13 + .../potato_projectile/type/honeyed_apple.json | 18 + .../potato_projectile/type/melon_block.json | 15 + .../potato_projectile/type/melon_slice.json | 11 + .../potato_projectile/type/poison_potato.json | 17 + .../create/potato_projectile/type/potato.json | 14 + .../potato_projectile/type/pufferfish.json | 46 ++ .../potato_projectile/type/pumpkin_block.json | 15 + .../potato_projectile/type/pumpkin_pie.json | 12 + .../type/suspicious_stew.json | 19 + .../potato_projectile/type/sweet_berry.json | 11 + .../java/com/simibubi/create/AllPackets.java | 7 +- src/main/java/com/simibubi/create/Create.java | 20 +- .../PotatoCannonProjectileType.java | 230 ++++++++++ .../PotatoProjectileBlockHitAction.java | 120 +++++ .../PotatoProjectileEntityHitAction.java | 245 ++++++++++ .../PotatoProjectileRenderMode.java | 71 +-- .../api/registry/CreateBuiltInRegistries.java | 7 + .../create/api/registry/CreateRegistries.java | 28 ++ .../extendoGrip/ExtendoGripItem.java | 1 + .../AllPotatoProjectileBlockHitActions.java | 21 + .../AllPotatoProjectileEntityHitActions.java | 29 ++ .../AllPotatoProjectileRenderModes.java | 25 ++ .../AllPotatoProjectileTypes.java | 266 +++++++++++ .../BuiltinPotatoProjectileTypes.java | 420 ------------------ .../potatoCannon/PotatoCannonItem.java | 63 +-- .../PotatoCannonItemRenderer.java | 25 +- .../PotatoCannonProjectileType.java | 298 ------------- .../potatoCannon/PotatoProjectileEntity.java | 41 +- .../PotatoProjectileTypeManager.java | 160 ------- .../foundation/events/CommonEvents.java | 13 - .../create/foundation/mixin/PlayerMixin.java | 4 +- .../accessor/MobEffectInstanceAccessor.java | 12 + .../accessor/SuspiciousStewItemAccessor.java | 18 + .../foundation/utility/CreateCodecs.java | 133 ++++++ .../infrastructure/config/CKinetics.java | 2 + .../data/GeneratedEntriesProvider.java | 14 +- src/main/resources/create.mixins.json | 2 + 54 files changed, 1736 insertions(+), 988 deletions(-) create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/apple.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/baked_potato.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/beetroot.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/blaze_cake.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/cake.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/carrot.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/chocolate_berry.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/chorus_fruit.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/enchanted_golden_apple.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/fallback.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/fish.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/glistering_melon.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/glow_berry.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/golden_apple.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/golden_carrot.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/honeyed_apple.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/melon_block.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/melon_slice.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/poison_potato.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/potato.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/pufferfish.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/pumpkin_block.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/pumpkin_pie.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/suspicious_stew.json create mode 100644 src/generated/resources/data/create/create/potato_projectile/type/sweet_berry.json create mode 100644 src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoCannonProjectileType.java create mode 100644 src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileBlockHitAction.java create mode 100644 src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileEntityHitAction.java rename src/main/java/com/simibubi/create/{content => api}/equipment/potatoCannon/PotatoProjectileRenderMode.java (51%) create mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileBlockHitActions.java create mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileEntityHitActions.java create mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileRenderModes.java create mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileTypes.java delete mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/BuiltinPotatoProjectileTypes.java delete mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonProjectileType.java delete mode 100644 src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileTypeManager.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/accessor/MobEffectInstanceAccessor.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/accessor/SuspiciousStewItemAccessor.java diff --git a/changelog.md b/changelog.md index e62e75725f..a24b5b089e 100644 --- a/changelog.md +++ b/changelog.md @@ -149,3 +149,6 @@ _Now using Flywheel 1.0_ - Synced AllPortalTracks with Create Fabric - Implemented DyeHelper api (#7265) - Implemented api to add custom block train conductors (#7030) +- Convert Potato Cannon project types into a dynamic registry + - Everything can be done with datapacks now, and there is no need to write a mod unless you need to add new + Render Modes, Entity Hit Actions or Block Hit Actions diff --git a/src/generated/resources/.cache/eaed56ca9d9781c7626be345dd9f2c9a1fad638e b/src/generated/resources/.cache/eaed56ca9d9781c7626be345dd9f2c9a1fad638e index 8022840b42..9dad6da61c 100644 --- a/src/generated/resources/.cache/eaed56ca9d9781c7626be345dd9f2c9a1fad638e +++ b/src/generated/resources/.cache/eaed56ca9d9781c7626be345dd9f2c9a1fad638e @@ -1,4 +1,29 @@ -// 1.20.1 2025-02-02T11:59:39.5970888 Create's Generated Registry Entries +// 1.20.1 2025-02-23T18:42:20.032170723 Create's Generated Registry Entries +abb9dd2c98388abb430343d4ac02d460e5edc086 data/create/create/potato_projectile/type/apple.json +1a20cb4e64dc07918a28fbccc73102bca3560f16 data/create/create/potato_projectile/type/baked_potato.json +8450576952f7723d22250da6f554dd0fda4e9fce data/create/create/potato_projectile/type/beetroot.json +9d927ec9c8b76a093e7ff8ff8f81be3a438d4aba data/create/create/potato_projectile/type/blaze_cake.json +46ccaf468caaa4faaca4f1494f60e99cd00785c9 data/create/create/potato_projectile/type/cake.json +22e0f5befe5835c7a9a6448e17e73e6fb7d0fb9c data/create/create/potato_projectile/type/carrot.json +af17d72549ee9421d2643a215ffc2291874fff93 data/create/create/potato_projectile/type/chocolate_berry.json +8cb4811601d46db5fdc0291edce3ec2f3a64e902 data/create/create/potato_projectile/type/chorus_fruit.json +9dd1298993a4657d69a9d2ac4de3ad7879d9aa8d data/create/create/potato_projectile/type/enchanted_golden_apple.json +e3ab3c4bd70ad742d37091ae05774aadffb1d1d5 data/create/create/potato_projectile/type/fallback.json +98bf0ce51484c5a9709fc69d046d0c70d987cfdd data/create/create/potato_projectile/type/fish.json +afe4e7cc87110d6f045f6672fb312a09290ca04a data/create/create/potato_projectile/type/glistering_melon.json +050c9333d41efd2577e1e597c7c68b00436b0963 data/create/create/potato_projectile/type/glow_berry.json +52046463af1abc92c5257992c302d7ab26c63e28 data/create/create/potato_projectile/type/golden_apple.json +c6234751ccad5111857b0ae9e297e42f529ad32a data/create/create/potato_projectile/type/golden_carrot.json +583b75978a4f920c2969473e5353fcc89886b612 data/create/create/potato_projectile/type/honeyed_apple.json +7a269ded36d1397f86f23c4c431c7a99fea74446 data/create/create/potato_projectile/type/melon_block.json +352402ba2fff3f23af178d15d61b0ba0a151097a data/create/create/potato_projectile/type/melon_slice.json +cbfd3028ad878bddbdaeb0eec0cd5a1c50d4c901 data/create/create/potato_projectile/type/poison_potato.json +b58e779803d29d4b36ecf79fde4e918577c71748 data/create/create/potato_projectile/type/potato.json +d15070ca23129e7d4025d86cb4be5701a466e593 data/create/create/potato_projectile/type/pufferfish.json +0c099b5f1bd7ba3832ea2d29e8c1c22c83ed1c3d data/create/create/potato_projectile/type/pumpkin_block.json +7d58a0671c55e40cdb728c60152665c89209fb91 data/create/create/potato_projectile/type/pumpkin_pie.json +2dc21c61b4fd4c60b9ade2974b395df42611ee26 data/create/create/potato_projectile/type/suspicious_stew.json +b4a7c10bd9cdcfe67df2a5766e5ec2e35a3f9b24 data/create/create/potato_projectile/type/sweet_berry.json 030ede1044384c4117ac1e491bf5c78bbd2842f5 data/create/damage_type/crush.json 92b0416950ffeb3ba68811e587177c2f8811c2c5 data/create/damage_type/cuckoo_surprise.json d2a4fdb64f4ba817e13a7b20c73fd1ca34b825fc data/create/damage_type/fan_fire.json diff --git a/src/generated/resources/data/create/create/potato_projectile/type/apple.json b/src/generated/resources/data/create/create/potato_projectile/type/apple.json new file mode 100644 index 0000000000..f2ccca1d80 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/apple.json @@ -0,0 +1,10 @@ +{ + "damage": 5, + "items": "minecraft:apple", + "knockback": 0.5, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.1, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/baked_potato.json b/src/generated/resources/data/create/create/potato_projectile/type/baked_potato.json new file mode 100644 index 0000000000..fc4ac7dcdb --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/baked_potato.json @@ -0,0 +1,14 @@ +{ + "damage": 5, + "items": "minecraft:baked_potato", + "knockback": 0.5, + "pre_entity_hit": { + "type": "create:set_on_fire", + "ticks": 60 + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "velocity_multiplier": 1.25 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/beetroot.json b/src/generated/resources/data/create/create/potato_projectile/type/beetroot.json new file mode 100644 index 0000000000..973aa6bef4 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/beetroot.json @@ -0,0 +1,13 @@ +{ + "damage": 2, + "items": "minecraft:beetroot", + "knockback": 0.1, + "reload_ticks": 5, + "render_mode": { + "type": "create:toward_motion", + "spin": 2.0, + "sprite_angle_offset": 140 + }, + "sound_pitch": 1.6, + "velocity_multiplier": 1.6 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/blaze_cake.json b/src/generated/resources/data/create/create/potato_projectile/type/blaze_cake.json new file mode 100644 index 0000000000..825c465075 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/blaze_cake.json @@ -0,0 +1,15 @@ +{ + "damage": 15, + "items": "create:blaze_cake", + "knockback": 0.3, + "pre_entity_hit": { + "type": "create:set_on_fire", + "ticks": 240 + }, + "reload_ticks": 20, + "render_mode": { + "type": "create:tumble" + }, + "sticky": true, + "velocity_multiplier": 1.1 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/cake.json b/src/generated/resources/data/create/create/potato_projectile/type/cake.json new file mode 100644 index 0000000000..08abe4660c --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/cake.json @@ -0,0 +1,11 @@ +{ + "damage": 8, + "items": "minecraft:cake", + "knockback": 0.1, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "sticky": true, + "velocity_multiplier": 1.1 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/carrot.json b/src/generated/resources/data/create/create/potato_projectile/type/carrot.json new file mode 100644 index 0000000000..614582ce30 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/carrot.json @@ -0,0 +1,17 @@ +{ + "damage": 4, + "items": "minecraft:carrot", + "knockback": 0.3, + "on_entity_hit": { + "type": "create:plant_crop", + "block": "minecraft:carrots" + }, + "reload_ticks": 12, + "render_mode": { + "type": "create:toward_motion", + "spin": 1.0, + "sprite_angle_offset": 140 + }, + "sound_pitch": 1.5, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/chocolate_berry.json b/src/generated/resources/data/create/create/potato_projectile/type/chocolate_berry.json new file mode 100644 index 0000000000..028bed0e85 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/chocolate_berry.json @@ -0,0 +1,11 @@ +{ + "damage": 4, + "items": "create:chocolate_glazed_berries", + "knockback": 0.2, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.25, + "split": 3, + "velocity_multiplier": 1.05 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/chorus_fruit.json b/src/generated/resources/data/create/create/potato_projectile/type/chorus_fruit.json new file mode 100644 index 0000000000..bba651329a --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/chorus_fruit.json @@ -0,0 +1,14 @@ +{ + "damage": 3, + "items": "minecraft:chorus_fruit", + "knockback": 0.05, + "on_entity_hit": { + "type": "create:chorus_teleport", + "teleport_diameter": 20.0 + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "velocity_multiplier": 1.2 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/enchanted_golden_apple.json b/src/generated/resources/data/create/create/potato_projectile/type/enchanted_golden_apple.json new file mode 100644 index 0000000000..d3ad360bf2 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/enchanted_golden_apple.json @@ -0,0 +1,51 @@ +{ + "items": "minecraft:enchanted_golden_apple", + "knockback": 0.05, + "on_entity_hit": { + "type": "create:food_effects", + "food_property": { + "can_always_eat": true, + "effects": [ + { + "effect": { + "amplifier": 1, + "duration": 400, + "effect": "minecraft:regeneration" + }, + "probability": 1.0 + }, + { + "effect": { + "duration": 6000, + "effect": "minecraft:resistance" + }, + "probability": 1.0 + }, + { + "effect": { + "duration": 6000, + "effect": "minecraft:fire_resistance" + }, + "probability": 1.0 + }, + { + "effect": { + "amplifier": 3, + "duration": 2400, + "effect": "minecraft:absorption" + }, + "probability": 1.0 + } + ], + "nutrition": 4, + "saturation_modifier": 1.2 + }, + "recoverable": false + }, + "reload_ticks": 100, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.1, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/fallback.json b/src/generated/resources/data/create/create/potato_projectile/type/fallback.json new file mode 100644 index 0000000000..c67cae4213 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/fallback.json @@ -0,0 +1,4 @@ +{ + "damage": 0, + "items": [] +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/fish.json b/src/generated/resources/data/create/create/potato_projectile/type/fish.json new file mode 100644 index 0000000000..6a4a526b88 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/fish.json @@ -0,0 +1,19 @@ +{ + "damage": 4, + "items": [ + "minecraft:cod", + "minecraft:cooked_cod", + "minecraft:salmon", + "minecraft:cooked_salmon", + "minecraft:tropical_fish" + ], + "knockback": 0.6, + "render_mode": { + "type": "create:toward_motion", + "spin": 1.0, + "sprite_angle_offset": 140 + }, + "sound_pitch": 1.3, + "sticky": true, + "velocity_multiplier": 1.3 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/glistering_melon.json b/src/generated/resources/data/create/create/potato_projectile/type/glistering_melon.json new file mode 100644 index 0000000000..67ca2a18fb --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/glistering_melon.json @@ -0,0 +1,18 @@ +{ + "damage": 5, + "items": "minecraft:glistering_melon_slice", + "knockback": 0.1, + "on_entity_hit": { + "type": "create:potion_effect", + "effect": "minecraft:glowing", + "level": 1, + "recoverable": true, + "ticks": 100 + }, + "reload_ticks": 8, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.5, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/glow_berry.json b/src/generated/resources/data/create/create/potato_projectile/type/glow_berry.json new file mode 100644 index 0000000000..dfacc954b6 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/glow_berry.json @@ -0,0 +1,18 @@ +{ + "damage": 2, + "items": "minecraft:glow_berries", + "knockback": 0.05, + "on_entity_hit": { + "type": "create:potion_effect", + "effect": "minecraft:glowing", + "level": 1, + "recoverable": false, + "ticks": 200 + }, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.2, + "split": 2, + "velocity_multiplier": 1.05 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/golden_apple.json b/src/generated/resources/data/create/create/potato_projectile/type/golden_apple.json new file mode 100644 index 0000000000..d63dcc81aa --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/golden_apple.json @@ -0,0 +1,13 @@ +{ + "items": "minecraft:golden_apple", + "knockback": 0.05, + "on_entity_hit": { + "type": "create:cure_zombie_villager" + }, + "reload_ticks": 100, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.1, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/golden_carrot.json b/src/generated/resources/data/create/create/potato_projectile/type/golden_carrot.json new file mode 100644 index 0000000000..2c5f25450b --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/golden_carrot.json @@ -0,0 +1,13 @@ +{ + "damage": 12, + "items": "minecraft:golden_carrot", + "knockback": 0.5, + "reload_ticks": 15, + "render_mode": { + "type": "create:toward_motion", + "spin": 2.0, + "sprite_angle_offset": 140 + }, + "sound_pitch": 1.5, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/honeyed_apple.json b/src/generated/resources/data/create/create/potato_projectile/type/honeyed_apple.json new file mode 100644 index 0000000000..0e658c2187 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/honeyed_apple.json @@ -0,0 +1,18 @@ +{ + "damage": 6, + "items": "create:honeyed_apple", + "knockback": 0.1, + "on_entity_hit": { + "type": "create:potion_effect", + "effect": "minecraft:slowness", + "level": 2, + "recoverable": true, + "ticks": 160 + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.1, + "velocity_multiplier": 1.35 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/melon_block.json b/src/generated/resources/data/create/create/potato_projectile/type/melon_block.json new file mode 100644 index 0000000000..a6c23c53b3 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/melon_block.json @@ -0,0 +1,15 @@ +{ + "damage": 8, + "items": "minecraft:melon", + "knockback": 2.0, + "on_entity_hit": { + "type": "create:place_block_on_ground", + "block": "minecraft:melon" + }, + "reload_ticks": 20, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 0.9, + "velocity_multiplier": 0.95 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/melon_slice.json b/src/generated/resources/data/create/create/potato_projectile/type/melon_slice.json new file mode 100644 index 0000000000..42caeeac39 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/melon_slice.json @@ -0,0 +1,11 @@ +{ + "damage": 3, + "items": "minecraft:melon_slice", + "knockback": 0.1, + "reload_ticks": 8, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.5, + "velocity_multiplier": 1.45 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/poison_potato.json b/src/generated/resources/data/create/create/potato_projectile/type/poison_potato.json new file mode 100644 index 0000000000..d34bfb8c06 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/poison_potato.json @@ -0,0 +1,17 @@ +{ + "damage": 5, + "items": "minecraft:poisonous_potato", + "knockback": 0.05, + "on_entity_hit": { + "type": "create:potion_effect", + "effect": "minecraft:poison", + "level": 1, + "recoverable": true, + "ticks": 160 + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "velocity_multiplier": 1.25 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/potato.json b/src/generated/resources/data/create/create/potato_projectile/type/potato.json new file mode 100644 index 0000000000..8b91116f61 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/potato.json @@ -0,0 +1,14 @@ +{ + "damage": 5, + "items": "minecraft:potato", + "knockback": 1.5, + "on_entity_hit": { + "type": "create:plant_crop", + "block": "minecraft:potatoes" + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "velocity_multiplier": 1.25 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/pufferfish.json b/src/generated/resources/data/create/create/potato_projectile/type/pufferfish.json new file mode 100644 index 0000000000..649c29daf9 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/pufferfish.json @@ -0,0 +1,46 @@ +{ + "damage": 4, + "items": "minecraft:pufferfish", + "knockback": 0.4, + "on_entity_hit": { + "type": "create:food_effects", + "food_property": { + "effects": [ + { + "effect": { + "amplifier": 1, + "duration": 1200, + "effect": "minecraft:poison" + }, + "probability": 1.0 + }, + { + "effect": { + "amplifier": 2, + "duration": 300, + "effect": "minecraft:hunger" + }, + "probability": 1.0 + }, + { + "effect": { + "duration": 300, + "effect": "minecraft:nausea" + }, + "probability": 1.0 + } + ], + "nutrition": 1, + "saturation_modifier": 0.1 + }, + "recoverable": false + }, + "render_mode": { + "type": "create:toward_motion", + "spin": 1.0, + "sprite_angle_offset": 140 + }, + "sound_pitch": 1.1, + "sticky": true, + "velocity_multiplier": 1.1 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_block.json b/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_block.json new file mode 100644 index 0000000000..8f2e8a207f --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_block.json @@ -0,0 +1,15 @@ +{ + "damage": 6, + "items": "minecraft:pumpkin", + "knockback": 2.0, + "on_entity_hit": { + "type": "create:place_block_on_ground", + "block": "minecraft:pumpkin" + }, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 0.9, + "velocity_multiplier": 0.95 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_pie.json b/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_pie.json new file mode 100644 index 0000000000..9a92807e7a --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/pumpkin_pie.json @@ -0,0 +1,12 @@ +{ + "damage": 7, + "items": "minecraft:pumpkin_pie", + "knockback": 0.05, + "reload_ticks": 15, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.1, + "sticky": true, + "velocity_multiplier": 1.1 +} \ No newline at end of file diff --git a/src/generated/resources/data/create/create/potato_projectile/type/suspicious_stew.json b/src/generated/resources/data/create/create/potato_projectile/type/suspicious_stew.json new file mode 100644 index 0000000000..51086d1ea4 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/suspicious_stew.json @@ -0,0 +1,19 @@ +{ + "damage": 3, + "drop_stack": { + "Count": 1, + "id": "minecraft:bowl" + }, + "items": "minecraft:suspicious_stew", + "knockback": 0.2, + "on_entity_hit": { + "type": "create:suspicious_stew" + }, + "reload_ticks": 40, + "render_mode": { + "type": "create:toward_motion", + "spin": 1.0, + "sprite_angle_offset": 140 + }, + "velocity_multiplier": 0.8 +} diff --git a/src/generated/resources/data/create/create/potato_projectile/type/sweet_berry.json b/src/generated/resources/data/create/create/potato_projectile/type/sweet_berry.json new file mode 100644 index 0000000000..d065288124 --- /dev/null +++ b/src/generated/resources/data/create/create/potato_projectile/type/sweet_berry.json @@ -0,0 +1,11 @@ +{ + "damage": 3, + "items": "minecraft:sweet_berries", + "knockback": 0.1, + "render_mode": { + "type": "create:tumble" + }, + "sound_pitch": 1.25, + "split": 3, + "velocity_multiplier": 1.05 +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllPackets.java b/src/main/java/com/simibubi/create/AllPackets.java index 04a05d3100..5dc3a044e0 100644 --- a/src/main/java/com/simibubi/create/AllPackets.java +++ b/src/main/java/com/simibubi/create/AllPackets.java @@ -40,7 +40,6 @@ import com.simibubi.create.content.equipment.blueprint.BlueprintAssignCompleteRe import com.simibubi.create.content.equipment.clipboard.ClipboardEditPacket; import com.simibubi.create.content.equipment.extendoGrip.ExtendoGripInteractionPacket; import com.simibubi.create.content.equipment.potatoCannon.PotatoCannonPacket; -import com.simibubi.create.content.equipment.potatoCannon.PotatoProjectileTypeManager; import com.simibubi.create.content.equipment.symmetryWand.ConfigureSymmetryWandPacket; import com.simibubi.create.content.equipment.symmetryWand.SymmetryEffectPacket; import com.simibubi.create.content.equipment.tool.KnockbackPacket; @@ -190,7 +189,7 @@ public enum AllPackets { CONTRAPTION_COLLIDER_LOCK_REQUEST(ContraptionColliderLockPacketRequest.class, ContraptionColliderLockPacketRequest::new, PLAY_TO_SERVER), RADIAL_WRENCH_MENU_SUBMIT(RadialWrenchMenuSubmitPacket.class, RadialWrenchMenuSubmitPacket::new, - PLAY_TO_SERVER), + PLAY_TO_SERVER), LOGISTICS_STOCK_REQUEST(LogisticalStockRequestPacket.class, LogisticalStockRequestPacket::new, PLAY_TO_SERVER), LOGISTICS_PACKAGE_REQUEST(PackageOrderRequestPacket.class, PackageOrderRequestPacket::new, PLAY_TO_SERVER), CHAIN_CONVEYOR_CONNECT(ChainConveyorConnectionPacket.class, ChainConveyorConnectionPacket::new, PLAY_TO_SERVER), @@ -227,8 +226,6 @@ public enum AllPackets { SOUL_PULSE(SoulPulseEffectPacket.class, SoulPulseEffectPacket::new, PLAY_TO_CLIENT), PERSISTENT_DATA(ISyncPersistentData.PersistentDataPacket.class, ISyncPersistentData.PersistentDataPacket::new, PLAY_TO_CLIENT), - SYNC_POTATO_PROJECTILE_TYPES(PotatoProjectileTypeManager.SyncPacket.class, - PotatoProjectileTypeManager.SyncPacket::new, PLAY_TO_CLIENT), SYNC_RAIL_GRAPH(TrackGraphSyncPacket.class, TrackGraphSyncPacket::new, PLAY_TO_CLIENT), SYNC_EDGE_GROUP(SignalEdgeGroupPacket.class, SignalEdgeGroupPacket::new, PLAY_TO_CLIENT), SYNC_TRAIN(TrainPacket.class, TrainPacket::new, PLAY_TO_CLIENT), @@ -280,7 +277,7 @@ public enum AllPackets { private PacketType packetType; AllPackets(Class type, Function factory, - NetworkDirection direction) { + NetworkDirection direction) { packetType = new PacketType<>(type, factory, direction); } diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index ab13776bab..8e7244882f 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -12,7 +12,9 @@ import com.simibubi.create.compat.Mods; import com.simibubi.create.compat.computercraft.ComputerCraftProxy; import com.simibubi.create.compat.curios.Curios; import com.simibubi.create.content.decoration.palettes.AllPaletteBlocks; -import com.simibubi.create.content.equipment.potatoCannon.BuiltinPotatoProjectileTypes; +import com.simibubi.create.content.equipment.potatoCannon.AllPotatoProjectileBlockHitActions; +import com.simibubi.create.content.equipment.potatoCannon.AllPotatoProjectileEntityHitActions; +import com.simibubi.create.content.equipment.potatoCannon.AllPotatoProjectileRenderModes; import com.simibubi.create.content.fluids.tank.BoilerHeaters; import com.simibubi.create.content.kinetics.TorquePropagator; import com.simibubi.create.content.kinetics.fan.processing.AllFanProcessingTypes; @@ -56,6 +58,7 @@ import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.RegisterEvent; @Mod(Create.ID) public class Create { @@ -68,7 +71,9 @@ public class Create { .disableHtmlEscaping() .create(); - /** Use the {@link Random} of a local {@link Level} or {@link Entity} or create one */ + /** + * Use the {@link Random} of a local {@link Level} or {@link Entity} or create one + */ @Deprecated public static final Random RANDOM = new Random(); @@ -82,7 +87,7 @@ public class Create { static { REGISTRATE.setTooltipModifierFactory(item -> new ItemDescription.Modifier(item, FontHelper.Palette.STANDARD_CREATE) - .andThen(TooltipModifier.mapNull(KineticStats.create(item))) + .andThen(TooltipModifier.mapNull(KineticStats.create(item))) ); } @@ -132,6 +137,7 @@ public class Create { AllConfigs.register(modLoadingContext); + // TODO - Make these use Registry.register and move them into the RegisterEvent AllArmInteractionPointTypes.register(modEventBus); AllFanProcessingTypes.register(modEventBus); AllItemAttributeTypes.register(modEventBus); @@ -148,6 +154,7 @@ public class Create { CopperRegistries.inject(); modEventBus.addListener(Create::init); + modEventBus.addListener(Create::onRegister); modEventBus.addListener(AllEntityTypes::registerEntityAttributes); modEventBus.addListener(EventPriority.LOWEST, CreateDatagen::gatherData); modEventBus.addListener(AllSoundEvents::register); @@ -166,7 +173,6 @@ public class Create { // TODO: custom registration should all happen in one place // Most registration happens in the constructor. // These registrations use Create's registered objects directly so they must run after registration has finished. - BuiltinPotatoProjectileTypes.register(); BoilerHeaters.registerDefaults(); AllPortalTracks.registerDefaults(); BlockSpoutingBehaviour.registerDefaults(); @@ -182,6 +188,12 @@ public class Create { }); } + public static void onRegister(final RegisterEvent event) { + AllPotatoProjectileRenderModes.init(); + AllPotatoProjectileEntityHitActions.init(); + AllPotatoProjectileBlockHitActions.init(); + } + public static LangBuilder lang() { return new LangBuilder(ID); } diff --git a/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoCannonProjectileType.java b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoCannonProjectileType.java new file mode 100644 index 0000000000..6e293bd68c --- /dev/null +++ b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoCannonProjectileType.java @@ -0,0 +1,230 @@ +package com.simibubi.create.api.equipment.potatoCannon; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.jetbrains.annotations.Nullable; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.Type; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.Billboard; +import com.simibubi.create.api.registry.CreateRegistries; + +import net.minecraft.core.Holder; +import net.minecraft.core.Holder.Reference; +import net.minecraft.core.HolderSet; +import net.minecraft.core.RegistryCodecs; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; + +public record PotatoCannonProjectileType(HolderSet items, int reloadTicks, int damage, int split, float knockback, + float drag, float velocityMultiplier, float gravityMultiplier, + float soundPitch, boolean sticky, ItemStack dropStack, + PotatoProjectileRenderMode renderMode, + Optional preEntityHit, + Optional onEntityHit, + Optional onBlockHit) { + public static final Codec CODEC = RecordCodecBuilder.create(i -> i.group( + RegistryCodecs.homogeneousList(Registries.ITEM).fieldOf("items").forGetter(PotatoCannonProjectileType::items), + Codec.INT.optionalFieldOf("reload_ticks", 10).forGetter(PotatoCannonProjectileType::reloadTicks), + Codec.INT.optionalFieldOf("damage", 1).forGetter(PotatoCannonProjectileType::damage), + Codec.INT.optionalFieldOf("split", 1).forGetter(PotatoCannonProjectileType::split), + Codec.FLOAT.optionalFieldOf("knockback", 1f).forGetter(PotatoCannonProjectileType::knockback), + Codec.FLOAT.optionalFieldOf("drag", .99f).forGetter(PotatoCannonProjectileType::drag), + Codec.FLOAT.optionalFieldOf("velocity_multiplier", 1f).forGetter(PotatoCannonProjectileType::velocityMultiplier), + Codec.FLOAT.optionalFieldOf("gravity_multiplier", 1f).forGetter(PotatoCannonProjectileType::gravityMultiplier), + Codec.FLOAT.optionalFieldOf("sound_pitch", 1f).forGetter(PotatoCannonProjectileType::soundPitch), + Codec.BOOL.optionalFieldOf("sticky", false).forGetter(PotatoCannonProjectileType::sticky), + ItemStack.CODEC.optionalFieldOf("drop_stack", ItemStack.EMPTY).forGetter(PotatoCannonProjectileType::dropStack), + PotatoProjectileRenderMode.CODEC.optionalFieldOf("render_mode", Billboard.INSTANCE).forGetter(PotatoCannonProjectileType::renderMode), + PotatoProjectileEntityHitAction.CODEC.optionalFieldOf("pre_entity_hit").forGetter(p -> p.preEntityHit), + PotatoProjectileEntityHitAction.CODEC.optionalFieldOf("on_entity_hit").forGetter(p -> p.onEntityHit), + PotatoProjectileBlockHitAction.CODEC.optionalFieldOf("on_entity_hit").forGetter(p -> p.onBlockHit) + ).apply(i, PotatoCannonProjectileType::new)); + + @Nullable + public static PotatoCannonProjectileType getTypeForItem(Level level, Item item) { + // Cache this if it causes performance issues, but it probably won't + List types = level.registryAccess() + .lookupOrThrow(CreateRegistries.POTATO_PROJECTILE_TYPE) + .listElements() + .map(Reference::value) + .toList(); + + for (PotatoCannonProjectileType type : types) + if (type.items.contains(item.builtInRegistryHolder())) + return type; + + return null; + } + + public static Optional getTypeForStack(Level level, ItemStack item) { + if (item.isEmpty()) + return Optional.empty(); + return Optional.ofNullable(getTypeForItem(level, item.getItem())); + } + + public boolean preEntityHit(ItemStack stack, EntityHitResult ray) { + return preEntityHit.map(i -> i.execute(stack, ray, Type.PRE_HIT)).orElse(false); + } + + public boolean onEntityHit(ItemStack stack, EntityHitResult ray) { + return onEntityHit.map(i -> i.execute(stack, ray, Type.ON_HIT)).orElse(false); + } + + public boolean onBlockHit(LevelAccessor level, ItemStack stack, BlockHitResult ray) { + return onBlockHit.map(i -> i.execute(level, stack, ray)).orElse(false); + } + + public static class Builder { + private ResourceLocation id; + + private final List> items = new ArrayList<>(); + private int reloadTicks = 10; + private int damage = 1; + private int split = 1; + private float knockback = 1f; + private float drag = 0.99f; + private float velocityMultiplier = 1f; + private float gravityMultiplier = 1f; + private float soundPitch = 1f; + private boolean sticky = false; + private ItemStack dropStack = ItemStack.EMPTY; + private PotatoProjectileRenderMode renderMode = Billboard.INSTANCE; + private PotatoProjectileEntityHitAction preEntityHit = null; + private PotatoProjectileEntityHitAction onEntityHit = null; + private PotatoProjectileBlockHitAction onBlockHit = null; + + public Builder(ResourceLocation id) { + this.id = id; + } + + public Builder reloadTicks(int reload) { + this.reloadTicks = reload; + return this; + } + + public Builder damage(int damage) { + this.damage = damage; + return this; + } + + public Builder splitInto(int split) { + this.split = split; + return this; + } + + public Builder knockback(float knockback) { + this.knockback = knockback; + return this; + } + + public Builder drag(float drag) { + this.drag = drag; + return this; + } + + public Builder velocity(float velocity) { + this.velocityMultiplier = velocity; + return this; + } + + public Builder gravity(float modifier) { + this.gravityMultiplier = modifier; + return this; + } + + public Builder soundPitch(float pitch) { + this.soundPitch = pitch; + return this; + } + + public Builder sticky() { + this.sticky = true; + return this; + } + + public Builder dropStack(ItemStack stack) { + this.dropStack = stack; + return this; + } + + public Builder renderMode(PotatoProjectileRenderMode renderMode) { + this.renderMode = renderMode; + return this; + } + + public Builder renderBillboard() { + renderMode(PotatoProjectileRenderMode.Billboard.INSTANCE); + return this; + } + + public Builder renderTumbling() { + renderMode(PotatoProjectileRenderMode.Tumble.INSTANCE); + return this; + } + + public Builder renderTowardMotion(int spriteAngle, float spin) { + renderMode(new PotatoProjectileRenderMode.TowardMotion(spriteAngle, spin)); + return this; + } + + public Builder preEntityHit(PotatoProjectileEntityHitAction entityHitAction) { + this.preEntityHit = entityHitAction; + return this; + } + + public Builder onEntityHit(PotatoProjectileEntityHitAction entityHitAction) { + this.onEntityHit = entityHitAction; + return this; + } + + public Builder onBlockHit(PotatoProjectileBlockHitAction blockHitAction) { + this.onBlockHit = blockHitAction; + return this; + } + + public Builder addItems(ItemLike... items) { + for (ItemLike provider : items) + this.items.add(provider.asItem().builtInRegistryHolder()); + return this; + } + + public void register(BootstapContext ctx) { + PotatoCannonProjectileType type = new PotatoCannonProjectileType( + HolderSet.direct(items), + reloadTicks, + damage, + split, + knockback, + drag, + velocityMultiplier, + gravityMultiplier, + soundPitch, + sticky, + dropStack, + renderMode, + Optional.ofNullable(preEntityHit), + Optional.ofNullable(onEntityHit), + Optional.ofNullable(onBlockHit) + ); + ctx.register(ResourceKey.create(CreateRegistries.POTATO_PROJECTILE_TYPE, id), type); + } + + public void registerAndAssign(BootstapContext ctx, ItemLike... items) { + addItems(items); + register(ctx); + } + } +} diff --git a/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileBlockHitAction.java b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileBlockHitAction.java new file mode 100644 index 0000000000..87a003a057 --- /dev/null +++ b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileBlockHitAction.java @@ -0,0 +1,120 @@ +package com.simibubi.create.api.equipment.potatoCannon; + +import java.util.function.Function; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; +import com.simibubi.create.foundation.mixin.accessor.FallingBlockEntityAccessor; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; + +import net.minecraftforge.common.IPlantable; +import net.minecraftforge.registries.ForgeRegistries; + +public interface PotatoProjectileBlockHitAction { + Codec CODEC = CreateBuiltInRegistries.POTATO_PROJECTILE_BLOCK_HIT_ACTION.byNameCodec() + .dispatch(PotatoProjectileBlockHitAction::codec, Function.identity()); + + boolean execute(LevelAccessor level, ItemStack projectile, BlockHitResult ray); + + Codec codec(); + + record PlantCrop(Holder cropBlock) implements PotatoProjectileBlockHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + BuiltInRegistries.BLOCK.holderByNameCodec().fieldOf("block").forGetter(PlantCrop::cropBlock) + ).apply(instance, PlantCrop::new)); + + public PlantCrop(Block cropBlock) { + this(ForgeRegistries.BLOCKS.getDelegateOrThrow(cropBlock)); + } + + @Override + public boolean execute(LevelAccessor level, ItemStack projectile, BlockHitResult ray) { + if (level.isClientSide()) + return true; + + BlockPos hitPos = ray.getBlockPos(); + if (level instanceof Level l && !l.isLoaded(hitPos)) + return true; + Direction face = ray.getDirection(); + if (face != Direction.UP) + return false; + BlockPos placePos = hitPos.relative(face); + if (!level.getBlockState(placePos) + .canBeReplaced()) + return false; + if (!(cropBlock.get() instanceof IPlantable)) + return false; + BlockState blockState = level.getBlockState(hitPos); + if (!blockState.canSustainPlant(level, hitPos, face, (IPlantable) cropBlock.get())) + return false; + level.setBlock(placePos, cropBlock.get() + .defaultBlockState(), 3); + return true; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + record PlaceBlockOnGround(Holder block) implements PotatoProjectileBlockHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + BuiltInRegistries.BLOCK.holderByNameCodec().fieldOf("block").forGetter(PlaceBlockOnGround::block) + ).apply(instance, PlaceBlockOnGround::new)); + + public PlaceBlockOnGround(Block block) { + this(ForgeRegistries.BLOCKS.getDelegateOrThrow(block)); + } + + @Override + public boolean execute(LevelAccessor levelAccessor, ItemStack projectile, BlockHitResult ray) { + if (levelAccessor.isClientSide()) + return true; + + BlockPos hitPos = ray.getBlockPos(); + if (levelAccessor instanceof Level l && !l.isLoaded(hitPos)) + return true; + Direction face = ray.getDirection(); + BlockPos placePos = hitPos.relative(face); + if (!levelAccessor.getBlockState(placePos) + .canBeReplaced()) + return false; + + if (face == Direction.UP) { + levelAccessor.setBlock(placePos, block.value() + .defaultBlockState(), 3); + } else if (levelAccessor instanceof Level level) { + double y = ray.getLocation().y - 0.5; + if (!level.isEmptyBlock(placePos.above())) + y = Math.min(y, placePos.getY()); + if (!level.isEmptyBlock(placePos.below())) + y = Math.max(y, placePos.getY()); + + FallingBlockEntity falling = FallingBlockEntityAccessor.create$callInit(level, placePos.getX() + 0.5, y, + placePos.getZ() + 0.5, block.get().defaultBlockState()); + falling.time = 1; + level.addFreshEntity(falling); + } + + return true; + } + + @Override + public Codec codec() { + return CODEC; + } + } +} diff --git a/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileEntityHitAction.java b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileEntityHitAction.java new file mode 100644 index 0000000000..b174de8a08 --- /dev/null +++ b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileEntityHitAction.java @@ -0,0 +1,245 @@ +package com.simibubi.create.api.equipment.potatoCannon; + +import java.util.UUID; +import java.util.function.Function; + +import com.mojang.authlib.GameProfile; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; +import com.simibubi.create.foundation.mixin.accessor.SuspiciousStewItemAccessor; +import com.simibubi.create.foundation.utility.CreateCodecs; + +import net.createmod.catnip.data.WorldAttached; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.entity.monster.ZombieVillager; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.food.Foods; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.Vec3; + +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.entity.EntityTeleportEvent; + +public interface PotatoProjectileEntityHitAction { + Codec CODEC = CreateBuiltInRegistries.POTATO_PROJECTILE_ENTITY_HIT_ACTION.byNameCodec() + .dispatch(PotatoProjectileEntityHitAction::codec, Function.identity()); + + enum Type { + PRE_HIT, + ON_HIT + } + + /** + * @return true if the hit should be canceled if the type is {@link Type#PRE_HIT PRE_HIT}, + * true if this shouldn't recover the projectile if the type is {@link Type#ON_HIT ON_HIT} + */ + boolean execute(ItemStack projectile, EntityHitResult ray, Type type); + + Codec codec(); + + record SetOnFire(int ticks) implements PotatoProjectileEntityHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.POSITIVE_INT.fieldOf("ticks").forGetter(SetOnFire::ticks) + ).apply(instance, SetOnFire::new)); + + public static SetOnFire seconds(int seconds) { + return new SetOnFire(seconds * 20); + } + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + ray.getEntity() + .setRemainingFireTicks(ticks); + return false; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + record PotionEffect(MobEffect effect, int level, int ticks, + boolean recoverable) implements PotatoProjectileEntityHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + BuiltInRegistries.MOB_EFFECT.byNameCodec().fieldOf("effect").forGetter(PotionEffect::effect), + ExtraCodecs.POSITIVE_INT.fieldOf("level").forGetter(PotionEffect::level), + ExtraCodecs.POSITIVE_INT.fieldOf("ticks").forGetter(PotionEffect::ticks), + Codec.BOOL.fieldOf("recoverable").forGetter(PotionEffect::recoverable) + ).apply(instance, PotionEffect::new)); + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + Entity entity = ray.getEntity(); + if (entity.level().isClientSide) + return true; + if (entity instanceof LivingEntity) + applyEffect((LivingEntity) entity, new MobEffectInstance(effect, ticks, level - 1)); + return !recoverable; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + record FoodEffects(FoodProperties foodProperty, boolean recoverable) implements PotatoProjectileEntityHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + CreateCodecs.FOOD_PROPERTIES.fieldOf("food_property").forGetter(FoodEffects::foodProperty), + Codec.BOOL.fieldOf("recoverable").forGetter(FoodEffects::recoverable) + ).apply(instance, FoodEffects::new)); + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + Entity entity = ray.getEntity(); + if (entity.level().isClientSide) + return true; + + if (entity instanceof LivingEntity livingEntity) { + for (Pair effect : foodProperty.getEffects()) { + if (livingEntity.getRandom().nextFloat() < effect.getSecond()) + applyEffect(livingEntity, new MobEffectInstance(effect.getFirst())); + } + } + return !recoverable; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + record ChorusTeleport(double teleportDiameter) implements PotatoProjectileEntityHitAction { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + CreateCodecs.POSITIVE_DOUBLE.fieldOf("teleport_diameter").forGetter(ChorusTeleport::teleportDiameter) + ).apply(instance, ChorusTeleport::new)); + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + Entity entity = ray.getEntity(); + Level level = entity.getCommandSenderWorld(); + if (level.isClientSide) + return true; + if (!(entity instanceof LivingEntity livingEntity)) + return false; + + double entityX = livingEntity.getX(); + double entityY = livingEntity.getY(); + double entityZ = livingEntity.getZ(); + + for (int teleportTry = 0; teleportTry < 16; ++teleportTry) { + double teleportX = entityX + (livingEntity.getRandom() + .nextDouble() - 0.5D) * teleportDiameter; + double teleportY = Mth.clamp(entityY + (livingEntity.getRandom() + .nextInt((int) teleportDiameter) - (int) (teleportDiameter / 2)), 0.0D, level.getHeight() - 1); + double teleportZ = entityZ + (livingEntity.getRandom() + .nextDouble() - 0.5D) * teleportDiameter; + + EntityTeleportEvent.ChorusFruit event = + ForgeEventFactory.onChorusFruitTeleport(livingEntity, teleportX, teleportY, teleportZ); + if (event.isCanceled()) + return false; + if (livingEntity.randomTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ(), true)) { + if (livingEntity.isPassenger()) + livingEntity.stopRiding(); + + SoundEvent soundevent = + livingEntity instanceof Fox ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT; + level.playSound(null, entityX, entityY, entityZ, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F); + livingEntity.playSound(soundevent, 1.0F, 1.0F); + livingEntity.setDeltaMovement(Vec3.ZERO); + return true; + } + } + + return false; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + enum CureZombieVillager implements PotatoProjectileEntityHitAction { + INSTANCE; + + private static final FoodEffects EFFECT = new FoodEffects(Foods.GOLDEN_APPLE, false); + private static final GameProfile ZOMBIE_CONVERTER_NAME = + new GameProfile(UUID.fromString("be12d3dc-27d3-4992-8c97-66be53fd49c5"), "Converter"); + private static final WorldAttached ZOMBIE_CONVERTERS = + new WorldAttached<>(w -> new FakePlayer((ServerLevel) w, ZOMBIE_CONVERTER_NAME)); + + public static final Codec CODEC = Codec.unit(INSTANCE); + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + Entity entity = ray.getEntity(); + Level world = entity.level(); + + if (!(entity instanceof ZombieVillager zombieVillager) || !zombieVillager.hasEffect(MobEffects.WEAKNESS)) + return EFFECT.execute(projectile, ray, type); + if (world.isClientSide) + return false; + + FakePlayer dummy = ZOMBIE_CONVERTERS.get(world); + dummy.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.GOLDEN_APPLE, 1)); + zombieVillager.mobInteract(dummy, InteractionHand.MAIN_HAND); + return true; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + enum SuspiciousStew implements PotatoProjectileEntityHitAction { + INSTANCE; + + public static final Codec CODEC = Codec.unit(INSTANCE); + + @Override + public boolean execute(ItemStack projectile, EntityHitResult ray, Type type) { + if (ray.getEntity() instanceof LivingEntity livingEntity) + SuspiciousStewItemAccessor.create$listPotionEffects(projectile, livingEntity::addEffect); + + return true; + } + + @Override + public Codec codec() { + return CODEC; + } + } + + private static void applyEffect(LivingEntity entity, MobEffectInstance effect) { + if (effect.getEffect().isInstantenous()) { + effect.getEffect() + .applyInstantenousEffect(null, null, entity, effect.getDuration(), 1.0); + } else { + entity.addEffect(effect); + } + } +} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileRenderMode.java b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileRenderMode.java similarity index 51% rename from src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileRenderMode.java rename to src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileRenderMode.java index cd3380d63b..19af90a785 100644 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileRenderMode.java +++ b/src/main/java/com/simibubi/create/api/equipment/potatoCannon/PotatoProjectileRenderMode.java @@ -1,8 +1,14 @@ -package com.simibubi.create.content.equipment.potatoCannon; +package com.simibubi.create.api.equipment.potatoCannon; -import static com.simibubi.create.content.equipment.potatoCannon.PotatoProjectileRenderMode.entityRandom; +import static com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.entityRandom; + +import java.util.function.Function; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; +import com.simibubi.create.content.equipment.potatoCannon.PotatoProjectileEntity; import dev.engine_room.flywheel.lib.transform.TransformStack; import net.createmod.catnip.math.AngleHelper; @@ -10,17 +16,23 @@ import net.minecraft.client.Minecraft; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.phys.Vec3; + import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; public interface PotatoProjectileRenderMode { + Codec CODEC = CreateBuiltInRegistries.POTATO_PROJECTILE_RENDER_MODE.byNameCodec() + .dispatch(PotatoProjectileRenderMode::codec, Function.identity()); @OnlyIn(Dist.CLIENT) void transform(PoseStack ms, PotatoProjectileEntity entity, float pt); - public static class Billboard implements PotatoProjectileRenderMode { + Codec codec(); - public static final Billboard INSTANCE = new Billboard(); + enum Billboard implements PotatoProjectileRenderMode { + INSTANCE; + + public static final Codec CODEC = Codec.unit(INSTANCE); @Override @OnlyIn(Dist.CLIENT) @@ -37,32 +49,37 @@ public interface PotatoProjectileRenderMode { .rotateXDegrees(AngleHelper.deg(Mth.atan2(diff.y, Mth.sqrt((float) (diff.x * diff.x + diff.z * diff.z))))); } + @Override + public Codec codec() { + return CODEC; + } } - public static class Tumble extends Billboard { + enum Tumble implements PotatoProjectileRenderMode { + INSTANCE; - public static final Tumble INSTANCE = new Tumble(); + public static final Codec CODEC = Codec.unit(INSTANCE); @Override @OnlyIn(Dist.CLIENT) public void transform(PoseStack ms, PotatoProjectileEntity entity, float pt) { - super.transform(ms, entity, pt); + Billboard.INSTANCE.transform(ms, entity, pt); TransformStack.of(ms) .rotateZDegrees((entity.tickCount + pt) * 2 * entityRandom(entity, 16)) .rotateXDegrees((entity.tickCount + pt) * entityRandom(entity, 32)); } + @Override + public Codec codec() { + return CODEC; + } } - public static class TowardMotion implements PotatoProjectileRenderMode { - - private int spriteAngleOffset; - private float spin; - - public TowardMotion(int spriteAngleOffset, float spin) { - this.spriteAngleOffset = spriteAngleOffset; - this.spin = spin; - } + record TowardMotion(int spriteAngleOffset, float spin) implements PotatoProjectileRenderMode { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.fieldOf("sprite_angle_offset").forGetter(i -> i.spriteAngleOffset), + Codec.FLOAT.fieldOf("spin").forGetter(i -> i.spin) + ).apply(instance, TowardMotion::new)); @Override @OnlyIn(Dist.CLIENT) @@ -77,15 +94,16 @@ public interface PotatoProjectileRenderMode { .rotateZDegrees(-spriteAngleOffset); } + @Override + public Codec codec() { + return CODEC; + } } - public static class StuckToEntity implements PotatoProjectileRenderMode { - - private Vec3 offset; - - public StuckToEntity(Vec3 offset) { - this.offset = offset; - } + record StuckToEntity(Vec3 offset) implements PotatoProjectileRenderMode { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Vec3.CODEC.fieldOf("offset").forGetter(i -> i.offset) + ).apply(instance, StuckToEntity::new)); @Override @OnlyIn(Dist.CLIENT) @@ -93,10 +111,13 @@ public interface PotatoProjectileRenderMode { TransformStack.of(ms).rotateYDegrees(AngleHelper.deg(Mth.atan2(offset.x, offset.z))); } + @Override + public Codec codec() { + return CODEC; + } } - public static int entityRandom(Entity entity, int maxValue) { + static int entityRandom(Entity entity, int maxValue) { return (System.identityHashCode(entity) * 31) % maxValue; } - } diff --git a/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java b/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java index 8e75692974..57039384c8 100644 --- a/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java +++ b/src/main/java/com/simibubi/create/api/registry/CreateBuiltInRegistries.java @@ -2,12 +2,16 @@ package com.simibubi.create.api.registry; import org.jetbrains.annotations.ApiStatus; +import com.mojang.serialization.Codec; import com.mojang.serialization.Lifecycle; import com.simibubi.create.api.behaviour.display.DisplaySource; import com.simibubi.create.api.behaviour.display.DisplayTarget; import com.simibubi.create.api.contraption.ContraptionType; import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageType; import com.simibubi.create.api.contraption.storage.item.MountedItemStorageType; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode; import com.simibubi.create.content.kinetics.fan.processing.FanProcessingType; import com.simibubi.create.content.kinetics.mechanicalArm.ArmInteractionPointType; import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType; @@ -32,6 +36,9 @@ public class CreateBuiltInRegistries { public static final Registry> MOUNTED_ITEM_STORAGE_TYPE = withIntrusiveHolders(CreateRegistries.MOUNTED_ITEM_STORAGE_TYPE); public static final Registry> MOUNTED_FLUID_STORAGE_TYPE = simple(CreateRegistries.MOUNTED_FLUID_STORAGE_TYPE); public static final Registry CONTRAPTION_TYPE = withIntrusiveHolders(CreateRegistries.CONTRAPTION_TYPE); + public static final Registry> POTATO_PROJECTILE_RENDER_MODE = simple(CreateRegistries.POTATO_PROJECTILE_RENDER_MODE); + public static final Registry> POTATO_PROJECTILE_ENTITY_HIT_ACTION = simple(CreateRegistries.POTATO_PROJECTILE_ENTITY_HIT_ACTION); + public static final Registry> POTATO_PROJECTILE_BLOCK_HIT_ACTION = simple(CreateRegistries.POTATO_PROJECTILE_BLOCK_HIT_ACTION); private static Registry simple(ResourceKey> key) { return register(key, new MappedRegistry<>(key, Lifecycle.stable(), false)); diff --git a/src/main/java/com/simibubi/create/api/registry/CreateRegistries.java b/src/main/java/com/simibubi/create/api/registry/CreateRegistries.java index ed09edcd34..981255389c 100644 --- a/src/main/java/com/simibubi/create/api/registry/CreateRegistries.java +++ b/src/main/java/com/simibubi/create/api/registry/CreateRegistries.java @@ -1,11 +1,18 @@ package com.simibubi.create.api.registry; +import org.jetbrains.annotations.ApiStatus.Internal; + +import com.mojang.serialization.Codec; import com.simibubi.create.Create; import com.simibubi.create.api.behaviour.display.DisplaySource; import com.simibubi.create.api.behaviour.display.DisplayTarget; import com.simibubi.create.api.contraption.ContraptionType; import com.simibubi.create.api.contraption.storage.fluid.MountedFluidStorageType; import com.simibubi.create.api.contraption.storage.item.MountedItemStorageType; +import com.simibubi.create.api.equipment.potatoCannon.PotatoCannonProjectileType; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode; import com.simibubi.create.content.kinetics.fan.processing.FanProcessingType; import com.simibubi.create.content.kinetics.mechanicalArm.ArmInteractionPointType; import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttributeType; @@ -13,10 +20,17 @@ import com.simibubi.create.content.logistics.item.filter.attribute.ItemAttribute import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.registries.DataPackRegistryEvent; + /** * Keys for registries added by Create. + * * @see CreateBuiltInRegistries */ +@EventBusSubscriber(bus = Bus.MOD) public class CreateRegistries { public static final ResourceKey> ARM_INTERACTION_POINT_TYPE = key("arm_interaction_point_type"); public static final ResourceKey> FAN_PROCESSING_TYPE = key("fan_processing_type"); @@ -26,8 +40,22 @@ public class CreateRegistries { public static final ResourceKey>> MOUNTED_ITEM_STORAGE_TYPE = key("mounted_item_storage_type"); public static final ResourceKey>> MOUNTED_FLUID_STORAGE_TYPE = key("mounted_fluid_storage_type"); public static final ResourceKey> CONTRAPTION_TYPE = key("contraption_type"); + public static final ResourceKey> POTATO_PROJECTILE_TYPE = key("potato_projectile/type"); + public static final ResourceKey>> POTATO_PROJECTILE_RENDER_MODE = key("potato_projectile/render_mode"); + public static final ResourceKey>> POTATO_PROJECTILE_ENTITY_HIT_ACTION = key("potato_projectile/entity_hit_action"); + public static final ResourceKey>> POTATO_PROJECTILE_BLOCK_HIT_ACTION = key("potato_projectile/block_hit_action"); private static ResourceKey> key(String name) { return ResourceKey.createRegistryKey(Create.asResource(name)); } + + @Internal + @SubscribeEvent + public static void registerDatapackRegistries(DataPackRegistryEvent.NewRegistry event) { + event.dataPackRegistry( + POTATO_PROJECTILE_TYPE, + PotatoCannonProjectileType.CODEC, + PotatoCannonProjectileType.CODEC + ); + } } diff --git a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java b/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java index 4873ba0976..39784615ac 100644 --- a/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/extendoGrip/ExtendoGripItem.java @@ -245,6 +245,7 @@ public class ExtendoGripItem extends Item { if (lastActiveDamageSource == null) return; Entity entity = lastActiveDamageSource.getDirectEntity(); + lastActiveDamageSource = null; if (!(entity instanceof Player player)) return; if (!isHoldingExtendoGrip(player)) diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileBlockHitActions.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileBlockHitActions.java new file mode 100644 index 0000000000..2c0fc96006 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileBlockHitActions.java @@ -0,0 +1,21 @@ +package com.simibubi.create.content.equipment.potatoCannon; + +import com.mojang.serialization.Codec; +import com.simibubi.create.Create; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction.PlaceBlockOnGround; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction.PlantCrop; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; + +import net.minecraft.core.Registry; + +public class AllPotatoProjectileBlockHitActions { + public static void init() { + register("plant_crop", PlantCrop.CODEC); + register("place_block_on_ground", PlaceBlockOnGround.CODEC); + } + + private static void register(String name, Codec codec) { + Registry.register(CreateBuiltInRegistries.POTATO_PROJECTILE_BLOCK_HIT_ACTION, Create.asResource(name), codec); + } +} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileEntityHitActions.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileEntityHitActions.java new file mode 100644 index 0000000000..90232dd90e --- /dev/null +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileEntityHitActions.java @@ -0,0 +1,29 @@ +package com.simibubi.create.content.equipment.potatoCannon; + +import com.mojang.serialization.Codec; +import com.simibubi.create.Create; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.ChorusTeleport; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.CureZombieVillager; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.FoodEffects; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.PotionEffect; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.SetOnFire; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.SuspiciousStew; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; + +import net.minecraft.core.Registry; + +public class AllPotatoProjectileEntityHitActions { + public static void init() { + register("set_on_fire", SetOnFire.CODEC); + register("potion_effect", PotionEffect.CODEC); + register("food_effects", FoodEffects.CODEC); + register("chorus_teleport", ChorusTeleport.CODEC); + register("cure_zombie_villager", CureZombieVillager.CODEC); + register("suspicious_stew", SuspiciousStew.CODEC); + } + + private static void register(String name, Codec codec) { + Registry.register(CreateBuiltInRegistries.POTATO_PROJECTILE_ENTITY_HIT_ACTION, Create.asResource(name), codec); + } +} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileRenderModes.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileRenderModes.java new file mode 100644 index 0000000000..331ea6f09f --- /dev/null +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileRenderModes.java @@ -0,0 +1,25 @@ +package com.simibubi.create.content.equipment.potatoCannon; + +import com.mojang.serialization.Codec; +import com.simibubi.create.Create; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.Billboard; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.StuckToEntity; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.TowardMotion; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode.Tumble; +import com.simibubi.create.api.registry.CreateBuiltInRegistries; + +import net.minecraft.core.Registry; + +public class AllPotatoProjectileRenderModes { + public static void init() { + register("billboard", Billboard.CODEC); + register("tumble", Tumble.CODEC); + register("toward_motion", TowardMotion.CODEC); + register("stuck_to_entity", StuckToEntity.CODEC); + } + + private static void register(String name, Codec codec) { + Registry.register(CreateBuiltInRegistries.POTATO_PROJECTILE_RENDER_MODE, Create.asResource(name), codec); + } +} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileTypes.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileTypes.java new file mode 100644 index 0000000000..38e1d1130f --- /dev/null +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/AllPotatoProjectileTypes.java @@ -0,0 +1,266 @@ +package com.simibubi.create.content.equipment.potatoCannon; + +import com.simibubi.create.AllItems; +import com.simibubi.create.Create; +import com.simibubi.create.api.equipment.potatoCannon.PotatoCannonProjectileType; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction.PlaceBlockOnGround; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileBlockHitAction.PlantCrop; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.ChorusTeleport; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.CureZombieVillager; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.FoodEffects; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.PotionEffect; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.SetOnFire; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileEntityHitAction.SuspiciousStew; +import com.simibubi.create.api.registry.CreateRegistries; + +import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.food.Foods; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; + +public class AllPotatoProjectileTypes { + public static ResourceKey FALLBACK = ResourceKey.create(CreateRegistries.POTATO_PROJECTILE_TYPE, Create.asResource("fallback")); + + public static void bootstrap(BootstapContext ctx) { + create("fallback") + .damage(0) + .register(ctx); + + create("potato") + .damage(5) + .reloadTicks(15) + .velocity(1.25f) + .knockback(1.5f) + .renderTumbling() + .onBlockHit(new PlantCrop(Blocks.POTATOES)) + .registerAndAssign(ctx, Items.POTATO); + + create("baked_potato") + .damage(5) + .reloadTicks(15) + .velocity(1.25f) + .knockback(0.5f) + .renderTumbling() + .preEntityHit(SetOnFire.seconds(3)) + .registerAndAssign(ctx, Items.BAKED_POTATO); + + create("carrot") + .damage(4) + .reloadTicks(12) + .velocity(1.45f) + .knockback(0.3f) + .renderTowardMotion(140, 1) + .soundPitch(1.5f) + .onBlockHit(new PlantCrop(Blocks.CARROTS)) + .registerAndAssign(ctx, Items.CARROT); + + create("golden_carrot") + .damage(12) + .reloadTicks(15) + .velocity(1.45f) + .knockback(0.5f) + .renderTowardMotion(140, 2) + .soundPitch(1.5f) + .registerAndAssign(ctx, Items.GOLDEN_CARROT); + + create("sweet_berry") + .damage(3) + .reloadTicks(10) + .knockback(0.1f) + .velocity(1.05f) + .renderTumbling() + .splitInto(3) + .soundPitch(1.25f) + .registerAndAssign(ctx, Items.SWEET_BERRIES); + + create("glow_berry") + .damage(2) + .reloadTicks(10) + .knockback(0.05f) + .velocity(1.05f) + .renderTumbling() + .splitInto(2) + .soundPitch(1.2f) + .onEntityHit(new PotionEffect(MobEffects.GLOWING, 1, 200, false)) + .registerAndAssign(ctx, Items.GLOW_BERRIES); + + create("chocolate_berry") + .damage(4) + .reloadTicks(10) + .knockback(0.2f) + .velocity(1.05f) + .renderTumbling() + .splitInto(3) + .soundPitch(1.25f) + .registerAndAssign(ctx, AllItems.CHOCOLATE_BERRIES.get()); + + create("poison_potato") + .damage(5) + .reloadTicks(15) + .knockback(0.05f) + .velocity(1.25f) + .renderTumbling() + .onEntityHit(new PotionEffect(MobEffects.POISON, 1, 160, true)) + .registerAndAssign(ctx, Items.POISONOUS_POTATO); + + create("chorus_fruit") + .damage(3) + .reloadTicks(15) + .velocity(1.20f) + .knockback(0.05f) + .renderTumbling() + .onEntityHit(new ChorusTeleport(20)) + .registerAndAssign(ctx, Items.CHORUS_FRUIT); + + create("apple") + .damage(5) + .reloadTicks(10) + .velocity(1.45f) + .knockback(0.5f) + .renderTumbling() + .soundPitch(1.1f) + .registerAndAssign(ctx, Items.APPLE); + + create("honeyed_apple") + .damage(6) + .reloadTicks(15) + .velocity(1.35f) + .knockback(0.1f) + .renderTumbling() + .soundPitch(1.1f) + .onEntityHit(new PotionEffect(MobEffects.MOVEMENT_SLOWDOWN, 2, 160, true)) + .registerAndAssign(ctx, AllItems.HONEYED_APPLE.get()); + + create("golden_apple") + .damage(1) + .reloadTicks(100) + .velocity(1.45f) + .knockback(0.05f) + .renderTumbling() + .soundPitch(1.1f) + .onEntityHit(CureZombieVillager.INSTANCE) + .registerAndAssign(ctx, Items.GOLDEN_APPLE); + + create("enchanted_golden_apple") + .damage(1) + .reloadTicks(100) + .velocity(1.45f) + .knockback(0.05f) + .renderTumbling() + .soundPitch(1.1f) + .onEntityHit(new FoodEffects(Foods.ENCHANTED_GOLDEN_APPLE, false)) + .registerAndAssign(ctx, Items.ENCHANTED_GOLDEN_APPLE); + + create("beetroot") + .damage(2) + .reloadTicks(5) + .velocity(1.6f) + .knockback(0.1f) + .renderTowardMotion(140, 2) + .soundPitch(1.6f) + .registerAndAssign(ctx, Items.BEETROOT); + + create("melon_slice") + .damage(3) + .reloadTicks(8) + .knockback(0.1f) + .velocity(1.45f) + .renderTumbling() + .soundPitch(1.5f) + .registerAndAssign(ctx, Items.MELON_SLICE); + + create("glistering_melon") + .damage(5) + .reloadTicks(8) + .knockback(0.1f) + .velocity(1.45f) + .renderTumbling() + .soundPitch(1.5f) + .onEntityHit(new PotionEffect(MobEffects.GLOWING, 1, 100, true)) + .registerAndAssign(ctx, Items.GLISTERING_MELON_SLICE); + + create("melon_block") + .damage(8) + .reloadTicks(20) + .knockback(2.0f) + .velocity(0.95f) + .renderTumbling() + .soundPitch(0.9f) + .onBlockHit(new PlaceBlockOnGround(Blocks.MELON)) + .registerAndAssign(ctx, Blocks.MELON); + + create("pumpkin_block") + .damage(6) + .reloadTicks(15) + .knockback(2.0f) + .velocity(0.95f) + .renderTumbling() + .soundPitch(0.9f) + .onBlockHit(new PlaceBlockOnGround(Blocks.PUMPKIN)) + .registerAndAssign(ctx, Blocks.PUMPKIN); + + create("pumpkin_pie") + .damage(7) + .reloadTicks(15) + .knockback(0.05f) + .velocity(1.1f) + .renderTumbling() + .sticky() + .soundPitch(1.1f) + .registerAndAssign(ctx, Items.PUMPKIN_PIE); + + create("cake") + .damage(8) + .reloadTicks(15) + .knockback(0.1f) + .velocity(1.1f) + .renderTumbling() + .sticky() + .registerAndAssign(ctx, Items.CAKE); + + create("blaze_cake") + .damage(15) + .reloadTicks(20) + .knockback(0.3f) + .velocity(1.1f) + .renderTumbling() + .sticky() + .preEntityHit(SetOnFire.seconds(12)) + .registerAndAssign(ctx, AllItems.BLAZE_CAKE.get()); + + create("fish") + .damage(4) + .knockback(0.6f) + .velocity(1.3f) + .renderTowardMotion(140, 1) + .sticky() + .soundPitch(1.3f) + .registerAndAssign(ctx, Items.COD, Items.COOKED_COD, Items.SALMON, Items.COOKED_SALMON, Items.TROPICAL_FISH); + + create("pufferfish") + .damage(4) + .knockback(0.4f) + .velocity(1.1f) + .renderTowardMotion(140, 1) + .sticky() + .onEntityHit(new FoodEffects(Foods.PUFFERFISH, false)) + .soundPitch(1.1f) + .registerAndAssign(ctx, Items.PUFFERFISH); + + create("suspicious_stew") + .damage(3) + .reloadTicks(40) + .knockback(0.2f) + .velocity(0.8f) + .renderTowardMotion(140, 1) + .dropStack(Items.BOWL.getDefaultInstance()) + .onEntityHit(SuspiciousStew.INSTANCE) + .registerAndAssign(ctx, Items.SUSPICIOUS_STEW); + } + + private static PotatoCannonProjectileType.Builder create(String name) { + return new PotatoCannonProjectileType.Builder(Create.asResource(name)); + } +} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/BuiltinPotatoProjectileTypes.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/BuiltinPotatoProjectileTypes.java deleted file mode 100644 index eb5b87af7b..0000000000 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/BuiltinPotatoProjectileTypes.java +++ /dev/null @@ -1,420 +0,0 @@ -package com.simibubi.create.content.equipment.potatoCannon; - -import java.util.UUID; -import java.util.function.BiPredicate; -import java.util.function.Predicate; -import java.util.function.Supplier; - -import com.mojang.authlib.GameProfile; -import com.mojang.datafixers.util.Pair; -import com.simibubi.create.AllItems; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.mixin.accessor.FallingBlockEntityAccessor; - -import net.createmod.catnip.data.WorldAttached; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; -import net.minecraft.util.Mth; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.animal.Fox; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.monster.ZombieVillager; -import net.minecraft.world.food.FoodProperties; -import net.minecraft.world.food.Foods; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.Vec3; - -import net.minecraftforge.common.IPlantable; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.event.ForgeEventFactory; -import net.minecraftforge.event.entity.EntityTeleportEvent; -import net.minecraftforge.registries.ForgeRegistries; - -public class BuiltinPotatoProjectileTypes { - - private static final GameProfile ZOMBIE_CONVERTER_NAME = - new GameProfile(UUID.fromString("be12d3dc-27d3-4992-8c97-66be53fd49c5"), "Converter"); - private static final WorldAttached ZOMBIE_CONVERTERS = - new WorldAttached<>(w -> new FakePlayer((ServerLevel) w, ZOMBIE_CONVERTER_NAME)); - - public static final PotatoCannonProjectileType - - FALLBACK = create("fallback").damage(0) - .register(), - - POTATO = create("potato").damage(5) - .reloadTicks(15) - .velocity(1.25f) - .knockback(1.5f) - .renderTumbling() - .onBlockHit(plantCrop(Blocks.POTATOES)) - .registerAndAssign(Items.POTATO), - - BAKED_POTATO = create("baked_potato").damage(5) - .reloadTicks(15) - .velocity(1.25f) - .knockback(0.5f) - .renderTumbling() - .preEntityHit(setFire(3)) - .registerAndAssign(Items.BAKED_POTATO), - - CARROT = create("carrot").damage(4) - .reloadTicks(12) - .velocity(1.45f) - .knockback(0.3f) - .renderTowardMotion(140, 1) - .soundPitch(1.5f) - .onBlockHit(plantCrop(Blocks.CARROTS)) - .registerAndAssign(Items.CARROT), - - GOLDEN_CARROT = create("golden_carrot").damage(12) - .reloadTicks(15) - .velocity(1.45f) - .knockback(0.5f) - .renderTowardMotion(140, 2) - .soundPitch(1.5f) - .registerAndAssign(Items.GOLDEN_CARROT), - - SWEET_BERRIES = create("sweet_berry").damage(3) - .reloadTicks(10) - .knockback(0.1f) - .velocity(1.05f) - .renderTumbling() - .splitInto(3) - .soundPitch(1.25f) - .registerAndAssign(Items.SWEET_BERRIES), - - GLOW_BERRIES = create("glow_berry").damage(2) - .reloadTicks(10) - .knockback(0.05f) - .velocity(1.05f) - .renderTumbling() - .splitInto(2) - .soundPitch(1.2f) - .onEntityHit(potion(MobEffects.GLOWING, 1, 200, false)) - .registerAndAssign(Items.GLOW_BERRIES), - - CHOCOLATE_BERRIES = create("chocolate_berry").damage(4) - .reloadTicks(10) - .knockback(0.2f) - .velocity(1.05f) - .renderTumbling() - .splitInto(3) - .soundPitch(1.25f) - .registerAndAssign(AllItems.CHOCOLATE_BERRIES.get()), - - POISON_POTATO = create("poison_potato").damage(5) - .reloadTicks(15) - .knockback(0.05f) - .velocity(1.25f) - .renderTumbling() - .onEntityHit(potion(MobEffects.POISON, 1, 160, true)) - .registerAndAssign(Items.POISONOUS_POTATO), - - CHORUS_FRUIT = create("chorus_fruit").damage(3) - .reloadTicks(15) - .velocity(1.20f) - .knockback(0.05f) - .renderTumbling() - .onEntityHit(chorusTeleport(20)) - .registerAndAssign(Items.CHORUS_FRUIT), - - APPLE = create("apple").damage(5) - .reloadTicks(10) - .velocity(1.45f) - .knockback(0.5f) - .renderTumbling() - .soundPitch(1.1f) - .registerAndAssign(Items.APPLE), - - HONEYED_APPLE = create("honeyed_apple").damage(6) - .reloadTicks(15) - .velocity(1.35f) - .knockback(0.1f) - .renderTumbling() - .soundPitch(1.1f) - .onEntityHit(potion(MobEffects.MOVEMENT_SLOWDOWN, 2, 160, true)) - .registerAndAssign(AllItems.HONEYED_APPLE.get()), - - GOLDEN_APPLE = create("golden_apple").damage(1) - .reloadTicks(100) - .velocity(1.45f) - .knockback(0.05f) - .renderTumbling() - .soundPitch(1.1f) - .onEntityHit(ray -> { - Entity entity = ray.getEntity(); - Level world = entity.level(); - - if (!(entity instanceof ZombieVillager) || !((ZombieVillager) entity).hasEffect(MobEffects.WEAKNESS)) - return foodEffects(Foods.GOLDEN_APPLE, false).test(ray); - if (world.isClientSide) - return false; - - FakePlayer dummy = ZOMBIE_CONVERTERS.get(world); - dummy.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.GOLDEN_APPLE, 1)); - ((ZombieVillager) entity).mobInteract(dummy, InteractionHand.MAIN_HAND); - return true; - }) - .registerAndAssign(Items.GOLDEN_APPLE), - - ENCHANTED_GOLDEN_APPLE = create("enchanted_golden_apple").damage(1) - .reloadTicks(100) - .velocity(1.45f) - .knockback(0.05f) - .renderTumbling() - .soundPitch(1.1f) - .onEntityHit(foodEffects(Foods.ENCHANTED_GOLDEN_APPLE, false)) - .registerAndAssign(Items.ENCHANTED_GOLDEN_APPLE), - - BEETROOT = create("beetroot").damage(2) - .reloadTicks(5) - .velocity(1.6f) - .knockback(0.1f) - .renderTowardMotion(140, 2) - .soundPitch(1.6f) - .registerAndAssign(Items.BEETROOT), - - MELON_SLICE = create("melon_slice").damage(3) - .reloadTicks(8) - .knockback(0.1f) - .velocity(1.45f) - .renderTumbling() - .soundPitch(1.5f) - .registerAndAssign(Items.MELON_SLICE), - - GLISTERING_MELON = create("glistering_melon").damage(5) - .reloadTicks(8) - .knockback(0.1f) - .velocity(1.45f) - .renderTumbling() - .soundPitch(1.5f) - .onEntityHit(potion(MobEffects.GLOWING, 1, 100, true)) - .registerAndAssign(Items.GLISTERING_MELON_SLICE), - - MELON_BLOCK = create("melon_block").damage(8) - .reloadTicks(20) - .knockback(2.0f) - .velocity(0.95f) - .renderTumbling() - .soundPitch(0.9f) - .onBlockHit(placeBlockOnGround(Blocks.MELON)) - .registerAndAssign(Blocks.MELON), - - PUMPKIN_BLOCK = create("pumpkin_block").damage(6) - .reloadTicks(15) - .knockback(2.0f) - .velocity(0.95f) - .renderTumbling() - .soundPitch(0.9f) - .onBlockHit(placeBlockOnGround(Blocks.PUMPKIN)) - .registerAndAssign(Blocks.PUMPKIN), - - PUMPKIN_PIE = create("pumpkin_pie").damage(7) - .reloadTicks(15) - .knockback(0.05f) - .velocity(1.1f) - .renderTumbling() - .sticky() - .soundPitch(1.1f) - .registerAndAssign(Items.PUMPKIN_PIE), - - CAKE = create("cake").damage(8) - .reloadTicks(15) - .knockback(0.1f) - .velocity(1.1f) - .renderTumbling() - .sticky() - .soundPitch(1.0f) - .registerAndAssign(Items.CAKE), - - BLAZE_CAKE = create("blaze_cake").damage(15) - .reloadTicks(20) - .knockback(0.3f) - .velocity(1.1f) - .renderTumbling() - .sticky() - .preEntityHit(setFire(12)) - .soundPitch(1.0f) - .registerAndAssign(AllItems.BLAZE_CAKE.get()); - - private static PotatoCannonProjectileType.Builder create(String name) { - return new PotatoCannonProjectileType.Builder(Create.asResource(name)); - } - - private static Predicate setFire(int seconds) { - return ray -> { - ray.getEntity() - .setSecondsOnFire(seconds); - return false; - }; - } - - private static Predicate potion(MobEffect effect, int level, int ticks, boolean recoverable) { - return ray -> { - Entity entity = ray.getEntity(); - if (entity.level().isClientSide) - return true; - if (entity instanceof LivingEntity) - applyEffect((LivingEntity) entity, new MobEffectInstance(effect, ticks, level - 1)); - return !recoverable; - }; - } - - private static Predicate foodEffects(FoodProperties food, boolean recoverable) { - return ray -> { - Entity entity = ray.getEntity(); - if (entity.level().isClientSide) - return true; - - if (entity instanceof LivingEntity) { - for (Pair effect : food.getEffects()) { - if (Create.RANDOM.nextFloat() < effect.getSecond()) - applyEffect((LivingEntity) entity, new MobEffectInstance(effect.getFirst())); - } - } - return !recoverable; - }; - } - - private static void applyEffect(LivingEntity entity, MobEffectInstance effect) { - if (effect.getEffect() - .isInstantenous()) - effect.getEffect() - .applyInstantenousEffect(null, null, entity, effect.getDuration(), 1.0); - else - entity.addEffect(effect); - } - - private static BiPredicate plantCrop(Supplier cropBlock) { - return (world, ray) -> { - if (world.isClientSide()) - return true; - - BlockPos hitPos = ray.getBlockPos(); - if (world instanceof Level l && !l.isLoaded(hitPos)) - return true; - Direction face = ray.getDirection(); - if (face != Direction.UP) - return false; - BlockPos placePos = hitPos.relative(face); - if (!world.getBlockState(placePos) - .canBeReplaced()) - return false; - if (!(cropBlock.get() instanceof IPlantable)) - return false; - BlockState blockState = world.getBlockState(hitPos); - if (!blockState.canSustainPlant(world, hitPos, face, (IPlantable) cropBlock.get())) - return false; - world.setBlock(placePos, cropBlock.get() - .defaultBlockState(), 3); - return true; - }; - } - - private static BiPredicate plantCrop(Block cropBlock) { - return plantCrop(ForgeRegistries.BLOCKS.getDelegateOrThrow(cropBlock)); - } - - private static BiPredicate placeBlockOnGround( - Supplier block) { - return (world, ray) -> { - if (world.isClientSide()) - return true; - - BlockPos hitPos = ray.getBlockPos(); - if (world instanceof Level l && !l.isLoaded(hitPos)) - return true; - Direction face = ray.getDirection(); - BlockPos placePos = hitPos.relative(face); - if (!world.getBlockState(placePos) - .canBeReplaced()) - return false; - - if (face == Direction.UP) { - world.setBlock(placePos, block.get() - .defaultBlockState(), 3); - } else if (world instanceof Level level) { - double y = ray.getLocation().y - 0.5; - if (!world.isEmptyBlock(placePos.above())) - y = Math.min(y, placePos.getY()); - if (!world.isEmptyBlock(placePos.below())) - y = Math.max(y, placePos.getY()); - - FallingBlockEntity falling = FallingBlockEntityAccessor.create$callInit(level, placePos.getX() + 0.5, y, - placePos.getZ() + 0.5, block.get().defaultBlockState()); - falling.time = 1; - world.addFreshEntity(falling); - } - - return true; - }; - } - - private static BiPredicate placeBlockOnGround(Block block) { - return placeBlockOnGround(ForgeRegistries.BLOCKS.getDelegateOrThrow(block)); - } - - private static Predicate chorusTeleport(double teleportDiameter) { - return ray -> { - Entity entity = ray.getEntity(); - Level world = entity.getCommandSenderWorld(); - if (world.isClientSide) - return true; - if (!(entity instanceof LivingEntity livingEntity)) - return false; - - double entityX = livingEntity.getX(); - double entityY = livingEntity.getY(); - double entityZ = livingEntity.getZ(); - - for (int teleportTry = 0; teleportTry < 16; ++teleportTry) { - double teleportX = entityX + (livingEntity.getRandom() - .nextDouble() - 0.5D) * teleportDiameter; - double teleportY = Mth.clamp(entityY + (livingEntity.getRandom() - .nextInt((int) teleportDiameter) - (int) (teleportDiameter / 2)), 0.0D, world.getHeight() - 1); - double teleportZ = entityZ + (livingEntity.getRandom() - .nextDouble() - 0.5D) * teleportDiameter; - - EntityTeleportEvent.ChorusFruit event = - ForgeEventFactory.onChorusFruitTeleport(livingEntity, teleportX, teleportY, teleportZ); - if (event.isCanceled()) - return false; - if (livingEntity.randomTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ(), true)) { - if (livingEntity.isPassenger()) - livingEntity.stopRiding(); - - SoundEvent soundevent = - livingEntity instanceof Fox ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT; - world.playSound(null, entityX, entityY, entityZ, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F); - livingEntity.playSound(soundevent, 1.0F, 1.0F); - livingEntity.setDeltaMovement(Vec3.ZERO); - return true; - } - } - - return false; - }; - } - - public static void register() { - } - -} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItem.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItem.java index 23bfe5a864..185bc0d350 100644 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItem.java @@ -9,8 +9,9 @@ import org.jetbrains.annotations.Nullable; import com.simibubi.create.AllEnchantments; import com.simibubi.create.AllEntityTypes; -import com.simibubi.create.Create; import com.simibubi.create.CreateClient; +import com.simibubi.create.api.equipment.potatoCannon.PotatoCannonProjectileType; +import com.simibubi.create.api.registry.CreateRegistries; import com.simibubi.create.content.equipment.armor.BacktankUtil; import com.simibubi.create.content.equipment.zapper.ShootableGadgetItemMethods; import com.simibubi.create.foundation.item.CustomArmPoseItem; @@ -50,6 +51,7 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.extensions.common.IClientItemExtensions; +import net.minecraftforge.server.ServerLifecycleHooks; public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem { @@ -109,14 +111,13 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP } @Override - public InteractionResultHolder use(Level world, Player player, InteractionHand hand) { + public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { ItemStack stack = player.getItemInHand(hand); - return findAmmoInInventory(world, player, stack).map(itemStack -> { - + return findAmmoInInventory(level, player, stack).map(itemStack -> { if (ShootableGadgetItemMethods.shouldSwap(player, stack, hand, this::isCannon)) return InteractionResultHolder.fail(stack); - if (world.isClientSide) { + if (level.isClientSide) { CreateClient.POTATO_CANNON_RENDER_HANDLER.dontAnimateItem(hand); return InteractionResultHolder.success(stack); } @@ -128,28 +129,33 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP .subtract(player.position() .add(0, player.getEyeHeight(), 0)); - PotatoCannonProjectileType projectileType = PotatoProjectileTypeManager.getTypeForStack(itemStack) - .orElse(BuiltinPotatoProjectileTypes.FALLBACK); + PotatoCannonProjectileType projectileType = PotatoCannonProjectileType.getTypeForStack(level, itemStack) + .orElseGet(() -> + level.registryAccess() + .lookupOrThrow(CreateRegistries.POTATO_PROJECTILE_TYPE) + .getOrThrow(AllPotatoProjectileTypes.FALLBACK) + .value() + ); Vec3 lookVec = player.getLookAngle(); Vec3 motion = lookVec.add(correction) .normalize() .scale(2) - .scale(projectileType.getVelocityMultiplier()); + .scale(projectileType.velocityMultiplier()); - float soundPitch = projectileType.getSoundPitch() + (Create.RANDOM.nextFloat() - .5f) / 4f; + float soundPitch = projectileType.soundPitch() + (level.getRandom().nextFloat() - .5f) / 4f; - boolean spray = projectileType.getSplit() > 1; - Vec3 sprayBase = VecHelper.rotate(new Vec3(0, 0.1, 0), 360 * Create.RANDOM.nextFloat(), Axis.Z); - float sprayChange = 360f / projectileType.getSplit(); + boolean spray = projectileType.split() > 1; + Vec3 sprayBase = VecHelper.rotate(new Vec3(0, 0.1, 0), 360 * level.getRandom().nextFloat(), Axis.Z); + float sprayChange = 360f / projectileType.split(); - for (int i = 0; i < projectileType.getSplit(); i++) { - PotatoProjectileEntity projectile = AllEntityTypes.POTATO_PROJECTILE.create(world); + for (int i = 0; i < projectileType.split(); i++) { + PotatoProjectileEntity projectile = AllEntityTypes.POTATO_PROJECTILE.create(level); projectile.setItem(itemStack); projectile.setEnchantmentEffectsFromCannon(stack); Vec3 splitMotion = motion; if (spray) { - float imperfection = 40 * (Create.RANDOM.nextFloat() - 0.5f); + float imperfection = 40 * (level.getRandom().nextFloat() - 0.5f); Vec3 sprayOffset = VecHelper.rotate(sprayBase, i * sprayChange + imperfection, Axis.Z); splitMotion = splitMotion.add(VecHelper.lookAt(sprayOffset, motion)); } @@ -160,7 +166,7 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP projectile.setPos(barrelPos.x, barrelPos.y, barrelPos.z); projectile.setDeltaMovement(splitMotion); projectile.setOwner(player); - world.addFreshEntity(projectile); + level.addFreshEntity(projectile); } if (!player.isCreative()) { @@ -173,8 +179,8 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(hand)); Integer cooldown = - findAmmoInInventory(world, player, stack).flatMap(PotatoProjectileTypeManager::getTypeForStack) - .map(PotatoCannonProjectileType::getReloadTicks) + findAmmoInInventory(level, player, stack).flatMap(i -> PotatoCannonProjectileType.getTypeForStack(level, i)) + .map(potatoCannonProjectileType -> potatoCannonProjectileType.reloadTicks()) .orElse(10); ShootableGadgetItemMethods.applyCooldown(player, stack, hand, this::isCannon, cooldown); @@ -190,9 +196,9 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP return slotChanged || newStack.getItem() != oldStack.getItem(); } - private Optional findAmmoInInventory(Level world, Player player, ItemStack held) { + private Optional findAmmoInInventory(Level level, Player player, ItemStack held) { ItemStack findAmmo = player.getProjectile(held); - return PotatoProjectileTypeManager.getTypeForStack(findAmmo) + return PotatoCannonProjectileType.getTypeForStack(level, findAmmo) .map($ -> findAmmo); } @@ -207,7 +213,7 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP if (player == null) return Optional.empty(); ItemStack findAmmo = player.getProjectile(cannon); - Optional found = PotatoProjectileTypeManager.getTypeForStack(findAmmo) + Optional found = PotatoCannonProjectileType.getTypeForStack(Minecraft.getInstance().level, findAmmo) .map($ -> findAmmo); found.ifPresent(stack -> CLIENT_CURRENT_AMMO = stack); return found; @@ -215,7 +221,7 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP @Override @OnlyIn(Dist.CLIENT) - public void appendHoverText(ItemStack stack, Level world, List tooltip, TooltipFlag flag) { + public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { int power = stack.getEnchantmentLevel(Enchantments.POWER_ARROWS); int punch = stack.getEnchantmentLevel(Enchantments.PUNCH_ARROWS); final float additionalDamageMult = 1 + power * .2f; @@ -229,17 +235,17 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP tooltip.add(CommonComponents.EMPTY); tooltip.add(Component.translatable(ammo.getDescriptionId()).append(Component.literal(":")) .withStyle(ChatFormatting.GRAY)); - PotatoCannonProjectileType type = PotatoProjectileTypeManager.getTypeForStack(ammo) + PotatoCannonProjectileType type = PotatoCannonProjectileType.getTypeForStack(Minecraft.getInstance().level, ammo) .get(); MutableComponent spacing = CommonComponents.space(); ChatFormatting green = ChatFormatting.GREEN; ChatFormatting darkGreen = ChatFormatting.DARK_GREEN; - float damageF = type.getDamage() * additionalDamageMult; + float damageF = type.damage() * additionalDamageMult; MutableComponent damage = Component.literal(damageF == Mth.floor(damageF) ? "" + Mth.floor(damageF) : "" + damageF); - MutableComponent reloadTicks = Component.literal("" + type.getReloadTicks()); + MutableComponent reloadTicks = Component.literal("" + type.reloadTicks()); MutableComponent knockback = - Component.literal("" + (type.getKnockback() + additionalKnockback)); + Component.literal("" + (type.knockback() + additionalKnockback)); damage = damage.withStyle(additionalDamageMult > 1 ? green : darkGreen); knockback = knockback.withStyle(additionalKnockback > 0 ? green : darkGreen); @@ -255,12 +261,13 @@ public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmP .append(CreateLang.translateDirect(_knockback, knockback) .withStyle(darkGreen))); }); - super.appendHoverText(stack, world, tooltip, flag); + super.appendHoverText(stack, level, tooltip, flag); } @Override public Predicate getAllSupportedProjectiles() { - return stack -> PotatoProjectileTypeManager.getTypeForStack(stack) + Level level = ServerLifecycleHooks.getCurrentServer().getLevel(Level.OVERWORLD); + return stack -> PotatoCannonProjectileType.getTypeForStack(level, stack) .isPresent(); } diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItemRenderer.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItemRenderer.java index 4a7c89e2b4..831a3683b9 100644 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonItemRenderer.java @@ -2,6 +2,7 @@ package com.simibubi.create.content.equipment.potatoCannon; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; +import com.simibubi.create.AllItems; import com.simibubi.create.Create; import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.item.render.CustomRenderedItemModel; @@ -27,7 +28,7 @@ public class PotatoCannonItemRenderer extends CustomRenderedItemModelRenderer { @Override protected void render(ItemStack stack, CustomRenderedItemModel model, PartialItemModelRenderer renderer, - ItemDisplayContext transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { + ItemDisplayContext transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) { Minecraft mc = Minecraft.getInstance(); ItemRenderer itemRenderer = mc.getItemRenderer(); renderer.render(model.getOriginalModel(), light); @@ -54,18 +55,18 @@ public class PotatoCannonItemRenderer extends CustomRenderedItemModelRenderer { ms.popPose(); if (transformType == ItemDisplayContext.GUI) { - PotatoCannonItem.getAmmoforPreview(stack) - .ifPresent(ammo -> { - PoseStack localMs = new PoseStack(); - localMs.translate(-1 / 4f, -1 / 4f, 1); - localMs.scale(.5f, .5f, .5f); - TransformStack.of(localMs) - .rotateYDegrees(-34); - itemRenderer.renderStatic(ammo, ItemDisplayContext.GUI, light, OverlayTexture.NO_OVERLAY, localMs, - buffer, mc.level, 0); - }); + PotatoCannonItem.getAmmoforPreview(stack).ifPresent(ammo -> { + if (AllItems.POTATO_CANNON.is(ammo)) return; + + PoseStack localMs = new PoseStack(); + localMs.translate(-1 / 4f, -1 / 4f, 1); + localMs.scale(.5f, .5f, .5f); + TransformStack.of(localMs) + .rotateYDegrees(-34); + itemRenderer.renderStatic(ammo, ItemDisplayContext.GUI, light, OverlayTexture.NO_OVERLAY, localMs, + buffer, mc.level, 0); + }); } - } } diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonProjectileType.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonProjectileType.java deleted file mode 100644 index 4ac551cdf4..0000000000 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoCannonProjectileType.java +++ /dev/null @@ -1,298 +0,0 @@ -package com.simibubi.create.content.equipment.potatoCannon; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.BiPredicate; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.Supplier; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; - -import net.createmod.catnip.platform.CatnipServices; -import net.minecraft.ResourceLocationException; -import net.minecraft.core.Holder; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.Item; -import net.minecraft.world.level.ItemLike; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraftforge.registries.ForgeRegistries; - -public class PotatoCannonProjectileType { - - private List> items = new ArrayList<>(); - - private int reloadTicks = 10; - private int damage = 1; - private int split = 1; - private float knockback = 1; - private float drag = 0.99f; - private float velocityMultiplier = 1; - private float gravityMultiplier = 1; - private float soundPitch = 1; - private boolean sticky = false; - private PotatoProjectileRenderMode renderMode = PotatoProjectileRenderMode.Billboard.INSTANCE; - - private Predicate preEntityHit = e -> false; // True if hit should be canceled - private Predicate onEntityHit = e -> false; // True if shouldn't recover projectile - private BiPredicate onBlockHit = (w, ray) -> false; - - protected PotatoCannonProjectileType() { - } - - public List> getItems() { - return items; - } - - public int getReloadTicks() { - return reloadTicks; - } - - public int getDamage() { - return damage; - } - - public int getSplit() { - return split; - } - - public float getKnockback() { - return knockback; - } - - public float getDrag() { - return drag; - } - - public float getVelocityMultiplier() { - return velocityMultiplier; - } - - public float getGravityMultiplier() { - return gravityMultiplier; - } - - public float getSoundPitch() { - return soundPitch; - } - - public boolean isSticky() { - return sticky; - } - - public PotatoProjectileRenderMode getRenderMode() { - return renderMode; - } - - public boolean preEntityHit(EntityHitResult ray) { - return preEntityHit.test(ray); - } - - public boolean onEntityHit(EntityHitResult ray) { - return onEntityHit.test(ray); - } - - public boolean onBlockHit(LevelAccessor world, BlockHitResult ray) { - return onBlockHit.test(world, ray); - } - - public static PotatoCannonProjectileType fromJson(JsonObject object) { - PotatoCannonProjectileType type = new PotatoCannonProjectileType(); - try { - JsonElement itemsElement = object.get("items"); - if (itemsElement != null && itemsElement.isJsonArray()) { - for (JsonElement element : itemsElement.getAsJsonArray()) { - if (element.isJsonPrimitive()) { - JsonPrimitive primitive = element.getAsJsonPrimitive(); - if (primitive.isString()) { - try { - Optional> reference = ForgeRegistries.ITEMS.getDelegate(new ResourceLocation(primitive.getAsString())); - if (reference.isPresent()) { - type.items.add(reference.get()); - } - } catch (ResourceLocationException e) { - // - } - } - } - } - } - - parseJsonPrimitive(object, "reload_ticks", JsonPrimitive::isNumber, primitive -> type.reloadTicks = primitive.getAsInt()); - parseJsonPrimitive(object, "damage", JsonPrimitive::isNumber, primitive -> type.damage = primitive.getAsInt()); - parseJsonPrimitive(object, "split", JsonPrimitive::isNumber, primitive -> type.split = primitive.getAsInt()); - parseJsonPrimitive(object, "knockback", JsonPrimitive::isNumber, primitive -> type.knockback = primitive.getAsFloat()); - parseJsonPrimitive(object, "drag", JsonPrimitive::isNumber, primitive -> type.drag = primitive.getAsFloat()); - parseJsonPrimitive(object, "velocity_multiplier", JsonPrimitive::isNumber, primitive -> type.velocityMultiplier = primitive.getAsFloat()); - parseJsonPrimitive(object, "gravity_multiplier", JsonPrimitive::isNumber, primitive -> type.gravityMultiplier = primitive.getAsFloat()); - parseJsonPrimitive(object, "sound_pitch", JsonPrimitive::isNumber, primitive -> type.soundPitch = primitive.getAsFloat()); - parseJsonPrimitive(object, "sticky", JsonPrimitive::isBoolean, primitive -> type.sticky = primitive.getAsBoolean()); - } catch (Exception e) { - // - } - return type; - } - - private static void parseJsonPrimitive(JsonObject object, String key, Predicate predicate, Consumer consumer) { - JsonElement element = object.get(key); - if (element != null && element.isJsonPrimitive()) { - JsonPrimitive primitive = element.getAsJsonPrimitive(); - if (predicate.test(primitive)) { - consumer.accept(primitive); - } - } - } - - public static void toBuffer(PotatoCannonProjectileType type, FriendlyByteBuf buffer) { - buffer.writeVarInt(type.items.size()); - for (Supplier delegate : type.items) { - buffer.writeResourceLocation(CatnipServices.REGISTRIES.getKeyOrThrow(delegate.get())); - } - buffer.writeInt(type.reloadTicks); - buffer.writeInt(type.damage); - buffer.writeInt(type.split); - buffer.writeFloat(type.knockback); - buffer.writeFloat(type.drag); - buffer.writeFloat(type.velocityMultiplier); - buffer.writeFloat(type.gravityMultiplier); - buffer.writeFloat(type.soundPitch); - buffer.writeBoolean(type.sticky); - } - - public static PotatoCannonProjectileType fromBuffer(FriendlyByteBuf buffer) { - PotatoCannonProjectileType type = new PotatoCannonProjectileType(); - int size = buffer.readVarInt(); - for (int i = 0; i < size; i++) { - Optional> reference = ForgeRegistries.ITEMS.getDelegate(buffer.readResourceLocation()); - if (reference.isPresent()) { - type.items.add(reference.get()); - } - } - type.reloadTicks = buffer.readInt(); - type.damage = buffer.readInt(); - type.split = buffer.readInt(); - type.knockback = buffer.readFloat(); - type.drag = buffer.readFloat(); - type.velocityMultiplier = buffer.readFloat(); - type.gravityMultiplier = buffer.readFloat(); - type.soundPitch = buffer.readFloat(); - type.sticky = buffer.readBoolean(); - return type; - } - - public static class Builder { - - protected ResourceLocation id; - protected PotatoCannonProjectileType result; - - public Builder(ResourceLocation id) { - this.id = id; - this.result = new PotatoCannonProjectileType(); - } - - public Builder reloadTicks(int reload) { - result.reloadTicks = reload; - return this; - } - - public Builder damage(int damage) { - result.damage = damage; - return this; - } - - public Builder splitInto(int split) { - result.split = split; - return this; - } - - public Builder knockback(float knockback) { - result.knockback = knockback; - return this; - } - - public Builder drag(float drag) { - result.drag = drag; - return this; - } - - public Builder velocity(float velocity) { - result.velocityMultiplier = velocity; - return this; - } - - public Builder gravity(float modifier) { - result.gravityMultiplier = modifier; - return this; - } - - public Builder soundPitch(float pitch) { - result.soundPitch = pitch; - return this; - } - - public Builder sticky() { - result.sticky = true; - return this; - } - - public Builder renderMode(PotatoProjectileRenderMode renderMode) { - result.renderMode = renderMode; - return this; - } - - public Builder renderBillboard() { - renderMode(PotatoProjectileRenderMode.Billboard.INSTANCE); - return this; - } - - public Builder renderTumbling() { - renderMode(PotatoProjectileRenderMode.Tumble.INSTANCE); - return this; - } - - public Builder renderTowardMotion(int spriteAngle, float spin) { - renderMode(new PotatoProjectileRenderMode.TowardMotion(spriteAngle, spin)); - return this; - } - - public Builder preEntityHit(Predicate callback) { - result.preEntityHit = callback; - return this; - } - - public Builder onEntityHit(Predicate callback) { - result.onEntityHit = callback; - return this; - } - - public Builder onBlockHit(BiPredicate callback) { - result.onBlockHit = callback; - return this; - } - - public Builder addItems(ItemLike... items) { - for (ItemLike provider : items) - result.items.add(ForgeRegistries.ITEMS.getDelegateOrThrow(provider.asItem())); - return this; - } - - public PotatoCannonProjectileType register() { - PotatoProjectileTypeManager.registerBuiltinType(id, result); - return result; - } - - public PotatoCannonProjectileType registerAndAssign(ItemLike... items) { - addItems(items); - register(); - return result; - } - - } - -} diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileEntity.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileEntity.java index 38e784ebfa..16b9cd8c1c 100644 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileEntity.java +++ b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileEntity.java @@ -4,6 +4,9 @@ import org.jetbrains.annotations.NotNull; import com.simibubi.create.AllEnchantments; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.api.equipment.potatoCannon.PotatoCannonProjectileType; +import com.simibubi.create.api.equipment.potatoCannon.PotatoProjectileRenderMode; +import com.simibubi.create.api.registry.CreateRegistries; import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.damageTypes.CreateDamageSources; import com.simibubi.create.foundation.particle.AirParticleData; @@ -68,8 +71,13 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements public PotatoCannonProjectileType getProjectileType() { if (type == null) - type = PotatoProjectileTypeManager.getTypeForStack(stack) - .orElse(BuiltinPotatoProjectileTypes.FALLBACK); + type = PotatoCannonProjectileType.getTypeForStack(level(), stack) + .orElseGet(() -> + level().registryAccess() + .lookupOrThrow(CreateRegistries.POTATO_PROJECTILE_TYPE) + .getOrThrow(AllPotatoProjectileTypes.FALLBACK) + .value() + ); return type; } @@ -127,7 +135,7 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements if (getStuckEntity() != null) return stuckRenderer; - return getProjectileType().getRenderMode(); + return getProjectileType().renderMode(); } public void tick() { @@ -139,15 +147,15 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements pop(position()); kill(); } else { - stuckFallSpeed += 0.007 * projectileType.getGravityMultiplier(); + stuckFallSpeed += 0.007 * projectileType.gravityMultiplier(); stuckOffset = stuckOffset.add(0, -stuckFallSpeed, 0); Vec3 pos = stuckEntity.position() .add(stuckOffset); setPos(pos.x, pos.y, pos.z); } } else { - setDeltaMovement(getDeltaMovement().add(0, -0.05 * projectileType.getGravityMultiplier(), 0) - .scale(projectileType.getDrag())); + setDeltaMovement(getDeltaMovement().add(0, -0.05 * projectileType.gravityMultiplier(), 0) + .scale(projectileType.drag())); } super.tick(); @@ -178,8 +186,8 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements Vec3 hit = ray.getLocation(); Entity target = ray.getEntity(); PotatoCannonProjectileType projectileType = getProjectileType(); - float damage = projectileType.getDamage() * additionalDamageMult; - float knockback = projectileType.getKnockback() + additionalKnockback; + float damage = projectileType.damage() * additionalDamageMult; + float knockback = projectileType.knockback() + additionalKnockback; Entity owner = this.getOwner(); if (!target.isAlive()) @@ -202,7 +210,7 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements if (target instanceof WitherBoss && ((WitherBoss) target).isPowered()) return; - if (projectileType.preEntityHit(ray)) + if (projectileType.preEntityHit(stack, ray)) return; boolean targetIsEnderman = target.getType() == EntityType.ENDERMAN; @@ -220,9 +228,12 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements if (targetIsEnderman) return; - if (!projectileType.onEntityHit(ray) && onServer) - if (random.nextDouble() <= recoveryChance) + if (!projectileType.onEntityHit(stack, ray) && onServer) + if (random.nextDouble() <= recoveryChance) { recoverItem(); + } else { + spawnAtLocation(projectileType.dropStack()); + } if (!(target instanceof LivingEntity livingentity)) { playHitSound(level(), position()); @@ -230,8 +241,8 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements return; } - if (type.getReloadTicks() < 10) - livingentity.invulnerableTime = type.getReloadTicks() + 10; + if (type.reloadTicks() < 10) + livingentity.invulnerableTime = type.reloadTicks() + 10; if (onServer && knockback > 0) { Vec3 appliedMotion = this.getDeltaMovement() @@ -259,7 +270,7 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements AllAdvancements.POTATO_CANNON.awardTo(serverplayerentity); } - if (type.isSticky() && target.isAlive()) { + if (type.sticky() && target.isAlive()) { setStuckEntity(target); } else { kill(); @@ -284,7 +295,7 @@ public class PotatoProjectileEntity extends AbstractHurtingProjectile implements protected void onHitBlock(BlockHitResult ray) { Vec3 hit = ray.getLocation(); pop(hit); - if (!getProjectileType().onBlockHit(level(), ray) && !level().isClientSide) + if (!getProjectileType().onBlockHit(level(), stack, ray) && !level().isClientSide) if (random.nextDouble() <= recoveryChance) recoverItem(); super.onHitBlock(ray); diff --git a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileTypeManager.java b/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileTypeManager.java deleted file mode 100644 index 09d8674bc0..0000000000 --- a/src/main/java/com/simibubi/create/content/equipment/potatoCannon/PotatoProjectileTypeManager.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.simibubi.create.content.equipment.potatoCannon; - -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.simibubi.create.AllItems; -import com.simibubi.create.AllPackets; -import com.simibubi.create.foundation.networking.SimplePacketBase; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; -import net.minecraft.util.profiling.ProfilerFiller; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraftforge.network.NetworkEvent.Context; -import net.minecraftforge.network.PacketDistributor; - -public class PotatoProjectileTypeManager { - - private static final Map BUILTIN_TYPE_MAP = new HashMap<>(); - private static final Map CUSTOM_TYPE_MAP = new HashMap<>(); - private static final Map ITEM_TO_TYPE_MAP = new IdentityHashMap<>(); - - public static void registerBuiltinType(ResourceLocation id, PotatoCannonProjectileType type) { - synchronized (BUILTIN_TYPE_MAP) { - BUILTIN_TYPE_MAP.put(id, type); - } - } - - public static PotatoCannonProjectileType getBuiltinType(ResourceLocation id) { - return BUILTIN_TYPE_MAP.get(id); - } - - public static PotatoCannonProjectileType getCustomType(ResourceLocation id) { - return CUSTOM_TYPE_MAP.get(id); - } - - public static PotatoCannonProjectileType getTypeForItem(Item item) { - return ITEM_TO_TYPE_MAP.get(item); - } - - public static Optional getTypeForStack(ItemStack item) { - if (item.isEmpty()) - return Optional.empty(); - return Optional.ofNullable(getTypeForItem(item.getItem())); - } - - public static void clear() { - CUSTOM_TYPE_MAP.clear(); - ITEM_TO_TYPE_MAP.clear(); - } - - public static void fillItemMap() { - for (Map.Entry entry : BUILTIN_TYPE_MAP.entrySet()) { - PotatoCannonProjectileType type = entry.getValue(); - for (Supplier delegate : type.getItems()) { - ITEM_TO_TYPE_MAP.put(delegate.get(), type); - } - } - for (Map.Entry entry : CUSTOM_TYPE_MAP.entrySet()) { - PotatoCannonProjectileType type = entry.getValue(); - for (Supplier delegate : type.getItems()) { - ITEM_TO_TYPE_MAP.put(delegate.get(), type); - } - } - ITEM_TO_TYPE_MAP.remove(AllItems.POTATO_CANNON.get()); - } - - public static void toBuffer(FriendlyByteBuf buffer) { - buffer.writeVarInt(CUSTOM_TYPE_MAP.size()); - for (Map.Entry entry : CUSTOM_TYPE_MAP.entrySet()) { - buffer.writeResourceLocation(entry.getKey()); - PotatoCannonProjectileType.toBuffer(entry.getValue(), buffer); - } - } - - public static void fromBuffer(FriendlyByteBuf buffer) { - clear(); - - int size = buffer.readVarInt(); - for (int i = 0; i < size; i++) { - CUSTOM_TYPE_MAP.put(buffer.readResourceLocation(), PotatoCannonProjectileType.fromBuffer(buffer)); - } - - fillItemMap(); - } - - public static void syncTo(ServerPlayer player) { - AllPackets.getChannel().send(PacketDistributor.PLAYER.with(() -> player), new SyncPacket()); - } - - public static void syncToAll() { - AllPackets.getChannel().send(PacketDistributor.ALL.noArg(), new SyncPacket()); - } - - public static class ReloadListener extends SimpleJsonResourceReloadListener { - - private static final Gson GSON = new Gson(); - - public static final ReloadListener INSTANCE = new ReloadListener(); - - protected ReloadListener() { - super(GSON, "potato_cannon_projectile_types"); - } - - @Override - protected void apply(Map map, ResourceManager resourceManager, ProfilerFiller profiler) { - clear(); - - for (Map.Entry entry : map.entrySet()) { - JsonElement element = entry.getValue(); - if (element.isJsonObject()) { - ResourceLocation id = entry.getKey(); - JsonObject object = element.getAsJsonObject(); - PotatoCannonProjectileType type = PotatoCannonProjectileType.fromJson(object); - CUSTOM_TYPE_MAP.put(id, type); - } - } - - fillItemMap(); - } - - } - - public static class SyncPacket extends SimplePacketBase { - - private FriendlyByteBuf buffer; - - public SyncPacket() { - } - - public SyncPacket(FriendlyByteBuf buffer) { - this.buffer = buffer; - } - - @Override - public void write(FriendlyByteBuf buffer) { - toBuffer(buffer); - } - - @Override - public boolean handle(Context context) { - context.enqueueWork(() -> { - fromBuffer(buffer); - }); - return true; - } - - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index 788cf9c7ee..7f94e72ec1 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -6,7 +6,6 @@ import com.simibubi.create.content.contraptions.ContraptionHandler; import com.simibubi.create.content.contraptions.actors.trainControls.ControlsServerHandler; import com.simibubi.create.content.contraptions.minecart.CouplingPhysics; import com.simibubi.create.content.contraptions.minecart.capability.CapabilityMinecartController; -import com.simibubi.create.content.equipment.potatoCannon.PotatoProjectileTypeManager; import com.simibubi.create.content.equipment.toolbox.ToolboxHandler; import com.simibubi.create.content.equipment.wrench.WrenchItem; import com.simibubi.create.content.equipment.zapper.ZapperInteractionHandler; @@ -39,7 +38,6 @@ import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; import net.minecraftforge.event.AddPackFindersEvent; import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.event.OnDatapackSyncEvent; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.TickEvent.LevelTickEvent; import net.minecraftforge.event.TickEvent.Phase; @@ -143,20 +141,9 @@ public class CommonEvents { @SubscribeEvent public static void addReloadListeners(AddReloadListenerEvent event) { event.addListener(RecipeFinder.LISTENER); - event.addListener(PotatoProjectileTypeManager.ReloadListener.INSTANCE); event.addListener(BeltHelper.LISTENER); } - @SubscribeEvent - public static void onDatapackSync(OnDatapackSyncEvent event) { - ServerPlayer player = event.getPlayer(); - if (player != null) { - PotatoProjectileTypeManager.syncTo(player); - } else { - PotatoProjectileTypeManager.syncToAll(); - } - } - @SubscribeEvent public static void serverStopping(ServerStoppingEvent event) { Create.SCHEMATIC_RECEIVER.shutdown(); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/PlayerMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/PlayerMixin.java index 4eec0a0956..f22f6131c7 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/PlayerMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/PlayerMixin.java @@ -5,6 +5,7 @@ import org.spongepowered.asm.mixin.injection.At; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.simibubi.create.content.contraptions.AbstractContraptionEntity; +import com.simibubi.create.infrastructure.config.AllConfigs; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -26,7 +27,8 @@ public abstract class PlayerMixin extends LivingEntity { ) private boolean pretendNotPassenger(boolean isPassenger) { // avoid touching all items in the contraption's massive hitbox - if (isPassenger && this.getVehicle() instanceof AbstractContraptionEntity) { + boolean shouldSync = AllConfigs.server().kinetics.syncPlayerPickupHitboxWithContraptionHitbox.get(); + if (isPassenger && !shouldSync && this.getVehicle() instanceof AbstractContraptionEntity) { return false; } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/MobEffectInstanceAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/MobEffectInstanceAccessor.java new file mode 100644 index 0000000000..da9d9a6ef6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/MobEffectInstanceAccessor.java @@ -0,0 +1,12 @@ +package com.simibubi.create.foundation.mixin.accessor; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.world.effect.MobEffectInstance; + +@Mixin(MobEffectInstance.class) +public interface MobEffectInstanceAccessor { + @Accessor("hiddenEffect") + MobEffectInstance create$getHiddenEffect(); +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/accessor/SuspiciousStewItemAccessor.java b/src/main/java/com/simibubi/create/foundation/mixin/accessor/SuspiciousStewItemAccessor.java new file mode 100644 index 0000000000..9586e69ed9 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/accessor/SuspiciousStewItemAccessor.java @@ -0,0 +1,18 @@ +package com.simibubi.create.foundation.mixin.accessor; + +import java.util.function.Consumer; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SuspiciousStewItem; + +@Mixin(SuspiciousStewItem.class) +public interface SuspiciousStewItemAccessor { + @Invoker("listPotionEffects") + static void create$listPotionEffects(ItemStack stack, Consumer output) { + throw new AssertionError(); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/CreateCodecs.java b/src/main/java/com/simibubi/create/foundation/utility/CreateCodecs.java index c912a8858e..dabca29a7d 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/CreateCodecs.java +++ b/src/main/java/com/simibubi/create/foundation/utility/CreateCodecs.java @@ -1,10 +1,30 @@ package com.simibubi.create.foundation.utility; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Stream; + +import com.google.common.base.Suppliers; +import com.google.common.primitives.UnsignedBytes; +import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.MapLike; +import com.mojang.serialization.RecordBuilder; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.foundation.item.ItemSlots; +import com.simibubi.create.foundation.mixin.accessor.MobEffectInstanceAccessor; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffectInstance.FactorData; +import net.minecraft.world.food.FoodProperties; import net.minecraftforge.items.ItemStackHandler; @@ -30,4 +50,117 @@ public class CreateCodecs { i -> i >= min ? DataResult.success(i) : DataResult.error(() -> "Value under minimum of " + min) ); } + + public static final Codec NON_NEGATIVE_DOUBLE = doubleRangeWithMessage(0, Double.MAX_VALUE, + i -> "Value must be non-negative: " + i); + public static final Codec POSITIVE_DOUBLE = doubleRangeWithMessage(1, Double.MAX_VALUE, + i -> "Value must be positive: " + i); + + private static Codec doubleRangeWithMessage(double min, double max, Function errorMessage) { + return ExtraCodecs.validate(Codec.DOUBLE, i -> + i.compareTo(min) >= 0 && i.compareTo(max) <= 0 ? DataResult.success(i) : DataResult.error(() -> + errorMessage.apply(i) + ) + ); + } + + public static final Codec UNSIGNED_BYTE = Codec.BYTE + .flatComapMap( + UnsignedBytes::toInt, + p_324632_ -> p_324632_ > 255 + ? DataResult.error(() -> "Unsigned byte was too large: " + p_324632_ + " > 255") + : DataResult.success(p_324632_.byteValue()) + ); + + public static final MapCodec MOB_EFFECT_INSTANCE = recursive( + "MobEffectInstance", + codec -> RecordCodecBuilder.mapCodec( + instance -> instance.group( + BuiltInRegistries.MOB_EFFECT.byNameCodec().fieldOf("effect").forGetter(MobEffectInstance::getEffect), + Codec.INT.optionalFieldOf("duration", 0).forGetter(MobEffectInstance::getDuration), + UNSIGNED_BYTE.optionalFieldOf("amplifier", 0).forGetter(MobEffectInstance::getAmplifier), + Codec.BOOL.optionalFieldOf("ambient", false).forGetter(MobEffectInstance::isAmbient), + Codec.BOOL.optionalFieldOf("show_particles", true).forGetter(MobEffectInstance::isVisible), + Codec.BOOL.optionalFieldOf("show_icon", true).forGetter(MobEffectInstance::showIcon), + codec.optionalFieldOf("hidden_effect").forGetter(i -> Optional.ofNullable(((MobEffectInstanceAccessor) i).create$getHiddenEffect())), + FactorData.CODEC.optionalFieldOf("factor_data").forGetter(MobEffectInstance::getFactorData) + ) + .apply(instance, (effect, duration, amplifier, isAmbient, showParticles, showIcon, hiddenEffect, factorData) -> + new MobEffectInstance(effect, duration, amplifier, isAmbient, showParticles, showIcon, hiddenEffect.orElse(null), factorData)) + ) + ); + + public static final Codec FOOD_PROPERTIES = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.NON_NEGATIVE_INT.fieldOf("nutrition").forGetter(FoodProperties::getNutrition), + Codec.FLOAT.fieldOf("saturation_modifier").forGetter(FoodProperties::getSaturationModifier), + Codec.BOOL.optionalFieldOf("is_meat", false).forGetter(FoodProperties::isMeat), + Codec.BOOL.optionalFieldOf("can_always_eat", false).forGetter(FoodProperties::canAlwaysEat), + Codec.BOOL.optionalFieldOf("is_fast_food", false).forGetter(FoodProperties::isFastFood), + FoodEffect.CODEC.listOf().optionalFieldOf("effects", List.of()).forGetter(i -> { + List effects = new ArrayList<>(); + for (Pair pair : i.getEffects()) + effects.add(new FoodEffect(pair.getFirst(), pair.getSecond())); + return effects; + }) + ).apply(instance, (nutrition, saturationModifier, isMeat, canAlwaysEat, isFastFood, effects) -> { + FoodProperties.Builder builder = new FoodProperties.Builder() + .nutrition(nutrition) + .saturationMod(saturationModifier); + + if (isMeat) builder.meat(); + if (canAlwaysEat) builder.alwaysEat(); + if (isFastFood) builder.fast(); + for (FoodEffect effect : effects) builder.effect(effect.effectSupplier(), effect.probability()); + + return builder.build(); + })); + + public record FoodEffect(Supplier effectSupplier, float probability) { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + MOB_EFFECT_INSTANCE.fieldOf("effect").forGetter(FoodEffect::effect), + Codec.FLOAT.fieldOf("probability").forGetter(FoodEffect::probability) + ).apply(instance, FoodEffect::new)); + + private FoodEffect(MobEffectInstance effect, float probability) { + this(() -> effect, probability); + } + + public MobEffectInstance effect() { + return new MobEffectInstance(this.effectSupplier.get()); + } + } + + public static MapCodec recursive(final String name, final Function, MapCodec> wrapped) { + return new RecursiveMapCodec<>(name, wrapped); + } + + private static class RecursiveMapCodec extends MapCodec { + private final String name; + private final Supplier> wrapped; + + private RecursiveMapCodec(final String name, final Function, MapCodec> wrapped) { + this.name = name; + this.wrapped = Suppliers.memoize(() -> wrapped.apply(codec())); + } + + @Override + public RecordBuilder encode(final A input, final DynamicOps ops, final RecordBuilder prefix) { + return wrapped.get().encode(input, ops, prefix); + } + + @Override + public DataResult decode(final DynamicOps ops, final MapLike input) { + return wrapped.get().decode(ops, input); + } + + @Override + public Stream keys(final DynamicOps ops) { + return wrapped.get().keys(ops); + } + + @Override + public String toString() { + return "RecursiveMapCodec[" + name + ']'; + } + } } diff --git a/src/main/java/com/simibubi/create/infrastructure/config/CKinetics.java b/src/main/java/com/simibubi/create/infrastructure/config/CKinetics.java index 39e6cb2d0d..b661ea3f84 100644 --- a/src/main/java/com/simibubi/create/infrastructure/config/CKinetics.java +++ b/src/main/java/com/simibubi/create/infrastructure/config/CKinetics.java @@ -51,6 +51,7 @@ public class CKinetics extends ConfigBase { public final ConfigBool minecartContraptionInContainers = b(false, "minecartContraptionInContainers", Comments.minecartContraptionInContainers); public final ConfigBool stabiliseStableContraptions = b(false, "stabiliseStableContraptions", Comments.stabiliseStableContraptions, "[Technical]"); + public final ConfigBool syncPlayerPickupHitboxWithContraptionHitbox = b(false, "syncPlayerPickupHitboxWithContraptionHitbox", Comments.syncPlayerPickupHitboxWithContraptionHitbox, "[Technical]"); public final ConfigGroup stats = group(1, "stats", Comments.stats); public final ConfigFloat mediumSpeed = f(30, 0, 4096, "mediumSpeed", Comments.rpm, Comments.mediumSpeed); @@ -120,6 +121,7 @@ public class CKinetics extends ConfigBase { static String reinforcedDeepslateMovement = "Configure how Reinforced Deepslate blocks can be moved by contraptions."; static String minecartContraptionInContainers = "Whether minecart contraptions can be placed into container items."; static String stabiliseStableContraptions = "Whether stabilised bearings create a separated entity even on non-rotating contraptions."; + static String syncPlayerPickupHitboxWithContraptionHitbox = "Whether the players hitbox should be expanded to the size of the contraption hitbox."; } public enum DeployerAggroSetting { diff --git a/src/main/java/com/simibubi/create/infrastructure/data/GeneratedEntriesProvider.java b/src/main/java/com/simibubi/create/infrastructure/data/GeneratedEntriesProvider.java index 421b39be30..93c765d1ee 100644 --- a/src/main/java/com/simibubi/create/infrastructure/data/GeneratedEntriesProvider.java +++ b/src/main/java/com/simibubi/create/infrastructure/data/GeneratedEntriesProvider.java @@ -5,25 +5,27 @@ import java.util.concurrent.CompletableFuture; import com.simibubi.create.AllDamageTypes; import com.simibubi.create.Create; +import com.simibubi.create.api.registry.CreateRegistries; +import com.simibubi.create.content.equipment.potatoCannon.AllPotatoProjectileTypes; import com.simibubi.create.infrastructure.worldgen.AllBiomeModifiers; import com.simibubi.create.infrastructure.worldgen.AllConfiguredFeatures; import com.simibubi.create.infrastructure.worldgen.AllPlacedFeatures; import net.minecraft.core.HolderLookup; import net.minecraft.core.RegistrySetBuilder; -import net.minecraft.core.RegistrySetBuilder.RegistryBootstrap; import net.minecraft.core.registries.Registries; import net.minecraft.data.PackOutput; + import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; import net.minecraftforge.registries.ForgeRegistries; public class GeneratedEntriesProvider extends DatapackBuiltinEntriesProvider { - @SuppressWarnings({ "rawtypes", "unchecked" }) private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder() - .add(Registries.DAMAGE_TYPE, AllDamageTypes::bootstrap) - .add(Registries.CONFIGURED_FEATURE, (RegistryBootstrap) AllConfiguredFeatures::bootstrap) - .add(Registries.PLACED_FEATURE, AllPlacedFeatures::bootstrap) - .add(ForgeRegistries.Keys.BIOME_MODIFIERS, AllBiomeModifiers::bootstrap); + .add(Registries.DAMAGE_TYPE, AllDamageTypes::bootstrap) + .add(Registries.CONFIGURED_FEATURE, AllConfiguredFeatures::bootstrap) + .add(Registries.PLACED_FEATURE, AllPlacedFeatures::bootstrap) + .add(ForgeRegistries.Keys.BIOME_MODIFIERS, AllBiomeModifiers::bootstrap) + .add(CreateRegistries.POTATO_PROJECTILE_TYPE, AllPotatoProjectileTypes::bootstrap); public GeneratedEntriesProvider(PackOutput output, CompletableFuture registries) { super(output, registries, BUILDER, Set.of(Create.ID)); diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 1fa07fdd31..e1d26393bd 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -31,9 +31,11 @@ "accessor.GameTestHelperAccessor", "accessor.ItemModelGeneratorsAccessor", "accessor.LivingEntityAccessor", + "accessor.MobEffectInstanceAccessor", "accessor.NbtAccounterAccessor", "accessor.ServerLevelAccessor", "accessor.StateHolderAccessor", + "accessor.SuspiciousStewItemAccessor", "accessor.SystemReportAccessor", "accessor.UseOnContextAccessor" ],