From f36d33402621fe1c91aebac81f0385385729271a Mon Sep 17 00:00:00 2001 From: MerchantBob <122754743+MerchantBob@users.noreply.github.com> Date: Sat, 26 Aug 2023 18:43:25 +0400 Subject: [PATCH] POLISHING WHEEL --- build.gradle | 1 - gradle.properties | 26 +-- .../java/com/example/modid/ExampleMod.java | 30 --- .../example/modid/mixin/MinecraftMixin.java | 20 -- .../create_so/CreateSandpaperOverhaul.java | 46 +++++ .../ghasto/create_so/ModBlockEntities.java | 26 +++ .../java/com/ghasto/create_so/ModBlocks.java | 46 +++++ .../java/com/ghasto/create_so/ModItems.java | 5 + .../com/ghasto/create_so/ModRecipeTypes.java | 109 ++++++++++ .../polishing_wheel/PolishingRecipe.java | 26 +++ .../polishing_wheel/PolishingWheelBlock.java | 194 ++++++++++++++++++ .../PolishingWheelBlockEntity.java | 72 +++++++ .../PolishingWheelControllerBlock.java | 186 +++++++++++++++++ .../PolishingWheelControllerBlockEntity.java | 39 ++++ ...odid.mixins.json => create_so.mixins.json} | 3 +- src/main/resources/fabric.mod.json | 13 +- 16 files changed, 768 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/com/example/modid/ExampleMod.java delete mode 100644 src/main/java/com/example/modid/mixin/MinecraftMixin.java create mode 100644 src/main/java/com/ghasto/create_so/CreateSandpaperOverhaul.java create mode 100644 src/main/java/com/ghasto/create_so/ModBlockEntities.java create mode 100644 src/main/java/com/ghasto/create_so/ModBlocks.java create mode 100644 src/main/java/com/ghasto/create_so/ModItems.java create mode 100644 src/main/java/com/ghasto/create_so/ModRecipeTypes.java create mode 100644 src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingRecipe.java create mode 100644 src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlock.java create mode 100644 src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlockEntity.java create mode 100644 src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlock.java create mode 100644 src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlockEntity.java rename src/main/resources/{modid.mixins.json => create_so.mixins.json} (73%) diff --git a/build.gradle b/build.gradle index 83eb556..5c6cf42 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,6 @@ version = "${mod_version}+${minecraft_version}" + (buildNumber != null ? "-${bui repositories { maven { url = "https://maven.shedaniel.me/" } // Cloth Config, REI - maven { url = "https://dvs1.progwml6.com/files/maven/" } // JEI maven { url = "https://maven.parchmentmc.org" } // Parchment mappings maven { url = "https://maven.quiltmc.org/repository/release" } // Quilt Mappings maven { url = "https://api.modrinth.com/maven" } // LazyDFU diff --git a/gradle.properties b/gradle.properties index c3ed695..e51df92 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,26 +1,26 @@ org.gradle.jvmargs=-Xmx2G # Mod Info -maven_group = com.example -archives_base_name = modid -mod_version = 0.0.1 +maven_group = com.ghasto +archives_base_name = create_so +mod_version = 1.6 -minecraft_version = 1.18.2 +minecraft_version = 1.20.1 # Dependencies # https://fabricmc.net/develop -fabric_loader_version = 0.14.11 -fabric_api_version = 0.67.0+1.18.2 +fabric_loader_version = 0.14.22 +fabric_api_version = 0.87.0+1.20.1 # Mappings # https://lambdaurora.dev/tools/import_quilt.html -qm_version = 26 +qm_version = 23 # https://parchmentmc.org/docs/getting-started -parchment_version = 2022.11.06 +parchment_version = 2023.08.20 # Create # https://modrinth.com/mod/create-fabric/versions -create_version = 0.5.0.i-944+1.18.2 +create_version = 0.5.1-d-build.1161+mc1.20.1 # Development QOL # Create supports all 3 recipe viewers: JEI, REI, and EMI. This decides which is enabled at runtime. @@ -29,11 +29,11 @@ recipe_viewer = unspecified # JEI - https://www.curseforge.com/minecraft/mc-mods/jei/files/all jei_version = 10.2.1.283 # REI - https://modrinth.com/mod/roughly-enough-items/versions -rei_version = 8.3.583 +rei_version = 12.0.645 # EMI - https://modrinth.com/mod/emi/versions -emi_version = 0.5.3+1.18.2 +emi_version = 1.0.19+1.20.1+fabric # Mod Menu - https://modrinth.com/mod/modmenu/versions -modmenu_version = 3.2.5 +modmenu_version = 7.2.1 # LazyDFU - https://modrinth.com/mod/lazydfu/versions -lazydfu_version = 0.1.2 +lazydfu_version = 0.1.3 diff --git a/src/main/java/com/example/modid/ExampleMod.java b/src/main/java/com/example/modid/ExampleMod.java deleted file mode 100644 index a397b66..0000000 --- a/src/main/java/com/example/modid/ExampleMod.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.example.modid; - -import com.simibubi.create.Create; - -import io.github.fabricators_of_create.porting_lib.util.EnvExecutor; -import net.fabricmc.api.ModInitializer; - -import net.minecraft.resources.ResourceLocation; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExampleMod implements ModInitializer { - public static final String ID = "modid"; - public static final String NAME = "Example Mod"; - public static final Logger LOGGER = LoggerFactory.getLogger(NAME); - - @Override - public void onInitialize() { - LOGGER.info("Create addon mod [{}] is loading alongside Create [{}]!", NAME, Create.VERSION); - LOGGER.info(EnvExecutor.unsafeRunForDist( - () -> () -> "{} is accessing Porting Lib from the client!", - () -> () -> "{} is accessing Porting Lib from the server!" - ), NAME); - } - - public static ResourceLocation id(String path) { - return new ResourceLocation(ID, path); - } -} diff --git a/src/main/java/com/example/modid/mixin/MinecraftMixin.java b/src/main/java/com/example/modid/mixin/MinecraftMixin.java deleted file mode 100644 index 9c20155..0000000 --- a/src/main/java/com/example/modid/mixin/MinecraftMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.modid.mixin; - -import com.example.modid.ExampleMod; - -import net.minecraft.client.Minecraft; - -import net.minecraft.client.main.GameConfig; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Minecraft.class) -public class MinecraftMixin { - @Inject(method = "", at = @At("TAIL")) - private void example$init(GameConfig gameConfig, CallbackInfo ci) { - ExampleMod.LOGGER.info("Hello from {}", ExampleMod.NAME); - } -} diff --git a/src/main/java/com/ghasto/create_so/CreateSandpaperOverhaul.java b/src/main/java/com/ghasto/create_so/CreateSandpaperOverhaul.java new file mode 100644 index 0000000..76fdddb --- /dev/null +++ b/src/main/java/com/ghasto/create_so/CreateSandpaperOverhaul.java @@ -0,0 +1,46 @@ +package com.ghasto.create_so; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.simibubi.create.AllItems; +import com.simibubi.create.Create; +import com.simibubi.create.foundation.data.CreateRegistrate; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; + +public class CreateSandpaperOverhaul implements ModInitializer{ + public static final String ID = "create_so"; + public static final String NAME = "Create: Sandpaper Overhaul"; + public static final Logger LOGGER = LoggerFactory.getLogger(NAME); + public static final CreateRegistrate REGISTRATE = CreateRegistrate.create(ID); + public static final CreativeModeTab TAB = FabricItemGroup.builder() + .title(Component.literal(NAME)) + .icon(AllItems.RED_SAND_PAPER::asStack) + .displayItems((c,p) -> { + REGISTRATE.getAll(Registries.ITEM).forEach(e -> { + p.accept(e.get()); + }); + }) + .build(); + + @Override + public void onInitialize() { + ModItems.register(); + ModBlocks.register(); + ModBlockEntities.register(); + ModRecipeTypes.register(); + REGISTRATE.simple("tab", Registries.CREATIVE_MODE_TAB, () -> TAB); + REGISTRATE.register(); + LOGGER.info("{} is loading alongside Create {}!", NAME, Create.VERSION); + } + + public static ResourceLocation id(String path) { + return new ResourceLocation(ID, path); + } +} diff --git a/src/main/java/com/ghasto/create_so/ModBlockEntities.java b/src/main/java/com/ghasto/create_so/ModBlockEntities.java new file mode 100644 index 0000000..696c423 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/ModBlockEntities.java @@ -0,0 +1,26 @@ +package com.ghasto.create_so; + +import static com.ghasto.create_so.CreateSandpaperOverhaul.REGISTRATE; + +import com.ghasto.create_so.content.polishing_wheel.PolishingWheelBlockEntity; +import com.ghasto.create_so.content.polishing_wheel.PolishingWheelControllerBlockEntity; +import com.simibubi.create.content.kinetics.base.CutoutRotatingInstance; +import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer; +import com.tterrag.registrate.util.entry.BlockEntityEntry; + +public class ModBlockEntities { + public static final BlockEntityEntry POLISHING_WHEEL = REGISTRATE + .blockEntity("polishing_wheel", PolishingWheelBlockEntity::new) + .instance(() -> CutoutRotatingInstance::new, false) + .validBlocks(ModBlocks.POLISHING_WHEEL) + .renderer(() -> KineticBlockEntityRenderer::new) + .register(); + + public static final BlockEntityEntry POLISHING_WHEEL_CONTROLLER = + REGISTRATE + .blockEntity("crushing_wheel_controller", PolishingWheelControllerBlockEntity::new) + .validBlocks(ModBlocks.POLISHING_WHEEL_CONTROLLER) + // .renderer(() -> renderer) + .register(); + public static void register() {} +} diff --git a/src/main/java/com/ghasto/create_so/ModBlocks.java b/src/main/java/com/ghasto/create_so/ModBlocks.java new file mode 100644 index 0000000..8c155d8 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/ModBlocks.java @@ -0,0 +1,46 @@ +package com.ghasto.create_so; + +import static com.ghasto.create_so.CreateSandpaperOverhaul.REGISTRATE; +import static com.simibubi.create.foundation.data.ModelGen.customItemModel; +import static com.simibubi.create.foundation.data.TagGen.pickaxeOnly; + +import com.ghasto.create_so.content.polishing_wheel.PolishingWheelBlock; +import com.ghasto.create_so.content.polishing_wheel.PolishingWheelControllerBlock; +import com.simibubi.create.content.kinetics.BlockStressDefaults; +import com.simibubi.create.foundation.data.AssetLookup; +import com.simibubi.create.foundation.data.BlockStateGen; +import com.simibubi.create.foundation.data.SharedProperties; +import com.tterrag.registrate.util.entry.BlockEntry; + +import net.minecraft.client.renderer.RenderType; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.world.level.material.PushReaction; + +public class ModBlocks { + public static final BlockEntry POLISHING_WHEEL = + REGISTRATE.block("crushing_wheel", PolishingWheelBlock::new) + .properties(p -> p.mapColor(MapColor.METAL)) + .initialProperties(SharedProperties::stone) + .properties(BlockBehaviour.Properties::noOcclusion) + .transform(pickaxeOnly()) + .blockstate((c, p) -> BlockStateGen.axisBlock(c, p, s -> AssetLookup.partialBaseModel(c, p))) + .addLayer(() -> RenderType::cutoutMipped) + .transform(BlockStressDefaults.setImpact(12.0)) + .item() + .transform(customItemModel()) + .register(); + + public static final BlockEntry POLISHING_WHEEL_CONTROLLER = + REGISTRATE.block("crushing_wheel_controller", PolishingWheelControllerBlock::new) + .properties(p -> p.mapColor(MapColor.STONE) + .noOcclusion() + .noLootTable() + .air() + .noCollission() + .pushReaction(PushReaction.BLOCK)) + .blockstate((c, p) -> p.getVariantBuilder(c.get()) + .forAllStatesExcept(BlockStateGen.mapToAir(p), PolishingWheelControllerBlock.FACING)) + .register(); + public static void register() {} +} diff --git a/src/main/java/com/ghasto/create_so/ModItems.java b/src/main/java/com/ghasto/create_so/ModItems.java new file mode 100644 index 0000000..b534b41 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/ModItems.java @@ -0,0 +1,5 @@ +package com.ghasto.create_so; + +public class ModItems { + public static void register() {} +} diff --git a/src/main/java/com/ghasto/create_so/ModRecipeTypes.java b/src/main/java/com/ghasto/create_so/ModRecipeTypes.java new file mode 100644 index 0000000..0de779c --- /dev/null +++ b/src/main/java/com/ghasto/create_so/ModRecipeTypes.java @@ -0,0 +1,109 @@ +package com.ghasto.create_so; + +import java.util.Optional; +import java.util.Set; +import java.util.function.Supplier; + +import org.jetbrains.annotations.Nullable; + +import com.ghasto.create_so.content.polishing_wheel.PolishingRecipe; +import com.google.common.collect.ImmutableSet; +import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder; +import com.simibubi.create.content.processing.recipe.ProcessingRecipeSerializer; +import com.simibubi.create.foundation.recipe.IRecipeTypeInfo; +import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.RegisteredObjects; + +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; + +public enum ModRecipeTypes implements IRecipeTypeInfo { + + POLISHING(PolishingRecipe::new); + + private final ResourceLocation id; + private final RecipeSerializer serializerObject; + @Nullable + private final RecipeType typeObject; + private final Supplier> type; + + ModRecipeTypes(Supplier> serializerSupplier, Supplier> typeSupplier, boolean registerType) { + String name = Lang.asId(name()); + id = CreateSandpaperOverhaul.id(name); + serializerObject = Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, id, serializerSupplier.get()); + if (registerType) { + typeObject = typeSupplier.get(); + Registry.register(BuiltInRegistries.RECIPE_TYPE, id, typeObject); + type = typeSupplier; + } else { + typeObject = null; + type = typeSupplier; + } + } + + ModRecipeTypes(Supplier> serializerSupplier) { + String name = Lang.asId(name()); + id = CreateSandpaperOverhaul.id(name); + serializerObject = Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, id, serializerSupplier.get()); + typeObject = simpleType(id); + Registry.register(BuiltInRegistries.RECIPE_TYPE, id, typeObject); + type = () -> typeObject; + } + + ModRecipeTypes(ProcessingRecipeBuilder.ProcessingRecipeFactory processingFactory) { + this(() -> new ProcessingRecipeSerializer<>(processingFactory)); + } + + public static > RecipeType simpleType(ResourceLocation id) { + String stringId = id.toString(); + return new RecipeType() { + @Override + public String toString() { + return stringId; + } + }; + } + + public static void register() { + } + + @Override + public ResourceLocation getId() { + return id; + } + + @SuppressWarnings("unchecked") + @Override + public > T getSerializer() { + return (T) serializerObject; + } + + @SuppressWarnings("unchecked") + @Override + public > T getType() { + return (T) type.get(); + } + + public > Optional find(C inv, Level world) { + return world.getRecipeManager() + .getRecipeFor(getType(), inv, world); + } + + public static final Set RECIPE_DENY_SET = + ImmutableSet.of(new ResourceLocation("occultism", "spirit_trade"), new ResourceLocation("occultism", "ritual")); + + public static boolean shouldIgnoreInAutomation(Recipe recipe) { + RecipeSerializer serializer = recipe.getSerializer(); + if (serializer != null && RECIPE_DENY_SET.contains(RegisteredObjects.getKeyOrThrow(serializer))) + return true; + return recipe.getId() + .getPath() + .endsWith("_manual_only"); + } +} diff --git a/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingRecipe.java b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingRecipe.java new file mode 100644 index 0000000..abd47ae --- /dev/null +++ b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingRecipe.java @@ -0,0 +1,26 @@ +package com.ghasto.create_so.content.polishing_wheel; + +import com.ghasto.create_so.ModRecipeTypes; +import com.simibubi.create.content.kinetics.crusher.AbstractCrushingRecipe; +import com.simibubi.create.content.processing.recipe.ProcessingRecipeBuilder; + +import net.minecraft.world.Container; +import net.minecraft.world.level.Level; + +public class PolishingRecipe extends AbstractCrushingRecipe { + public PolishingRecipe(ProcessingRecipeBuilder.ProcessingRecipeParams params) { + super(ModRecipeTypes.POLISHING, params); + } + @Override + public boolean matches(Container inv, Level worldIn) { + if (inv.isEmpty()) + return false; + return ingredients.get(0) + .test(inv.getItem(0)); + } + + @Override + protected int getMaxOutputCount() { + return 64; + } +} diff --git a/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlock.java b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlock.java new file mode 100644 index 0000000..592fd94 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlock.java @@ -0,0 +1,194 @@ +package com.ghasto.create_so.content.polishing_wheel; + +import static com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlock.VALID; + +import com.ghasto.create_so.ModBlockEntities; +import com.ghasto.create_so.ModBlocks; +import com.simibubi.create.AllShapes; +import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock; +import com.simibubi.create.foundation.block.IBE; +import com.simibubi.create.foundation.utility.Iterate; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class PolishingWheelBlock extends RotatedPillarKineticBlock implements IBE{ + + public PolishingWheelBlock(Properties properties) { + super(properties); + } + + @Override + public Direction.Axis getRotationAxis(BlockState state) { + return state.getValue(AXIS); + } + + @Override + public RenderShape getRenderShape(BlockState state) { + return RenderShape.ENTITYBLOCK_ANIMATED; + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + return AllShapes.CRUSHING_WHEEL_COLLISION_SHAPE; + } + + @Override + public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { + for (Direction d : Iterate.directions) { + if (d.getAxis() == state.getValue(AXIS)) + continue; + if (ModBlocks.POLISHING_WHEEL_CONTROLLER.has(worldIn.getBlockState(pos.relative(d)))) + worldIn.removeBlock(pos.relative(d), isMoving); + } + + super.onRemove(state, worldIn, pos, newState, isMoving); + } + + public void updateControllers(BlockState state, Level world, BlockPos pos, Direction side) { + if (side.getAxis() == state.getValue(AXIS)) + return; + if (world == null) + return; + + BlockPos controllerPos = pos.relative(side); + BlockPos otherWheelPos = pos.relative(side, 2); + + boolean controllerExists = ModBlocks.POLISHING_WHEEL_CONTROLLER.has(world.getBlockState(controllerPos)); + boolean controllerIsValid = controllerExists && world.getBlockState(controllerPos) + .getValue(VALID); + Direction controllerOldDirection = controllerExists ? world.getBlockState(controllerPos) + .getValue(PolishingWheelControllerBlock.FACING) : null; + + boolean controllerShouldExist = false; + boolean controllerShouldBeValid = false; + Direction controllerNewDirection = Direction.DOWN; + + BlockState otherState = world.getBlockState(otherWheelPos); + if (ModBlocks.POLISHING_WHEEL.has(otherState)) { + controllerShouldExist = true; + + PolishingWheelBlockEntity be = getBlockEntity(world, pos); + PolishingWheelBlockEntity otherBE = getBlockEntity(world, otherWheelPos); + + if (be != null && otherBE != null && (be.getSpeed() > 0) != (otherBE.getSpeed() > 0) + && be.getSpeed() != 0) { + Direction.Axis wheelAxis = state.getValue(AXIS); + Direction.Axis sideAxis = side.getAxis(); + int controllerADO = Math.round(Math.signum(be.getSpeed())) * side.getAxisDirection() + .getStep(); + Vec3 controllerDirVec = new Vec3(wheelAxis == Direction.Axis.X ? 1 : 0, wheelAxis == Direction.Axis.Y ? 1 : 0, + wheelAxis == Direction.Axis.Z ? 1 : 0).cross( + new Vec3(sideAxis == Direction.Axis.X ? 1 : 0, sideAxis == Direction.Axis.Y ? 1 : 0, sideAxis == Direction.Axis.Z ? 1 : 0)); + + controllerNewDirection = Direction.getNearest(controllerDirVec.x * controllerADO, + controllerDirVec.y * controllerADO, controllerDirVec.z * controllerADO); + + controllerShouldBeValid = true; + } + if (otherState.getValue(AXIS) != state.getValue(AXIS)) + controllerShouldExist = false; + } + + if (!controllerShouldExist) { + if (controllerExists) + world.setBlockAndUpdate(controllerPos, Blocks.AIR.defaultBlockState()); + return; + } + + if (!controllerExists) { + if (!world.getBlockState(controllerPos) + .canBeReplaced()) + return; + world.setBlockAndUpdate(controllerPos, ModBlocks.POLISHING_WHEEL_CONTROLLER.getDefaultState() + .setValue(VALID, controllerShouldBeValid) + .setValue(PolishingWheelControllerBlock.FACING, controllerNewDirection)); + } else if (controllerIsValid != controllerShouldBeValid || controllerOldDirection != controllerNewDirection) { + world.setBlockAndUpdate(controllerPos, world.getBlockState(controllerPos) + .setValue(VALID, controllerShouldBeValid) + .setValue(PolishingWheelControllerBlock.FACING, controllerNewDirection)); + } + + ((PolishingWheelControllerBlock) ModBlocks.POLISHING_WHEEL_CONTROLLER.get()) + .updateSpeed(world.getBlockState(controllerPos), world, controllerPos); + + } + + @Override + public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity entityIn) { + if (entityIn.getY() < pos.getY() + 1.25f || !entityIn.onGround()) + return; + + float speed = getBlockEntityOptional(worldIn, pos).map(PolishingWheelBlockEntity::getSpeed) + .orElse(0f); + + double x = 0; + double z = 0; + + if (state.getValue(AXIS) == Direction.Axis.X) { + z = speed / 20f; + x += (pos.getX() + .5f - entityIn.getX()) * .1f; + } + if (state.getValue(AXIS) == Direction.Axis.Z) { + x = speed / -20f; + z += (pos.getZ() + .5f - entityIn.getZ()) * .1f; + } + entityIn.setDeltaMovement(entityIn.getDeltaMovement() + .add(x, 0, z)); + } + + @Override + public boolean canSurvive(BlockState state, LevelReader worldIn, BlockPos pos) { + for (Direction direction : Iterate.directions) { + BlockPos neighbourPos = pos.relative(direction); + BlockState neighbourState = worldIn.getBlockState(neighbourPos); + Direction.Axis stateAxis = state.getValue(AXIS); + if (ModBlocks.POLISHING_WHEEL_CONTROLLER.has(neighbourState) && direction.getAxis() != stateAxis) + return false; + if (!ModBlocks.POLISHING_WHEEL.has(neighbourState)) + continue; + if (neighbourState.getValue(AXIS) != stateAxis || stateAxis != direction.getAxis()) + return false; + } + + return true; + } + + @Override + public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) { + return face.getAxis() == state.getValue(AXIS); + } + + @Override + public float getParticleTargetRadius() { + return 1.125f; + } + + @Override + public float getParticleInitialRadius() { + return 1f; + } + + @Override + public Class getBlockEntityClass() { + return PolishingWheelBlockEntity.class; + } + + @Override + public BlockEntityType getBlockEntityType() { + return ModBlockEntities.POLISHING_WHEEL.get(); + } + + +} diff --git a/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlockEntity.java b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlockEntity.java new file mode 100644 index 0000000..e2464d0 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelBlockEntity.java @@ -0,0 +1,72 @@ +package com.ghasto.create_so.content.polishing_wheel; + +import java.util.Collection; +import java.util.List; + +import com.simibubi.create.AllDamageTypes; +import com.simibubi.create.content.kinetics.base.KineticBlockEntity; +import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; +import com.simibubi.create.foundation.utility.Iterate; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; + +public class PolishingWheelBlockEntity extends KineticBlockEntity { + public PolishingWheelBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + setLazyTickRate(20); + } + + @Override + public void addBehaviours(List behaviours) { + super.addBehaviours(behaviours); + } + + @Override + public void onSpeedChanged(float prevSpeed) { + super.onSpeedChanged(prevSpeed); + fixControllers(); + } + + public void fixControllers() { + for (Direction d : Iterate.directions) + ((PolishingWheelBlock) getBlockState().getBlock()).updateControllers(getBlockState(), getLevel(), getBlockPos(), + d); + } + + @Override + protected AABB createRenderBoundingBox() { + return new AABB(worldPosition).inflate(1); + } + + @Override + public void lazyTick() { + super.lazyTick(); + fixControllers(); + } + + public static int crushingIsFortunate(DamageSource source, LivingEntity target, int currentLevel, boolean recentlyHit) { + if (!AllDamageTypes.CRUSH.is(source)) + return 0; + return 2; + } + + public static boolean handleCrushedMobDrops(LivingEntity target, DamageSource source, Collection drops, int lootingLevel, boolean recentlyHit) { + if (!AllDamageTypes.CRUSH.is(source)) + return false; + Vec3 outSpeed = Vec3.ZERO; + for (ItemEntity outputItem : drops) { + outputItem.setDeltaMovement(outSpeed); + } + return false; + } + +} + diff --git a/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlock.java b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlock.java new file mode 100644 index 0000000..6583ff2 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlock.java @@ -0,0 +1,186 @@ +package com.ghasto.create_so.content.polishing_wheel; + + +import com.ghasto.create_so.ModBlockEntities; +import com.ghasto.create_so.ModBlocks; +import com.simibubi.create.AllShapes; +import com.simibubi.create.foundation.block.IBE; +import com.simibubi.create.foundation.item.ItemHelper; +import com.simibubi.create.foundation.utility.Iterate; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.util.RandomSource; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +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.DirectionalBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.EntityCollisionContext; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class PolishingWheelControllerBlock extends DirectionalBlock implements IBE { + + public PolishingWheelControllerBlock(Properties p_i48440_1_) { + super(p_i48440_1_); + } + + public static final BooleanProperty VALID = BooleanProperty.create("valid"); + + @Override + public boolean canBeReplaced(BlockState state, BlockPlaceContext useContext) { + return false; + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(VALID); + builder.add(FACING); + super.createBlockStateDefinition(builder); + } + + public void entityInside(BlockState state, Level worldIn, BlockPos pos, Entity entityIn) { + if (!state.getValue(VALID)) + return; + + Direction facing = state.getValue(FACING); + Direction.Axis axis = facing.getAxis(); + + checkEntityForProcessing(worldIn, pos, entityIn); + + withBlockEntityDo(worldIn, pos, be -> { + if (be.processingEntity == entityIn) + + entityIn.makeStuckInBlock(state, new Vec3(axis == Direction.Axis.X ? (double) 0.05F : 0.25D, + axis == Direction.Axis.Y ? (double) 0.05F : 0.25D, axis == Direction.Axis.Z ? (double) 0.05F : 0.25D)); + }); + } + + public void checkEntityForProcessing(Level worldIn, BlockPos pos, Entity entityIn) { + PolishingWheelControllerBlockEntity be = getBlockEntity(worldIn, pos); + if (be == null) + return; + if (be.crushingspeed == 0) + return; + if (be.isOccupied()) + return; + boolean isPlayer = entityIn instanceof Player; + if (isPlayer && ((Player) entityIn).isCreative()) + return; + if (isPlayer && entityIn.level().getDifficulty() == Difficulty.PEACEFUL) + return; + + be.startCrushing(entityIn); + } + + @Override + public void updateEntityAfterFallOn(BlockGetter worldIn, Entity entityIn) { + super.updateEntityAfterFallOn(worldIn, entityIn); + // Moved to onEntityCollision to allow for omnidirectional input + } + + @Override + public void animateTick(BlockState stateIn, Level worldIn, BlockPos pos, RandomSource rand) { + if (!stateIn.getValue(VALID)) + return; + if (rand.nextInt(1) != 0) + return; + double d0 = (double) ((float) pos.getX() + rand.nextFloat()); + double d1 = (double) ((float) pos.getY() + rand.nextFloat()); + double d2 = (double) ((float) pos.getZ() + rand.nextFloat()); + worldIn.addParticle(ParticleTypes.CRIT, d0, d1, d2, 0.0D, 0.0D, 0.0D); + } + + @Override + public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, + BlockPos currentPos, BlockPos facingPos) { + updateSpeed(stateIn, worldIn, currentPos); + return stateIn; + } + + public void updateSpeed(BlockState state, LevelAccessor world, BlockPos pos) { + withBlockEntityDo(world, pos, be -> { + if (!state.getValue(VALID)) { + if (be.crushingspeed != 0) { + be.crushingspeed = 0; + be.sendData(); + } + return; + } + + for (Direction d : Iterate.directions) { + BlockState neighbour = world.getBlockState(pos.relative(d)); + if (!ModBlocks.POLISHING_WHEEL.has(neighbour)) + continue; + if (neighbour.getValue(BlockStateProperties.AXIS) == d.getAxis()) + continue; + BlockEntity adjBE = world.getBlockEntity(pos.relative(d)); + if (!(adjBE instanceof PolishingWheelBlockEntity cwbe)) + continue; + be.crushingspeed = Math.abs(cwbe.getSpeed() / 50f); + be.sendData(); + break; + } + }); + } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { + VoxelShape standardShape = AllShapes.CRUSHING_WHEEL_CONTROLLER_COLLISION.get(state.getValue(FACING)); + + if (!state.getValue(VALID)) + return standardShape; + if (!(context instanceof EntityCollisionContext)) + return standardShape; + Entity entity = ((EntityCollisionContext) context).getEntity(); + if (entity == null) + return standardShape; + + PolishingWheelControllerBlockEntity be = getBlockEntity(worldIn, pos); + if (be != null && be.processingEntity == entity) + return Shapes.empty(); + + return standardShape; + } + + @Override + public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { + if (!state.hasBlockEntity() || state.getBlock() == newState.getBlock()) + return; + + withBlockEntityDo(worldIn, pos, be -> ItemHelper.dropContents(worldIn, pos, be.inventory)); + worldIn.removeBlockEntity(pos); + } + + @Override + public Class getBlockEntityClass() { + return PolishingWheelControllerBlockEntity.class; + } + + @Override + public BlockEntityType getBlockEntityType() { + return ModBlockEntities.POLISHING_WHEEL_CONTROLLER.get(); + } + + @Override + public boolean isPathfindable(BlockState state, BlockGetter reader, BlockPos pos, PathComputationType type) { + return false; + } + +} + diff --git a/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlockEntity.java b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlockEntity.java new file mode 100644 index 0000000..1f8deb9 --- /dev/null +++ b/src/main/java/com/ghasto/create_so/content/polishing_wheel/PolishingWheelControllerBlockEntity.java @@ -0,0 +1,39 @@ +package com.ghasto.create_so.content.polishing_wheel; + +import java.util.List; +import java.util.Optional; + +import com.ghasto.create_so.ModRecipeTypes; +import com.simibubi.create.content.kinetics.belt.behaviour.DirectBeltInputBehaviour; +import com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlockEntity; +import com.simibubi.create.content.processing.recipe.ProcessingRecipe; +import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.Container; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; + +public class PolishingWheelControllerBlockEntity extends CrushingWheelControllerBlockEntity { + public PolishingWheelControllerBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + @Override + public Optional> findRecipe() { + return ModRecipeTypes.POLISHING.find(inventory, level); + } + + @Override + public void addBehaviours(List behaviours) { + behaviours.add(new DirectBeltInputBehaviour(this).onlyInsertWhen(this::supportsDirectBeltInput)); + } + private boolean supportsDirectBeltInput(Direction side) { + BlockState blockState = getBlockState(); + if (blockState == null) + return false; + Direction direction = blockState.getValue(PolishingWheelControllerBlock.FACING); + return direction == Direction.DOWN || direction == side; + } +} diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/create_so.mixins.json similarity index 73% rename from src/main/resources/modid.mixins.json rename to src/main/resources/create_so.mixins.json index 2d9cc32..8229c75 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/create_so.mixins.json @@ -1,12 +1,11 @@ { "required": true, "minVersion": "0.8", - "package": "com.example.modid.mixin", + "package": "com.ghasto.create_so.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ ], "client": [ - "MinecraftMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8b25c96..94fb0f7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,30 +1,27 @@ { "schemaVersion": 1, - "id": "modid", + "id": "create_so", "version": "${version}", - "name": "Example Mod", + "name": "Create: Sandpaper Overhaul", "description": "This is an example description! Tell everyone what your mod is about!", "authors": [ "Me!" ], - "contact": { - "sources": "https://github.com/Fabricators-of-Create/create-fabric-addon-template" - }, "license": "CC0", "icon": "assets/modid/icon.png", "environment": "*", "entrypoints": { "main": [ - "com.example.modid.ExampleMod" + "com.ghasto.create_so.CreateSandpaperOverhaul" ] }, "mixins": [ - "modid.mixins.json" + "create_so.mixins.json" ], "depends": { "fabricloader": ">=${fabric_loader_version}", "fabric-api": ">=${fabric_api_version}", - "create": "${create_version}", + "create": ">=${create_version}", "minecraft": "${minecraft_version}" } }