mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-11-19 19:59:34 +00:00
Removed unnecessary block updates from Creative Keystone and other blocks
This commit is contained in:
1 parent
20ccdda09e
commit
a4f00d8a47
9 files changed
+107
-162
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.brandon3055.draconicevolution.common.blocks;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -26,9 +27,10 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
/**
|
||||
* Created by Brandon on 27/08/2014.
|
||||
*/
|
||||
public class CKeyStone extends BlockDE {
|
||||
public class CKeyStone extends BlockDE implements ITileEntityProvider {
|
||||
|
||||
private IIcon blockIcon1;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon blockIconActive;
|
||||
|
||||
public CKeyStone() {
|
||||
this.setBlockUnbreakable();
|
||||
@@ -43,43 +45,41 @@ public class CKeyStone extends BlockDE {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileCKeyStone();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_inactive");
|
||||
blockIcon1 = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_active");
|
||||
blockIconActive = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_active");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
if (side == 0 || side == 1) return Blocks.furnace.getIcon(side, meta);
|
||||
else return blockIcon1;
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
return side == 0 || side == 1 ? Blocks.furnace.getIcon(side, metadata) : blockIconActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
if (side == 0 || side == 1) return Blocks.furnace.getIcon(side, 0);
|
||||
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
|
||||
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) return tile.isActivated ? blockIcon1 : blockIcon;
|
||||
else return blockIcon;
|
||||
if (side == 0 || side == 1) {
|
||||
return Blocks.furnace.getIcon(side, 0);
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileCKeyStone) {
|
||||
return ((TileCKeyStone) tile).isActivated ? blockIconActive : blockIcon;
|
||||
}
|
||||
return blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
|
||||
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
|
||||
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
|
||||
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
|
||||
if (tile != null) return tile.onActivated(player.getHeldItem(), player);
|
||||
return false;
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
|
||||
float subY, float subZ) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
return tile instanceof TileCKeyStone && ((TileCKeyStone) tile).onActivated(player.getHeldItem(), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,26 +94,17 @@ public class CKeyStone extends BlockDE {
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int meta) {
|
||||
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
|
||||
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) return tile.isActivated ? 15 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int meta) {
|
||||
return 0;
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
return tile instanceof TileCKeyStone && ((TileCKeyStone) tile).isActivated ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
|
||||
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
|
||||
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
|
||||
: null;
|
||||
if (tile != null) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileCKeyStone) {
|
||||
TileCKeyStone keyStone = (TileCKeyStone) tile;
|
||||
ItemStack key = new ItemStack(ModItems.key);
|
||||
ItemNBTHelper.setInteger(key, "KeyCode", tile.getKeyCode());
|
||||
ItemNBTHelper.setInteger(key, "KeyCode", keyStone.getKeyCode());
|
||||
ItemNBTHelper.setInteger(key, "X", x);
|
||||
ItemNBTHelper.setInteger(key, "Y", y);
|
||||
ItemNBTHelper.setInteger(key, "Z", z);
|
||||
@@ -123,8 +114,7 @@ public class CKeyStone extends BlockDE {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(IBlockAccess p_149747_1_, int p_149747_2_, int p_149747_3_, int p_149747_4_,
|
||||
int p_149747_5_) {
|
||||
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -154,7 +154,8 @@ public class PlayerDetector extends BlockDE implements ITileEntityProvider {
|
||||
x + direction.offsetX,
|
||||
y + direction.offsetY,
|
||||
z + direction.offsetZ,
|
||||
blockBroken);
|
||||
blockBroken,
|
||||
direction.getOpposite().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -172,7 +172,8 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
|
||||
x + direction.offsetX,
|
||||
y + direction.offsetY,
|
||||
z + direction.offsetZ,
|
||||
blockBroken);
|
||||
blockBroken,
|
||||
direction.getOpposite().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
-103
@@ -25,85 +25,57 @@ public class TileCKeyStone extends TileEntity {
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (isActivated && (getMeta() == 1 || getMeta() == 3)) {
|
||||
if (isActivated && (blockMetadata == 1 || blockMetadata == 3)) {
|
||||
activeTicks++;
|
||||
if (activeTicks >= delay) {
|
||||
activeTicks = 0;
|
||||
isActivated = false;
|
||||
updateBlocks();
|
||||
worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.5F);
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.5F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onActivated(ItemStack stack, EntityPlayer player) {
|
||||
if (stack == null || stack.getItem() != ModItems.key) {
|
||||
if (player.capabilities.isCreativeMode && stack == null
|
||||
&& player.isSneaking()
|
||||
&& (getMeta() == 1 || getMeta() == 3))
|
||||
if (stack == null && player.capabilities.isCreativeMode) {
|
||||
if (player.isSneaking() && (blockMetadata == 1 || blockMetadata == 3)) {
|
||||
delay += 5;
|
||||
if (player.capabilities.isCreativeMode && stack == null) giveInformation(player);
|
||||
}
|
||||
giveInformation(player);
|
||||
}
|
||||
if (stack == null || stack.getItem() != ModItems.key) {
|
||||
return false;
|
||||
}
|
||||
if (isMasterKey(stack)) {
|
||||
return true;
|
||||
}
|
||||
if (setKey(stack)) {
|
||||
return true;
|
||||
}
|
||||
if (!isKeyValid(stack, player)) {
|
||||
return false;
|
||||
}
|
||||
if (isMasterKey(stack)) return true;
|
||||
if (setKey(stack)) return true;
|
||||
if (!isKeyValid(stack, player)) return false;
|
||||
|
||||
switch (getMeta()) {
|
||||
switch (blockMetadata) {
|
||||
case 0: // Permanent Activation
|
||||
isActivated = true;
|
||||
player.destroyCurrentEquippedItem();
|
||||
worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.6F);
|
||||
break;
|
||||
case 1: // Button Activation
|
||||
isActivated = true;
|
||||
worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.6F);
|
||||
break;
|
||||
case 2: // Toggle Activation
|
||||
if (!isActivated) worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.6F);
|
||||
else worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.5F);
|
||||
isActivated = !isActivated;
|
||||
break;
|
||||
case 3: // Button Activation (Consume Key)
|
||||
isActivated = true;
|
||||
player.destroyCurrentEquippedItem();
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.6F);
|
||||
break;
|
||||
case 1: // Button Activation
|
||||
isActivated = true;
|
||||
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.6F);
|
||||
break;
|
||||
case 2: // Toggle Activation
|
||||
isActivated = !isActivated;
|
||||
worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
xCoord + 0.5D,
|
||||
yCoord + 0.5D,
|
||||
zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.6F);
|
||||
isActivated ? 0.6F : 0.5F);
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
@@ -115,30 +87,25 @@ public class TileCKeyStone extends TileEntity {
|
||||
|
||||
private void giveInformation(EntityPlayer player) {
|
||||
if (worldObj.isRemote) {
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("msg.cKeyStoneType" + getMeta() + ".txt"));
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("msg.cKeyStoneType" + blockMetadata + ".txt"));
|
||||
player.addChatComponentMessage(new ChatComponentText("Key: " + keyCode));
|
||||
if (getMeta() == 1 || getMeta() == 3) player.addChatComponentMessage(
|
||||
new ChatComponentText("Delay: " + delay + "t (" + (((double) delay) / 20D) + "s)"));
|
||||
if (blockMetadata == 1 || blockMetadata == 3) {
|
||||
player.addChatComponentMessage(
|
||||
new ChatComponentText("Delay: " + delay + "t (" + (((double) delay) / 20D) + "s)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMasterKey(ItemStack key) {
|
||||
if (key.getItemDamage() == 1) {
|
||||
if (!isActivated) worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.6F);
|
||||
else worldObj.playSoundEffect(
|
||||
(double) xCoord + 0.5D,
|
||||
(double) yCoord + 0.5D,
|
||||
(double) zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
0.5F);
|
||||
isActivated = !isActivated;
|
||||
worldObj.playSoundEffect(
|
||||
xCoord + 0.5D,
|
||||
yCoord + 0.5D,
|
||||
zCoord + 0.5D,
|
||||
"random.click",
|
||||
0.3F,
|
||||
isActivated ? 0.6F : 0.5F);
|
||||
updateBlocks();
|
||||
return true;
|
||||
}
|
||||
@@ -146,38 +113,40 @@ public class TileCKeyStone extends TileEntity {
|
||||
}
|
||||
|
||||
private boolean setKey(ItemStack key) {
|
||||
if (keyCode == 0 && ItemNBTHelper.getInteger(key, "KeyCode", 0) == 0) {
|
||||
keyCode = worldObj.rand.nextInt();
|
||||
ItemNBTHelper.setInteger(key, "KeyCode", keyCode);
|
||||
ItemNBTHelper.setInteger(key, "X", xCoord);
|
||||
ItemNBTHelper.setInteger(key, "Y", yCoord);
|
||||
ItemNBTHelper.setInteger(key, "Z", zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
} else if (keyCode == 0 && ItemNBTHelper.getInteger(key, "KeyCode", 0) != 0) {
|
||||
keyCode = ItemNBTHelper.getInteger(key, "KeyCode", 0);
|
||||
ItemNBTHelper.setInteger(key, "LockCount", ItemNBTHelper.getInteger(key, "LockCount", 0) + 1);
|
||||
ItemNBTHelper.setInteger(key, "X_" + ItemNBTHelper.getInteger(key, "LockCount", 0), xCoord);
|
||||
ItemNBTHelper.setInteger(key, "Y_" + ItemNBTHelper.getInteger(key, "LockCount", 0), yCoord);
|
||||
ItemNBTHelper.setInteger(key, "Z_" + ItemNBTHelper.getInteger(key, "LockCount", 0), zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
if (keyCode == 0) {
|
||||
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) == 0) {
|
||||
keyCode = worldObj.rand.nextInt();
|
||||
ItemNBTHelper.setInteger(key, "KeyCode", keyCode);
|
||||
ItemNBTHelper.setInteger(key, "X", xCoord);
|
||||
ItemNBTHelper.setInteger(key, "Y", yCoord);
|
||||
ItemNBTHelper.setInteger(key, "Z", zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
}
|
||||
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) != 0) {
|
||||
keyCode = ItemNBTHelper.getInteger(key, "KeyCode", 0);
|
||||
int lockCount = ItemNBTHelper.getInteger(key, "LockCount", 0) + 1;
|
||||
ItemNBTHelper.setInteger(key, "LockCount", lockCount);
|
||||
ItemNBTHelper.setInteger(key, "X_" + lockCount, xCoord);
|
||||
ItemNBTHelper.setInteger(key, "Y_" + lockCount, yCoord);
|
||||
ItemNBTHelper.setInteger(key, "Z_" + lockCount, zCoord);
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isKeyValid(ItemStack key, EntityPlayer player) {
|
||||
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) != keyCode) {
|
||||
if (worldObj.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.wrongKey.txt"));
|
||||
if (worldObj.isRemote) {
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("msg.wrongKey.txt"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getMeta() {
|
||||
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public int getKeyCode() {
|
||||
return keyCode;
|
||||
}
|
||||
@@ -212,12 +181,6 @@ public class TileCKeyStone extends TileEntity {
|
||||
|
||||
public void updateBlocks() {
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -69,7 +69,8 @@ public class TilePlayerDetector extends TileEntity {
|
||||
xCoord + direction.offsetX,
|
||||
yCoord + direction.offsetY,
|
||||
zCoord + direction.offsetZ,
|
||||
blockType);
|
||||
blockType,
|
||||
direction.getOpposite().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -102,7 +102,8 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
|
||||
xCoord + direction.offsetX,
|
||||
yCoord + direction.offsetY,
|
||||
zCoord + direction.offsetZ,
|
||||
blockType);
|
||||
blockType,
|
||||
direction.getOpposite().ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -65,11 +65,7 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
|
||||
if (tick % 20 == 0) {
|
||||
int comparatorOut = (int) (getEnergyStored() / getMaxEnergyStored() * 15D);
|
||||
if (comparatorOut != lastCheckCompOverride) {
|
||||
worldObj.notifyBlocksOfNeighborChange(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
|
||||
lastCheckCompOverride = comparatorOut;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -46,11 +46,7 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
|
||||
int comparatorOutput = core.getComparatorOutput(comparatorMode);
|
||||
if (comparatorOutput != comparatorOutputCache) {
|
||||
comparatorOutputCache = comparatorOutput;
|
||||
worldObj.notifyBlocksOfNeighborChange(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -65,11 +65,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
|
||||
int comparatorOutput = core.getComparatorOutput(comparatorMode);
|
||||
if (comparatorOutput != comparatorOutputCache) {
|
||||
comparatorOutputCache = comparatorOutput;
|
||||
worldObj.notifyBlocksOfNeighborChange(
|
||||
xCoord,
|
||||
yCoord,
|
||||
zCoord,
|
||||
worldObj.getBlock(xCoord, yCoord, zCoord));
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user