Skip to content

Commit

Permalink
Multiloadered!
Browse files Browse the repository at this point in the history
  • Loading branch information
cakeGit committed Aug 1, 2024
1 parent dbc1873 commit 7890c3c
Show file tree
Hide file tree
Showing 74 changed files with 2,490 additions and 171 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ architectury {
}

loom {
accessWidenerPath = file("src/main/resources/examplemod.accesswidener")
accessWidenerPath = file("src/main/resources/pattern_schematics.accesswidener")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.cak.pattern_schematics;

import com.cak.pattern_schematics.registry.PatternSchematicPackets;
import com.cak.pattern_schematics.registry.PatternSchematicsItems;
import com.cak.pattern_schematics.registry.PatternSchematicsLang;
import com.mojang.logging.LogUtils;
import com.simibubi.create.AllPackets;
import com.simibubi.create.foundation.data.CreateRegistrate;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
public class PatternSchematics {
// Define mod id in a common place for everything to reference
public static final String MODID = "create_pattern_schematics";
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();

public static void init() {
PatternSchematicsItems.register();
PatternSchematicPackets.registerPackets();
PatternSchematicsLang.register();
PatternSchematicPackets.getChannel().initServerListener();
}

public static ResourceLocation asResource(String loc) {
return new ResourceLocation(MODID, loc);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cak.pattern_schematics;

import com.cak.pattern_schematics.foundation.mirror.PatternSchematicHandler;
import com.cak.pattern_schematics.registry.PatternSchematicPackets;

public class PatternSchematicsClient {

/**Treat as final, the variable is initialised by platform*/
public static PatternSchematicHandler PATTERN_SCHEMATIC_HANDLER;

public static void init() {
PatternSchematicPackets.getChannel().initClientListener();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.cak.pattern_schematics;

import com.jozufozu.flywheel.event.RenderLayerEvent;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.foundation.render.SuperRenderTypeBuffer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.client.Minecraft;
import net.minecraft.world.phys.Vec3;

public class PatternSchematicsClientEvents {

public static void onTick() {
if (Minecraft.getInstance().level == null || Minecraft.getInstance().player == null)
return;
PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER.tick();
}

public static void renderPatternSchematic(PoseStack stack) {
stack.pushPose();

SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();

Vec3 camera = Minecraft.getInstance().gameRenderer.getMainCamera()
.getPosition();

PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER.render(stack, buffer, camera);

buffer.draw();
RenderSystem.enableCull();
stack.popPose();
}

public static void onKeyInput(int key, boolean pressed) {
PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER.onKeyInput(key, pressed);
}

public static boolean onMouseScrolled(double delta) {
if (Minecraft.getInstance().screen != null)
return false;

return PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER.mouseScrolled(delta);
}

public static boolean onMouseInput(int button, boolean pressed) {
if (Minecraft.getInstance().screen != null)
return false;

return PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER.onMouseInput(button, pressed);
}

//Todo: For foge
// @Mod.EventBusSubscriber(value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
// public static class ModBusEvents {
//
// @SubscribeEvent
// public static void registerGuiOverlays(RegisterGuiOverlaysEvent event) {
// event.registerAbove(VanillaGuiOverlay.HOTBAR.id(), "pattern_schematic", PatternSchematicsClient.PATTERN_SCHEMATIC_HANDLER);
// }
//
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cak.pattern_schematics;

import dev.architectury.injectables.annotations.ExpectPlatform;

public class PlatformGetter {

/**
* an example of {@link ExpectPlatform}.
* <p>
* This must be a <b>public static</b> method. The platform-implemented solution must be placed under a platform
* sub-package, with its class suffixed with {@code Impl}.
* <p>
* Example: Expect: net.examplemod.ExampleExpectPlatform#platformName() Actual Fabric:
* net.examplemod.fabric.ExampleExpectPlatformImpl#platformName() Actual Forge:
* net.examplemod.forge.ExampleExpectPlatformImpl#platformName()
* <p>
* <a href="https://plugins.jetbrains.com/plugin/16210-architectury">You should also get the IntelliJ plugin to help
* with @ExpectPlatform.</a>
*/
@ExpectPlatform
public static String platformName() {
// Just throw an error, the content should get replaced at runtime.
throw new AssertionError();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.cak.pattern_schematics.content;

import com.cak.pattern_schematics.registry.PatternSchematicsItems;
import com.simibubi.create.content.schematics.SchematicItem;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderGetter;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;

public class PatternSchematicItem extends SchematicItem {

public PatternSchematicItem(Properties properties) {
super(properties);
}

public static ItemStack create(HolderGetter<Block> lookup, String schematic, String owner) {
ItemStack blueprint = PatternSchematicsItems.PATTERN_SCHEMATIC.asStack();

CompoundTag tag = new CompoundTag();
tag.putBoolean("Deployed", false);
tag.putString("Owner", owner);
tag.putString("File", schematic);
tag.put("Anchor", NbtUtils.writeBlockPos(BlockPos.ZERO));
tag.putString("Rotation", Rotation.NONE.name());
tag.putString("Mirror", Mirror.NONE.name());
blueprint.setTag(tag);

writeSize(lookup, blueprint);
return blueprint;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.cak.pattern_schematics.content.packet;

import com.cak.pattern_schematics.foundation.util.Vec3iUtils;
import com.cak.pattern_schematics.registry.PatternSchematicsItems;
import com.simibubi.create.content.schematics.SchematicInstances;
import com.simibubi.create.foundation.networking.SimplePacketBase;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;

public class PatternSchematicSyncPacket extends SimplePacketBase {

public int slot;
public boolean deployed;
public BlockPos anchor;
public Rotation rotation;
public Mirror mirror;
public Vec3i cloneScaleMin, cloneScaleMax, cloneOffset;

public PatternSchematicSyncPacket(int slot, StructurePlaceSettings settings,
BlockPos anchor, boolean deployed,
Vec3i cloneScaleMin, Vec3i cloneScaleMax, Vec3i cloneOffset) {
this.slot = slot;
this.deployed = deployed;
this.anchor = anchor;
this.rotation = settings.getRotation();
this.mirror = settings.getMirror();
this.cloneScaleMin = cloneScaleMin;
this.cloneScaleMax = cloneScaleMax;
this.cloneOffset = cloneOffset;
}

public PatternSchematicSyncPacket(FriendlyByteBuf buffer) {
slot = buffer.readVarInt();
deployed = buffer.readBoolean();
anchor = buffer.readBlockPos();
rotation = buffer.readEnum(Rotation.class);
mirror = buffer.readEnum(Mirror.class);

this.cloneScaleMin = Vec3iUtils.unpackVec3i(buffer);
this.cloneScaleMax = Vec3iUtils.unpackVec3i(buffer);
this.cloneOffset = Vec3iUtils.unpackVec3i(buffer);
}

@Override
public void write(FriendlyByteBuf buffer) {
buffer.writeVarInt(slot);
buffer.writeBoolean(deployed);
buffer.writeBlockPos(anchor);
buffer.writeEnum(rotation);
buffer.writeEnum(mirror);

Vec3iUtils.packVec3i(cloneScaleMin, buffer);
Vec3iUtils.packVec3i(cloneScaleMax, buffer);
Vec3iUtils.packVec3i(cloneOffset, buffer);
}

@Override
public boolean handle(Context context) {
context.enqueueWork(() -> {
ServerPlayer player = context.getSender();
if (player == null)
return;
ItemStack stack = ItemStack.EMPTY;
if (slot == -1) {
stack = player.getMainHandItem();
} else {
stack = player.getInventory().getItem(slot);
}
if (!PatternSchematicsItems.PATTERN_SCHEMATIC.isIn(stack)) {
return;
}
CompoundTag tag = stack.getOrCreateTag();
tag.putBoolean("Deployed", deployed);
tag.put("Anchor", NbtUtils.writeBlockPos(anchor));
tag.putString("Rotation", rotation.name());
tag.putString("Mirror", mirror.name());

Vec3iUtils.putVec3i("CloneScaleMin", cloneScaleMin, tag);
Vec3iUtils.putVec3i("CloneScaleMax", cloneScaleMax, tag);
Vec3iUtils.putVec3i("CloneOffset", cloneOffset, tag);

SchematicInstances.clearHash(stack);
});
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.cak.pattern_schematics.foundation;

import com.cak.pattern_schematics.foundation.mirror.PatternSchematicHandler;
import com.simibubi.create.content.schematics.client.tools.SchematicToolBase;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.util.Mth;

public class CloneTool extends SchematicToolBase {

@Override
public boolean handleRightClick() {
return false;
}

@Override
public boolean handleMouseWheel(double delta) {
if (!schematicSelected)
return true;

if (!(schematicHandler instanceof PatternSchematicHandler patternSchematicHandler))
throw new RuntimeException("Clone tool bound in a normal SchematicHandler!");

boolean isPositive = selectedFace.getAxisDirection() == Direction.AxisDirection.POSITIVE;

Vec3i cloneScale;
if (isPositive)
cloneScale = patternSchematicHandler.getCloneScaleMax();
else
cloneScale = patternSchematicHandler.getCloneScaleMin();

cloneScale = cloneScale.relative(selectedFace, Mth.sign(delta));

if (isPositive)
patternSchematicHandler.setCloneScaleMax(cloneScale);
else
patternSchematicHandler.setCloneScaleMin(cloneScale);

schematicHandler.markDirty();
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cak.pattern_schematics.foundation;

import com.cak.pattern_schematics.foundation.mirror.PatternSchematicHandler;
import dev.architectury.injectables.annotations.ExpectPlatform;

public class PatternSchematicHandlerPlatformProvider {

@ExpectPlatform
public static PatternSchematicHandler getPlatformPatternSchematicHandler() {
throw new AssertionError();
}

}
Loading

0 comments on commit 7890c3c

Please sign in to comment.