Skip to content

Commit

Permalink
Fix client-only classes usage on server (#17)
Browse files Browse the repository at this point in the history
* fix client-only classes usage on server

* remove old unused version checker

* add NEI at runtime
  • Loading branch information
Lyfts authored Sep 26, 2024
1 parent c9f35f8 commit c799c7c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 277 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.24'

implementation 'com.github.GTNewHorizons:GTNHLib:0.5.11:dev'
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.6.38-GTNH:dev")
}
83 changes: 58 additions & 25 deletions src/main/java/net/malisis/doors/event/DoorEventHandlerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,81 @@
import net.malisis.doors.door.block.CollisionHelperBlock;
import net.malisis.doors.door.tileentity.DoorTileEntity;
import net.malisis.doors.door.tileentity.MultiTile;
import net.malisis.doors.network.FrameUpdateMessage;
import net.malisis.doors.renderer.CustomDoorBoundingBoxRenderer;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class DoorEventHandlerClient extends DoorEventHandlerCommon {
public class DoorEventHandlerClient {

public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer();

@SubscribeEvent
public void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
World world = event.player.worldObj;
if (world.isRemote) {
MovingObjectPosition target = event.target;

if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int x = target.blockX;
int y = target.blockY;
int z = target.blockZ;
Block block = world.getBlock(x, y, z);

if (block instanceof CollisionHelperBlock) {
MultiTile cTE = ((MultiTile) world.getTileEntity(x, y, z));
TileEntity mainDoorTE = cTE.getMainBlockTile();
if (mainDoorTE instanceof DoorTileEntity) {
DoorState state = ((DoorTileEntity) mainDoorTE).getState();
if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) {
event.setCanceled(true);
cdbbRenderer.renderOpenDoorBoundingBox(
world,
(CollisionHelperBlock) block,
event.player,
event.partialTicks,
target);
}
}
MovingObjectPosition target = event.target;

if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int x = target.blockX;
int y = target.blockY;
int z = target.blockZ;
Block block = world.getBlock(x, y, z);

if (!(block instanceof CollisionHelperBlock collisionHelper)) return;
if (world.getTileEntity(x, y, z) instanceof MultiTile multi
&& multi.getMainBlockTile() instanceof DoorTileEntity doorTile) {
DoorState state = doorTile.getState();
if (state == DoorState.OPENED || state == DoorState.OPENING || state == DoorState.CLOSING) {
event.setCanceled(true);
cdbbRenderer
.renderOpenDoorBoundingBox(world, collisionHelper, event.player, event.partialTicks, target);
}
}
}
}

@SubscribeEvent
public void onClientInteract(PlayerInteractEvent event) {
EntityPlayer player = event.entityPlayer;
TileEntity tileEntity = getTileEntityLookingAt(player);
if (player.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
&& tileEntity instanceof MultiTile multiTile
&& Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
ItemStack heldStack = player.getHeldItem();
if (heldStack == null) return;

Block block = Block.getBlockFromItem(heldStack.getItem());
int damageValue = heldStack.getItemDamage();
if (block != null) {
event.setCanceled(true);
FrameUpdateMessage.SendFrameUpdateMessage(multiTile, block, damageValue);
}
}
}

private TileEntity getTileEntityLookingAt(EntityPlayer player) {
Minecraft mc = Minecraft.getMinecraft();
double maxReach = mc.playerController.getBlockReachDistance();
Vec3 eyePosition = player.getPosition(1.0F);
Vec3 lookVector = player.getLook(1.0F);
Vec3 endPosition = eyePosition
.addVector(lookVector.xCoord * maxReach, lookVector.yCoord * maxReach, lookVector.zCoord * maxReach);
MovingObjectPosition rayTraceResult = mc.theWorld.rayTraceBlocks(eyePosition, endPosition);
if (rayTraceResult != null && rayTraceResult.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
return mc.theWorld.getTileEntity(rayTraceResult.blockX, rayTraceResult.blockY, rayTraceResult.blockZ);
}
return null;
}
}
54 changes: 0 additions & 54 deletions src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java

This file was deleted.

7 changes: 1 addition & 6 deletions src/main/java/net/malisis/doors/proxy/ServerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

package net.malisis.doors.proxy;

import net.malisis.doors.event.DoorEventHandlerCommon;
import net.minecraftforge.common.MinecraftForge;

/**
* @author Ordinastie
*
Expand All @@ -29,7 +26,5 @@ public void initRenderers() {}
public void initFonts() {}

@Override
public void initEventHandlers() {
MinecraftForge.EVENT_BUS.register(new DoorEventHandlerCommon());
}
public void initEventHandlers() {}
}
192 changes: 0 additions & 192 deletions src/main/java/net/malisis/javacompat/JavaCompatibility.java

This file was deleted.

0 comments on commit c799c7c

Please sign in to comment.