Skip to content

Commit

Permalink
WIP 1.21.1 port before rebrand
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Dec 27, 2024
1 parent 67a7146 commit 02a8c26
Show file tree
Hide file tree
Showing 60 changed files with 3,313 additions and 209 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ loader_version_range=[4,)

# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=examplemod
mod_id=plonk
# The human-readable display name for the mod.
mod_name=Example Mod
mod_name=Plonk
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=1.0.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=com.example.examplemod
mod_group_id=
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=YourNameHere, OtherNameHere
mod_authors=Leclowndu93150, BlueAgent
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Example mod description.\nNewline characters can be used and will be replaced properly.
63 changes: 0 additions & 63 deletions src/main/java/com/example/examplemod/Config.java

This file was deleted.

136 changes: 0 additions & 136 deletions src/main/java/com/example/examplemod/ExampleMod.java

This file was deleted.

56 changes: 56 additions & 0 deletions src/main/java/com/portingdeadmods/plonk/Plonk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.portingdeadmods.plonk;

import com.portingdeadmods.plonk.client.ClientEvents;
import com.portingdeadmods.plonk.common.config.PlonkConfig;
import com.portingdeadmods.plonk.common.registry.RegistryBlocks;
import com.portingdeadmods.plonk.common.registry.RegistryItems;
import com.portingdeadmods.plonk.common.registry.RegistryPackets;
import com.portingdeadmods.plonk.common.registry.RegistryTileEntities;
import com.portingdeadmods.plonk.common.tag.PlonkTags;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.registries.RegisterEvent;

@Mod(Plonk.MOD_ID)
public class Plonk {
public static final String MOD_ID = "plonk";
public static final String NAME = "Plonk";
public static final String CARRY_ON_MOD_ID = "carryon";

private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(
new ResourceLocation(MOD_ID, "main"),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals
);

public Plonk(IEventBus modEventBus, ModContainer modContainer) {

modEventBus.addListener(this::onRegister);
modEventBus.addListener(this::setup);
modEventBus.addListener(PlonkConfig::refresh);

if (FMLEnvironment.dist.isClient()) {
ClientEvents.init(modEventBus);
}

modContainer.registerConfig(ModConfig.Type.SERVER, PlonkConfig.serverSpec);
PlonkTags.init();
}

public void onRegister(RegisterEvent event) {
event.register(Registries.BLOCK, RegistryBlocks::init);
event.register(Registries.ITEM, RegistryItems::init);
event.register(Registries.BLOCK_ENTITY_TYPE, RegistryTileEntities::init);
}

public void setup(FMLCommonSetupEvent event) {
RegistryPackets.init();
}
}
97 changes: 97 additions & 0 deletions src/main/java/com/portingdeadmods/plonk/client/ClientEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.portingdeadmods.plonk.client;

import com.portingdeadmods.plonk.Plonk;
import com.portingdeadmods.plonk.client.command.CommandClientPlonk;
import com.portingdeadmods.plonk.client.registry.RegistryTESRs;
import com.portingdeadmods.plonk.client.render.tile.TESRPlacedItems;
import com.portingdeadmods.plonk.common.packet.PacketPlaceItem;
import com.portingdeadmods.plonk.common.packet.PacketRotateTile;
import com.portingdeadmods.plonk.common.registry.RegistryItems;
import com.portingdeadmods.plonk.common.tile.TilePlacedItems;
import com.portingdeadmods.plonk.common.util.EntityUtils;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.neoforge.client.event.InputEvent;
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.server.ServerStartingEvent;

import static com.mojang.blaze3d.platform.InputConstants.Type.KEYSYM;
import static net.neoforged.neoforge.client.settings.KeyConflictContext.IN_GAME;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_P;

public class ClientEvents {
public static final KeyMapping KEY_PLACE = new KeyMapping("key.plonk.place", IN_GAME, KEYSYM, GLFW_KEY_P, "key.categories.plonk");

public static void init(IEventBus modEventBus) {
modEventBus.addListener(ClientEvents::setupClient);
modEventBus.addListener(ClientEvents::onRegisterKeyMappings);

NeoForge.EVENT_BUS.addListener(ClientEvents::onKeyInput);
NeoForge.EVENT_BUS.addListener(ClientEvents::serverStarting);
}

public static void setupClient(FMLClientSetupEvent event) {
RegistryTESRs.init();
}

public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
event.register(ClientEvents.KEY_PLACE);
}

public static void onKeyInput(InputEvent.Key event) {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (mc.getOverlay() == null && mc.screen == null) {
if (KEY_PLACE.consumeClick() && player != null) {
HitResult hitRaw = mc.hitResult;
if (hitRaw != null && hitRaw.getType() == HitResult.Type.BLOCK) {
BlockHitResult hit = (BlockHitResult) hitRaw;
ItemStack held = player.getMainHandItem();
if (!held.isEmpty()) {
int renderType = TESRPlacedItems.getRenderTypeFromStack(held);
ItemStack toPlace = new ItemStack(RegistryItems.placed_items, 1);
RegistryItems.placed_items.setHeldStack(toPlace, held, renderType);
EntityUtils.setHeldItemSilent(player, InteractionHand.MAIN_HAND, toPlace);
if (toPlace.useOn(new UseOnContext(player, InteractionHand.MAIN_HAND, hit)).consumesAction()) {
Plonk.CHANNEL.sendToServer(new PacketPlaceItem(hit, renderType));
ItemStack newHeld = RegistryItems.placed_items.getHeldStack(toPlace);
EntityUtils.setHeldItemSilent(player, InteractionHand.MAIN_HAND, newHeld);
} else {
EntityUtils.setHeldItemSilent(player, InteractionHand.MAIN_HAND, held);
}
} else if (player.isShiftKeyDown()) {
if (!rotatePlacedItemsTile(player.level(), hit.getBlockPos())) {
rotatePlacedItemsTile(player.level(), hit.getBlockPos().relative(hit.getDirection()));
}
}
}
}
}
}

private static boolean rotatePlacedItemsTile(Level world, BlockPos pos) {
BlockEntity te = world.getBlockEntity(pos);
if (te instanceof TilePlacedItems) {
((TilePlacedItems) te).rotateTile();
Plonk.CHANNEL.sendToServer(new PacketRotateTile(pos));
return true;
}
return false;
}

public static void serverStarting(ServerStartingEvent event) {
new CommandClientPlonk().register(event.getServer().getCommands().getDispatcher());
}
}
Loading

0 comments on commit 02a8c26

Please sign in to comment.