use of net.geforcemods.securitycraft.api.CustomizableSCTE in project SecurityCraft by Geforce132.
the class BlockUtils method setBlockProperty.
public static void setBlockProperty(World par1World, BlockPos pos, PropertyBool property, boolean value, boolean retainOldTileEntity) {
if (retainOldTileEntity) {
ItemStack[] modules = null;
ItemStack[] inventory = null;
int[] times = new int[4];
String password = "";
Owner owner = null;
int cooldown = -1;
if (par1World.getTileEntity(pos) instanceof CustomizableSCTE)
modules = ((CustomizableSCTE) par1World.getTileEntity(pos)).itemStacks;
if (par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace) {
inventory = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceItemStacks;
times[0] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceBurnTime;
times[1] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).currentItemBurnTime;
times[2] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).cookTime;
times[3] = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).totalCookTime;
}
if (par1World.getTileEntity(pos) instanceof TileEntityOwnable && ((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner() != null)
owner = ((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner();
if (par1World.getTileEntity(pos) instanceof TileEntityKeypad && ((TileEntityKeypad) par1World.getTileEntity(pos)).getPassword() != null)
password = ((TileEntityKeypad) par1World.getTileEntity(pos)).getPassword();
if (par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace && ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).getPassword() != null)
password = ((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).getPassword();
if (par1World.getTileEntity(pos) instanceof TileEntityKeypadChest && ((TileEntityKeypadChest) par1World.getTileEntity(pos)).getPassword() != null)
password = ((TileEntityKeypadChest) par1World.getTileEntity(pos)).getPassword();
if (par1World.getTileEntity(pos) instanceof TileEntityPortableRadar && ((TileEntityPortableRadar) par1World.getTileEntity(pos)).getAttackCooldown() != 0)
cooldown = ((TileEntityPortableRadar) par1World.getTileEntity(pos)).getAttackCooldown();
TileEntity tileEntity = par1World.getTileEntity(pos);
par1World.setBlockState(pos, par1World.getBlockState(pos).withProperty(property, value));
par1World.setTileEntity(pos, tileEntity);
if (modules != null)
((CustomizableSCTE) par1World.getTileEntity(pos)).itemStacks = modules;
if (inventory != null && par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace) {
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceItemStacks = inventory;
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).furnaceBurnTime = times[0];
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).currentItemBurnTime = times[1];
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).cookTime = times[2];
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).totalCookTime = times[3];
}
if (owner != null)
((TileEntityOwnable) par1World.getTileEntity(pos)).getOwner().set(owner);
if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypad)
((TileEntityKeypad) par1World.getTileEntity(pos)).setPassword(password);
if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypadFurnace)
((TileEntityKeypadFurnace) par1World.getTileEntity(pos)).setPassword(password);
if (!password.isEmpty() && par1World.getTileEntity(pos) instanceof TileEntityKeypadChest)
((TileEntityKeypadChest) par1World.getTileEntity(pos)).setPassword(password);
if (cooldown != -1 && par1World.getTileEntity(pos) instanceof TileEntityPortableRadar)
((TileEntityPortableRadar) par1World.getTileEntity(pos)).setAttackCooldown(cooldown);
} else
par1World.setBlockState(pos, par1World.getBlockState(pos).withProperty(property, value));
}
use of net.geforcemods.securitycraft.api.CustomizableSCTE in project SecurityCraft by Geforce132.
the class ModuleUtils method getPlayersFromModule.
public static List<String> getPlayersFromModule(World par1World, BlockPos pos, EnumCustomModules module) {
List<String> list = new ArrayList<String>();
CustomizableSCTE te = (CustomizableSCTE) par1World.getTileEntity(pos);
if (te.hasModule(module)) {
ItemStack item = te.getModule(module);
for (int i = 1; i <= 10; i++) if (item.getTagCompound() != null && item.getTagCompound().getString("Player" + i) != null && !item.getTagCompound().getString("Player" + i).isEmpty())
list.add(item.getTagCompound().getString("Player" + i).toLowerCase());
}
return list;
}
use of net.geforcemods.securitycraft.api.CustomizableSCTE in project SecurityCraft by Geforce132.
the class SCEventHandler method onBlockBroken.
@SubscribeEvent
public void onBlockBroken(BreakEvent event) {
if (!event.world.isRemote)
if (event.world.getTileEntity(event.pos) != null && event.world.getTileEntity(event.pos) instanceof CustomizableSCTE) {
CustomizableSCTE te = (CustomizableSCTE) event.world.getTileEntity(event.pos);
for (int i = 0; i < te.getNumberOfCustomizableOptions(); i++) if (te.itemStacks[i] != null) {
ItemStack stack = te.itemStacks[i];
EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), stack);
event.world.spawnEntityInWorld(item);
te.onModuleRemoved(stack, ((ItemModule) stack.getItem()).getModule());
te.createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { stack, ((ItemModule) stack.getItem()).getModule() }, te);
if (te instanceof TileEntitySecurityCamera)
te.getWorld().notifyNeighborsOfStateChange(te.getPos().offset((EnumFacing) te.getWorld().getBlockState(te.getPos()).getValue(BlockSecurityCamera.FACING), -1), te.getWorld().getBlockState(te.getPos()).getBlock());
}
}
}
use of net.geforcemods.securitycraft.api.CustomizableSCTE in project SecurityCraft by Geforce132.
the class SCEventHandler method onPlayerInteracted.
@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
if (!event.entityPlayer.worldObj.isRemote) {
World world = event.entityPlayer.worldObj;
TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
if (event.action != Action.RIGHT_CLICK_BLOCK)
return;
if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.codebreaker) && handleCodebreaking(event)) {
event.setCanceled(true);
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockModifier)) {
event.setCanceled(true);
if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
return;
}
event.entityPlayer.openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
event.setCanceled(true);
for (String character : new String[] { "(", ")" }) if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
return;
}
if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
return;
}
event.entityPlayer.getCurrentEquippedItem().stackSize--;
((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockRemover)) {
event.setCanceled(true);
if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
return;
}
if (block == SCContent.laserBlock) {
world.destroyBlock(event.pos, true);
BlockLaserBlock.destroyAdjacentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
} else {
world.destroyBlock(event.pos, true);
world.removeTileEntity(event.pos);
event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
}
}
}
}
use of net.geforcemods.securitycraft.api.CustomizableSCTE in project SecurityCraft by Geforce132.
the class ForgeEventHandler method onPlayerInteracted.
@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
if (!event.entityPlayer.worldObj.isRemote) {
World world = event.entityPlayer.worldObj;
TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
if (event.action != Action.RIGHT_CLICK_BLOCK)
return;
if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.codebreaker) && handleCodebreaking(event)) {
event.setCanceled(true);
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockModifier)) {
event.setCanceled(true);
if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
return;
}
event.entityPlayer.openGui(mod_SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
event.setCanceled(true);
for (String character : new String[] { "(", ")" }) {
if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
return;
}
}
if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
return;
}
event.entityPlayer.getCurrentEquippedItem().stackSize--;
((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
return;
}
if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, mod_SecurityCraft.universalBlockRemover)) {
event.setCanceled(true);
if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
return;
}
if (block == mod_SecurityCraft.laserBlock) {
world.destroyBlock(event.pos, true);
BlockLaserBlock.destroyAdjecentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
} else {
world.destroyBlock(event.pos, true);
world.removeTileEntity(event.pos);
event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
}
}
}
}
Aggregations