Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locked Iron Door #201

Merged
merged 10 commits into from
Jun 23, 2014
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void preInit(FMLPreInitializationEvent event) {
globalConfig.load();
globalConfig.save();

BetterStorage.log.info(Constants.modName + " will overwrite some of its own items. Don't worry, this is normal.");
BetterStorageTiles.initialize();
BetterStorageItems.initialize();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.mcft.copy.betterstorage.client.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraftforge.common.util.ForgeDirection;

public class ModelLockableDoor extends ModelBase {

private ModelRenderer main;

public ModelLockableDoor() {

textureWidth = 64;
textureHeight = 64;

main = new ModelRenderer(this, 0, 0);

main.addBox(-1.5F, 0F, -14.5F, 3, 32, 16);
main.setRotationPoint(-6.5F, -8F, 6.5F);
}

public void renderAll() {
float foo = 1 / 16.0F;
main.render(foo);
}

public void setOrientation(ForgeDirection orientation) {
float x, y, z;

switch (orientation) {
case WEST: x = -6.5F; y = -8F; z = 6.5F; break;
case EAST: x = 6.5F; y = -8F; z = -6.5F; break;
case SOUTH: x = -6.5F; y = -8F; z = -6.5F; break;
default: x = 6.5F; y = -8F; z = 6.5F; break;
}

main.setRotationPoint(x, y, z);
}

public void setRotation(float rotation) {
rotation = rotation / 360 * ((float)Math.PI * 2);
main.rotateAngleY = rotation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public void renderTileEntityAt(TileEntityBackpack backpack, double x, double y,
if ((backpack.stack != null) &&
(backpack.stack.isItemEnchanted())) {
float f9 = (backpack.ticksExisted + partialTicks) / 3;

RenderUtils.bindTexture(Resources.enchantedEffect);

GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1.0F);
GL11.glDepthMask(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.mcft.copy.betterstorage.client.renderer;

import net.mcft.copy.betterstorage.attachment.LockAttachment;
import net.mcft.copy.betterstorage.client.model.ModelLockableDoor;
import net.mcft.copy.betterstorage.misc.Resources;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class TileEntityLockableDoorRenderer extends TileEntitySpecialRenderer {

private ModelLockableDoor model = new ModelLockableDoor();

public void renderTileEntityAt(TileEntityLockableDoor arg0, double x, double y, double z, float partialTicks) {

GL11.glPushMatrix();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glTranslated(x, y + 2.0, z + 1.0);
GL11.glScalef(1.0F, -1.0F, -1.0F);
GL11.glTranslated(0.5F, 0.5F, 0.5F);

float angle = arg0.isOpen ? 1F : 0F;

switch (arg0.orientation) {
case WEST: angle *= -90F; break;
case EAST: angle *= -90F; angle += 180F; break;
case SOUTH: angle *= -90F; angle -= 90F; break;
default: angle = 1 - angle; angle *= 90F; break;
}

GL11.glPushMatrix();
GL11.glRotatef(180F, 1, 0, 0);
GL11.glRotatef(90F, 0, 1, 0);

switch (arg0.orientation) {
case WEST: GL11.glTranslatef(0.5F - 1.5F / 16F, -0.5F + 2 / 16F, -0.5F + 1.5F / 16F); break;
case EAST: GL11.glTranslatef(-0.5F + 1.5F / 16F, -0.5F + 2 / 16F, 0.5F - 1.5F / 16F); break;
case SOUTH: GL11.glTranslatef(-0.5F + 1.5F / 16F, -0.5F + 2 / 16F, -0.5F + 1.5F / 16F); break;
default: GL11.glTranslatef(0.5F - 1.5F / 16F, -0.5F + 2 / 16F, 0.5F - 1.5F / 16F); break;
}

GL11.glRotatef(-angle, 0, 1, 0);
GL11.glTranslatef(-0.5F - 3F / 16F, 0F, 0F);
GL11.glScalef(1F, 1F, 2.5F);

LockAttachment a = arg0.lockAttachment;
a.getRenderer().render(a, partialTicks);
GL11.glPopMatrix();

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
bindTexture(Resources.textureLockableDoor);

GL11.glPushMatrix();
model.setOrientation(arg0.orientation);
model.setRotation(angle);
model.renderAll();
GL11.glPopMatrix();

GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}

@Override
public void renderTileEntityAt(TileEntity arg0, double arg1, double arg2, double arg3, float arg4) {
renderTileEntityAt((TileEntityLockableDoor)arg0, arg1, arg2, arg3, arg4);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class GlobalConfig extends Config {
public static final String reinforcedLockerEnabled = "tile.reinforcedLocker";
public static final String craftingStationEnabled = "tile.craftingStation";
public static final String flintBlockEnabled = "tile.flintBlock";
public static final String lockableDoorEnabled = "tile.lockableDoor";

// Items
public static final String keyEnabled = "item.key";
Expand Down Expand Up @@ -91,6 +92,7 @@ public GlobalConfig(File file) {
new BooleanSetting(this, reinforcedLockerEnabled, true);
new BooleanSetting(this, craftingStationEnabled, true);
new BooleanSetting(this, flintBlockEnabled, true);
new BooleanSetting(this, lockableDoorEnabled, true);

// Items
new BooleanSetting(this, keyEnabled, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack;
import net.mcft.copy.betterstorage.tile.entity.TileEntityCardboardBox;
import net.mcft.copy.betterstorage.tile.entity.TileEntityCraftingStation;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLocker;
import net.mcft.copy.betterstorage.tile.entity.TileEntityReinforcedChest;
import net.mcft.copy.betterstorage.tile.entity.TileEntityReinforcedLocker;
Expand All @@ -26,7 +27,8 @@ public static void register() {
GameRegistry.registerTileEntity(TileEntityCardboardBox.class, Constants.containerCardboardBox);
GameRegistry.registerTileEntity(TileEntityReinforcedLocker.class, Constants.containerReinforcedLocker);
GameRegistry.registerTileEntity(TileEntityCraftingStation.class, Constants.containerCraftingStation);

GameRegistry.registerTileEntity(TileEntityLockableDoor.class, Constants.lockableDoor);

Addon.registerTileEntitesAll();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.mcft.copy.betterstorage.tile.TileCraftingStation;
import net.mcft.copy.betterstorage.tile.TileEnderBackpack;
import net.mcft.copy.betterstorage.tile.TileFlintBlock;
import net.mcft.copy.betterstorage.tile.TileLockableDoor;
import net.mcft.copy.betterstorage.tile.TileLocker;
import net.mcft.copy.betterstorage.tile.TileReinforcedChest;
import net.mcft.copy.betterstorage.tile.TileReinforcedLocker;
Expand All @@ -26,6 +27,7 @@ public final class BetterStorageTiles {
public static TileReinforcedLocker reinforcedLocker;
public static TileCraftingStation craftingStation;
public static TileFlintBlock flintBlock;
public static TileLockableDoor lockableDoor;

private BetterStorageTiles() { }

Expand All @@ -41,6 +43,7 @@ public static void initialize() {
reinforcedLocker = MiscUtils.conditionalNew(TileReinforcedLocker.class, GlobalConfig.reinforcedLockerEnabled);
craftingStation = MiscUtils.conditionalNew(TileCraftingStation.class, GlobalConfig.craftingStationEnabled);
flintBlock = MiscUtils.conditionalNew(TileFlintBlock.class, GlobalConfig.flintBlockEnabled);
lockableDoor = MiscUtils.conditionalNew(TileLockableDoor.class, GlobalConfig.lockableDoorEnabled);

Addon.initializeTilesAll();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class Constants {
public static final String containerThaumcraftBackpack = "container." + modId + ".thaumcraftBackpack";
public static final String containerThaumiumChest = "container." + modId + ".thaumiumChest";

public static final String lockableDoor = modId + ".lockableDoor";

private Constants() { }

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/mcft/copy/betterstorage/misc/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@SideOnly(Side.CLIENT)
public final class Resources {

public static final ResourceLocation textureEmpty = new BetterStorageResource("textures/empty.png");
public static final ResourceLocation textureEmpty = new BetterStorageResource("textures/empty.png");
public static final ResourceLocation enchantedItem = new ResourceLocation("minecraft", "textures/misc/enchanted_item_glint.png");

public static final ResourceLocation enchantedEffect = new ResourceLocation("textures/misc/enchanted_item_glint.png");

Expand All @@ -25,7 +26,8 @@ public final class Resources {
public static final ResourceLocation textureCardboardArmor = new BetterStorageResource("textures/models/cardboardArmor.png");
public static final ResourceLocation textureCardboardLeggins = new BetterStorageResource("textures/models/cardboardArmor_leggings.png");
public static final ResourceLocation textureCluckOverlay = new BetterStorageResource("textures/models/cluck.png");

public static final ResourceLocation textureLockableDoor = new BetterStorageResource("textures/models/lockableDoor.png");


public static final ResourceLocation modelLocker = new BetterStorageResource("models/locker.obj");
public static final ResourceLocation modelLockerLarge = new BetterStorageResource("models/locker_large.obj");
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/mcft/copy/betterstorage/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.mcft.copy.betterstorage.client.renderer.RenderFrienderman;
import net.mcft.copy.betterstorage.client.renderer.TileEntityArmorStandRenderer;
import net.mcft.copy.betterstorage.client.renderer.TileEntityBackpackRenderer;
import net.mcft.copy.betterstorage.client.renderer.TileEntityLockableDoorRenderer;
import net.mcft.copy.betterstorage.client.renderer.TileEntityLockerRenderer;
import net.mcft.copy.betterstorage.client.renderer.TileEntityReinforcedChestRenderer;
import net.mcft.copy.betterstorage.content.BetterStorageItems;
Expand All @@ -27,6 +28,7 @@
import net.mcft.copy.betterstorage.tile.TileArmorStand;
import net.mcft.copy.betterstorage.tile.entity.TileEntityArmorStand;
import net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLocker;
import net.mcft.copy.betterstorage.tile.entity.TileEntityReinforcedChest;
import net.mcft.copy.betterstorage.tile.entity.TileEntityReinforcedLocker;
Expand All @@ -40,6 +42,7 @@
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
Expand Down Expand Up @@ -70,6 +73,7 @@ public class ClientProxy extends CommonProxy {
public static int armorStandRenderId;
public static int backpackRenderId;
public static int reinforcedLockerRenderId;
public static int lockableDoorRenderId;

public static final Map<Class<? extends TileEntity>, BetterStorageRenderingHandler> renderingHandlers =
new HashMap<Class<? extends TileEntity>, BetterStorageRenderingHandler>();
Expand Down Expand Up @@ -101,6 +105,7 @@ private void registerRenderers() {
armorStandRenderId = registerTileEntityRenderer(TileEntityArmorStand.class, new TileEntityArmorStandRenderer(), false, 0, 1, 0);
backpackRenderId = registerTileEntityRenderer(TileEntityBackpack.class, new TileEntityBackpackRenderer(), true, -160, 1.5F, 0.14F);
reinforcedLockerRenderId = registerTileEntityRenderer(TileEntityReinforcedLocker.class, new TileEntityLockerRenderer());
lockableDoorRenderId = registerTileEntityRenderer(TileEntityLockableDoor.class, new TileEntityLockableDoorRenderer(), false, 0, 1, 0);

Addon.registerRenderersAll();

Expand Down Expand Up @@ -135,6 +140,7 @@ public void drawBlockHighlight(DrawBlockHighlightEvent event) {
EntityPlayer player = event.player;
World world = player.worldObj;
MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);

if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK)) return;
int x = target.blockX;
int y = target.blockY;
Expand All @@ -146,6 +152,8 @@ public void drawBlockHighlight(DrawBlockHighlightEvent event) {

if (block instanceof TileArmorStand)
box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
else if (block == Blocks.iron_door)
box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
else if (tileEntity instanceof IHasAttachments)
box = getAttachmentPointsHighlightBox(player, tileEntity, target);

Expand Down Expand Up @@ -196,7 +204,7 @@ else if (tileEntity instanceof IHasAttachments)
event.setCanceled(true);

}

private AxisAlignedBB getArmorStandHighlightBox(EntityPlayer player, World world, int x, int y, int z, Vec3 hitVec) {

int metadata = world.getBlockMetadata(x, y, z);
Expand Down Expand Up @@ -266,7 +274,9 @@ public void onRenderPlayerSpecialsPre(RenderPlayerEvent.Specials.Pre event) {

if (backpack.isItemEnchanted()) {
float f9 = player.ticksExisted + partial;

RenderUtils.bindTexture(Resources.enchantedEffect);

GL11.glEnable(GL11.GL_BLEND);
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1.0F);
GL11.glDepthFunc(GL11.GL_EQUAL);
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/net/mcft/copy/betterstorage/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import net.mcft.copy.betterstorage.attachment.EnumAttachmentInteraction;
import net.mcft.copy.betterstorage.attachment.IHasAttachments;
import net.mcft.copy.betterstorage.content.BetterStorageItems;
import net.mcft.copy.betterstorage.content.BetterStorageTiles;
import net.mcft.copy.betterstorage.entity.EntityCluckington;
import net.mcft.copy.betterstorage.item.IDyeableItem;
import net.mcft.copy.betterstorage.item.ItemBucketSlime;
import net.mcft.copy.betterstorage.item.cardboard.ICardboardItem;
import net.mcft.copy.betterstorage.item.cardboard.ItemCardboardSheet;
import net.mcft.copy.betterstorage.misc.SetBlockFlag;
import net.mcft.copy.betterstorage.misc.handlers.BackpackHandler;
import net.mcft.copy.betterstorage.misc.handlers.CraftingHandler;
import net.mcft.copy.betterstorage.tile.crate.CratePileCollection;
import net.mcft.copy.betterstorage.tile.entity.TileEntityLockableDoor;
import net.mcft.copy.betterstorage.utils.StackUtils;
import net.mcft.copy.betterstorage.utils.WorldUtils;
import net.minecraft.block.Block;
Expand All @@ -21,8 +24,12 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
Expand Down Expand Up @@ -111,6 +118,66 @@ public void onPlayerInteract(PlayerInteractEvent event) {
!ItemCardboardSheet.isEffective(holding))
event.useItem = Result.DENY;

if (!world.isRemote && BetterStorageTiles.lockableDoor != null && rightClick && block == Blocks.iron_door) {

MovingObjectPosition target = WorldUtils.rayTrace(player, 1F);
if(target != null && getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block) != null) {

int meta = world.getBlockMetadata(x, y, z);
if (meta >= 8) {
y -= 1;
meta = world.getBlockMetadata(x, y, z);
}

int rotation = meta & 3;
ForgeDirection orientation = rotation == 0 ? ForgeDirection.WEST : rotation == 1 ? ForgeDirection.NORTH : rotation == 2 ? ForgeDirection.EAST : ForgeDirection.SOUTH;

world.setBlock(x, y, z, BetterStorageTiles.lockableDoor, 0, SetBlockFlag.SEND_TO_CLIENT);
world.setBlock(x, y + 1, z, BetterStorageTiles.lockableDoor, 1, SetBlockFlag.SEND_TO_CLIENT);

TileEntityLockableDoor te = WorldUtils.get(world, x, y, z, TileEntityLockableDoor.class);
te.orientation = orientation;
te.setLock(holding);

player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
}

protected AxisAlignedBB getIronDoorHightlightBox(EntityPlayer player, World world, int x, int y, int z, Vec3 hitVec, Block block) {
if(!StackUtils.isLock(player.getCurrentEquippedItem())) return null;

int meta = world.getBlockMetadata(x, y, z);
if(meta >= 8) {
y -= 1;
meta = world.getBlockMetadata(x, y, z);
}

boolean isOpen = (meta & 4) == 4;
int rotation = (meta & 3);

//TODO Maybe change the bounding box of the doors somehow to match LockableDoor.
AxisAlignedBB box;
switch(rotation) {
case 0 :
if(!isOpen) box = AxisAlignedBB.getAABBPool().getAABB(x - 0.005 / 16F, y + 14.5 / 16F, z + 10 / 16F, x + 3.005 / 16F, y + 20.5 / 16F, z + 15 / 16F);
else box = AxisAlignedBB.getAABBPool().getAABB(x + 10 / 16F, y + 14.5 / 16F, z - 0.005 / 16F, x + 15 / 16F, y + 20.5 / 16F, z + 3.005 / 16F);
break;
case 1 :
if(!isOpen) box = AxisAlignedBB.getAABBPool().getAABB(x + 1 / 16F, y + 14.5 / 16F, z - 0.005 / 16F, x + 6 / 16F, y + 20.5 / 16F, z + 3.005 / 16F);
else box = AxisAlignedBB.getAABBPool().getAABB(x + 12.995 / 16F, y + 14.5 / 16F, z + 10 / 16F, x + 16.005 / 16F, y + 20.5 / 16F, z + 15 / 16F);
break;
case 2 :
if(!isOpen) box = AxisAlignedBB.getAABBPool().getAABB(x + 12.995 / 16F, y + 14.5 / 16F, z + 1 / 16F, x + 16.005 / 16F, y + 20.5 / 16F, z + 6 / 16F);
else box = AxisAlignedBB.getAABBPool().getAABB(x + 1 / 16F, y + 14.5 / 16F, z + 12.995 / 16F, x + 6 / 16F, y + 20.5 / 16F, z + 16.005 / 16F);
break;
default :
if(!isOpen) box = AxisAlignedBB.getAABBPool().getAABB(x + 10 / 16F, y + 14.5 / 16F, z + 12.995 / 16F, x + 15 / 16F, y + 20.5 / 16F, z + 16.005 / 16F);
else box = AxisAlignedBB.getAABBPool().getAABB(x + 0.005 / 16F, y + 14.5 / 16F, z + 1 / 16F, x + 3.005 / 16F, y + 20.5 / 16F, z + 6 / 16F);
break;
}

return box.isVecInside(hitVec) ? box : null;
}

@SubscribeEvent
Expand Down
Loading