use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.
the class HackableHandler method getHackableForCoord.
public static IHackableBlock getHackableForCoord(IBlockAccess world, int x, int y, int z, EntityPlayer player) {
//clean up the map
Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> iterator = getInstance().trackedHackableBlocks.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<WorldAndCoord, IHackableBlock> entry = iterator.next();
Class<? extends IHackableBlock> hackableBlockClazz = PneumaticCraftAPIHandler.getInstance().hackableBlocks.get(entry.getKey().getBlock());
if (hackableBlockClazz != entry.getValue().getClass() || !entry.getValue().canHack(entry.getKey().world, entry.getKey().x, entry.getKey().y, entry.getKey().z, player) && !isInDisplayCooldown(entry.getValue(), entry.getKey().world, entry.getKey().x, entry.getKey().y, entry.getKey().z, player))
iterator.remove();
}
Block block = world.getBlock(x, y, z);
if (block instanceof IHackableBlock && ((IHackableBlock) block).canHack(world, x, y, z, player))
return (IHackableBlock) block;
IHackableBlock hackable = getInstance().trackedHackableBlocks.get(new WorldAndCoord(world, x, y, z));
if (hackable == null) {
if (!PneumaticCraftAPIHandler.getInstance().hackableBlocks.containsKey(block))
return null;
try {
hackable = PneumaticCraftAPIHandler.getInstance().hackableBlocks.get(block).newInstance();
if (hackable.canHack(world, x, y, z, player)) {
getInstance().trackedHackableBlocks.put(new WorldAndCoord(world, x, y, z), hackable);
} else {
hackable = null;
}
} catch (Exception e) {
//shouldn't happen, checked earlier.
e.printStackTrace();
}
}
return hackable;
}
use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.
the class PacketHackingBlockStart method handleServerSide.
@Override
public void handleServerSide(PacketHackingBlockStart message, EntityPlayer player) {
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z));
NetworkHandler.sendToAllAround(message, player.worldObj);
}
use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.
the class HackTickHandler method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
Iterator<Map.Entry<WorldAndCoord, IHackableBlock>> blockIterator = hackedBlocks.entrySet().iterator();
while (blockIterator.hasNext()) {
Map.Entry<WorldAndCoord, IHackableBlock> entry = blockIterator.next();
IHackableBlock hackableBlock = entry.getValue();
WorldAndCoord hackedBlock = entry.getKey();
boolean found = false;
for (Map.Entry<Block, Class<? extends IHackableBlock>> registeredEntry : PneumaticCraftAPIHandler.getInstance().hackableBlocks.entrySet()) {
if (hackableBlock.getClass() == registeredEntry.getValue()) {
if (hackedBlock.getBlock() == registeredEntry.getKey()) {
if (!hackableBlock.afterHackTick((World) hackedBlock.world, hackedBlock.x, hackedBlock.y, hackedBlock.z)) {
blockIterator.remove();
}
found = true;
break;
}
}
}
if (!found)
blockIterator.remove();
}
}
}
use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.
the class PacketHackingBlockFinish method handleClientSide.
@Override
public void handleClientSide(PacketHackingBlockFinish message, EntityPlayer player) {
IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(player.worldObj, message.x, message.y, message.z, player);
if (hackableBlock != null) {
hackableBlock.onHackFinished(player.worldObj, message.x, message.y, message.z, player);
PneumaticCraft.proxy.getHackTickHandler().trackBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z), hackableBlock);
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(null);
player.worldObj.playSound(message.x, message.y, message.z, "PneumaticCraft:helmetHackFinish", 1.0F, 1.0F, false);
}
}
use of pneumaticCraft.common.util.WorldAndCoord in project PneumaticCraft by MineMaarten.
the class PacketHackingBlockStart method handleClientSide.
@Override
public void handleClientSide(PacketHackingBlockStart message, EntityPlayer player) {
CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(new WorldAndCoord(player.worldObj, message.x, message.y, message.z));
RenderBlockTarget target = HUDHandler.instance().getSpecificRenderer(BlockTrackUpgradeHandler.class).getTargetForCoord(message.x, message.y, message.z);
if (target != null)
target.onHackConfirmServer();
}
Aggregations