Skip to content

Commit

Permalink
Fixing a bunch of shit I fucked up and fixing rendering on server on …
Browse files Browse the repository at this point in the history
…accident
  • Loading branch information
Cardinalstars committed Sep 15, 2024
1 parent ae725d7 commit d631ba5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/malisis/doors/MalisisDoors.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import net.malisis.doors.door.block.ForcefieldDoor;
import net.malisis.doors.door.block.RustyHatch;
import net.malisis.doors.door.item.ForcefieldItem;
import net.malisis.doors.event.DoorEventHandler;
import net.malisis.doors.event.DoorEventHandlerClient;
import net.malisis.doors.proxy.IProxy;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
Expand Down Expand Up @@ -91,7 +91,7 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new DoorEventHandler());
proxy.initEventHandlers();
}

@EventHandler
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/net/malisis/doors/door/block/BigDoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class BigDoor extends MalisisBlock implements ITileEntityProvider {

public enum Type {

DEFAULT("carriage_door", net.minecraft.init.Items.wooden_door),
CARRIAGE("carriage_door", net.minecraft.init.Items.wooden_door),
MEDIEVAL("medieval_door", Items.doorSpruceItem);

Expand Down Expand Up @@ -92,8 +93,6 @@ private Type(String name, Item door) {
Pair.of(createVectorHelper(0, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(0, 5, 1 - Door.DOOR_WIDTH)),
Pair.of(createVectorHelper(4, 4, 1 - Door.DOOR_WIDTH), createVectorHelper(4, 5, 1 - Door.DOOR_WIDTH)) };

private final int DoorBlockWidth = 4;
private final int DoorBlockHeight = 5;
public static int renderId;
public static int renderPass = -1;
private AxisAlignedBB defaultBoundingBox = AxisAlignedBB.getBoundingBox(0, 0, 1 - Door.DOOR_WIDTH, 4, 5, 1);
Expand Down Expand Up @@ -268,16 +267,6 @@ public TileEntity createNewTileEntity(World world, int metadata) {
return new BigDoorTileEntity(this.type);
}

@SuppressWarnings("deprecation")
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
if (!player.capabilities.isCreativeMode) {
BigDoorTileEntity te = TileEntityUtils.getTileEntity(BigDoorTileEntity.class, world, x, y, z);
if (te != null) dropBlockAsItem(world, x, y, z, te.getDroppedItemStack());
}
return super.removedByPlayer(world, player, x, y, z);
}

@Override
public boolean isOpaqueCube() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ public class BigDoorTileEntity extends MultiTile implements IMultiBlock, IBluePr

private final MultiBlueprint closedBlueprint = new MultiBlueprint(closedPrint, metaMap, new Vector3i(1, 0, 0));
private final MultiBlueprint openBlueprint = new MultiBlueprint(openPrint, metaMap, new Vector3i(1, 0, 0));
private final BigDoor.Type type;
private BigDoor.Type type;

public BigDoorTileEntity() {
this.type = BigDoor.Type.DEFAULT;
DoorDescriptor descriptor = new DoorDescriptor();
descriptor.setMovement(DoorRegistry.getMovement(CarriageDoorMovement.class));
descriptor.setSound(DoorRegistry.getSound(CarriageDoorSound.class));
descriptor.setDoubleDoor(false);
descriptor.setOpeningTime(20);
setDescriptor(descriptor);
}

public BigDoorTileEntity(BigDoor.Type type) {
this.type = type;
Expand All @@ -112,6 +122,7 @@ public BlockState getFrameState() {
public void setFrameState(BlockState state) {
if (state != null) frameState = state;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
this.markDirty();
}

@Override
Expand Down Expand Up @@ -173,13 +184,23 @@ public void readFromNBT(NBTTagCompound tag) {
direction = mb.getDirection();
processed = false;
}

frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(defaultBorderBlock));
int typeInt = tag.getInteger("type");
switch (typeInt)
{
case 0,1:
this.type = BigDoor.Type.CARRIAGE;
break;
case 2:
this.type = BigDoor.Type.MEDIEVAL;
break;
}
this.frameState = Objects.firstNonNull(BlockState.fromNBT(tag), new BlockState(defaultBorderBlock));
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setInteger("type", this.type.ordinal());
BlockState.toNBT(nbt, frameState);
}

Expand Down Expand Up @@ -411,8 +432,8 @@ private void bluePrintPlacerHelper(World world, int x, int y, int z, MultiBluepr
{
for (int k = 0; k < print.bluePrint[0][0].length; k++) // z
{
if (!(i == print.startingLocation.x && j == print.startingLocation.y
&& k == print.startingLocation.z) && print.bluePrint[j][i][k] > -1) {
if (!(i == mainBlockRelativeX && j == mainBlockRelativeY
&& k == mainBlockRelativeZ) && print.bluePrint[j][i][k] > -1) {

switch (this.type) {
case CARRIAGE -> ((CollisionHelperBlock) MalisisDoors.Blocks.collisionHelperBlockCarriage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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

public class DoorEventHandler {
public class DoorEventHandlerClient extends DoorEventHandlerCommon {

public CustomDoorBoundingBoxRenderer cdbbRenderer = new CustomDoorBoundingBoxRenderer();

Expand Down Expand Up @@ -56,39 +56,4 @@ public void onDrawBlockHighlight(DrawBlockHighlightEvent event) {
}
}
}

@SubscribeEvent
public void PlayerInteractEvent(PlayerInteractEvent event) {
TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer);
if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
&& tileEntity instanceof MultiTile multiTile
&& Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
ItemStack heldStack = event.entityPlayer.getHeldItem();
if (heldStack != null) {
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) {
int blockX = rayTraceResult.blockX;
int blockY = rayTraceResult.blockY;
int blockZ = rayTraceResult.blockZ;
return mc.theWorld.getTileEntity(blockX, blockY, blockZ);
}
return null;
}
}
51 changes: 51 additions & 0 deletions src/main/java/net/malisis/doors/event/DoorEventHandlerCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.malisis.doors.event;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.malisis.doors.door.tileentity.MultiTile;
import net.malisis.doors.network.FrameUpdateMessage;
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.minecraftforge.event.entity.player.PlayerInteractEvent;
import org.lwjgl.input.Keyboard;

public class DoorEventHandlerCommon {
@SubscribeEvent
public void PlayerInteractEvent(PlayerInteractEvent event) {
TileEntity tileEntity = getTileEntityLookingAt(event.entityPlayer);
if (event.entityPlayer.isSneaking() && event.action.equals(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK)
&& tileEntity instanceof MultiTile multiTile
&& Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
ItemStack heldStack = event.entityPlayer.getHeldItem();
if (heldStack != null) {
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) {
int blockX = rayTraceResult.blockX;
int blockY = rayTraceResult.blockY;
int blockZ = rayTraceResult.blockZ;
return mc.theWorld.getTileEntity(blockX, blockY, blockZ);
}
return null;
}
}
8 changes: 8 additions & 0 deletions src/main/java/net/malisis/doors/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.malisis.doors.door.tileentity.SaloonDoorTileEntity;
import net.malisis.doors.entity.GarageDoorTileEntity;
import net.malisis.doors.entity.VanishingTileEntity;
import net.malisis.doors.event.DoorEventHandlerClient;
import net.malisis.doors.renderer.GarageDoorRenderer;
import net.malisis.doors.renderer.MixedBlockRenderer;
import net.malisis.doors.renderer.RustyLadderRenderer;
Expand All @@ -37,6 +38,7 @@
import net.malisis.doors.trapdoor.tileentity.TrapDoorTileEntity;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;

public class ClientProxy implements IProxy {

Expand Down Expand Up @@ -100,4 +102,10 @@ public void initFonts() {
ResourceLocation rl = new ResourceLocation(MalisisDoors.modid + ":fonts/digital-7 (mono).ttf");
MalisisDoors.digitalFont = new MalisisFont(rl);
}

@Override
public void initEventHandlers()
{
MinecraftForge.EVENT_BUS.register(new DoorEventHandlerClient());
}
}
6 changes: 4 additions & 2 deletions src/main/java/net/malisis/doors/proxy/IProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
public interface IProxy {

public void initRenderers();
void initRenderers();

public void initFonts();
void initFonts();

void initEventHandlers();
}
8 changes: 8 additions & 0 deletions src/main/java/net/malisis/doors/proxy/ServerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package net.malisis.doors.proxy;

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

/**
* @author Ordinastie
*
Expand All @@ -24,4 +27,9 @@ public void initRenderers() {}

@Override
public void initFonts() {}

@Override
public void initEventHandlers() {
MinecraftForge.EVENT_BUS.register(new DoorEventHandlerCommon());
}
}

0 comments on commit d631ba5

Please sign in to comment.