generated from NeoForgeMDKs/MDK-1.21.1-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67a7146
commit 02a8c26
Showing
60 changed files
with
3,313 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
97
src/main/java/com/portingdeadmods/plonk/client/ClientEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.