use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockExpander method clOnBlockActivated.
@Override
protected boolean clOnBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hand.equals(EnumHand.OFF_HAND))
return true;
Expander expander = (Expander) worldIn.getTileEntity(pos);
if (expander == null) {
return true;
}
TurretBase base = expander.getBase();
if (base == null) {
worldIn.destroyBlock(pos, true);
return true;
}
TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(playerIn, base);
if (trustedPlayer != null) {
if (base.getTrustedPlayer(playerIn.getUniqueID()).canOpenGUI && state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
}
if (PlayerUtil.isPlayerOwner(playerIn, base)) {
if (playerIn.isSneaking() && playerIn.getHeldItemMainhand() == null) {
worldIn.destroyBlock(pos, true);
} else if (state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
} else {
return true;
}
} else {
addChatMessage(playerIn, new TextComponentString(safeLocalize("status.ownership")));
}
return true;
}
use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.
the class TurretHeadUtil method getSpecificItemFromInvExpanders.
public static ItemStack getSpecificItemFromInvExpanders(World world, ItemStack itemStack, TurretBase base) {
for (TileEntity tileEntity : WorldUtil.getTouchingTileEntities(world, base.getPos())) {
if (tileEntity instanceof Expander && !((Expander) tileEntity).isPowerExpander()) {
Expander exp = (Expander) tileEntity;
ItemStack stack = deductFromInvExpander(itemStack, exp, base);
if (stack != ItemStack.EMPTY) {
return stack;
}
}
}
return ItemStack.EMPTY;
}
use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.
the class TurretHeadUtil method getAmmoLevel.
public static int getAmmoLevel(TurretHead turret, TurretBase base) {
int result = 0;
ItemStack ammoStackRequired = turret.getAmmo();
if (ammoStackRequired == null) {
return base.getEnergyLevel(EnumFacing.DOWN) / turret.getTurretPowerUsage();
}
for (int i = 0; i <= 8; i++) {
ItemStack ammoStack = base.getStackInSlot(i);
if (ammoStack != ItemStack.EMPTY && getStackSize(ammoStack) > 0 && ammoStack.getItem() == ammoStackRequired.getItem() && ammoStack.getMetadata() == ammoStackRequired.getMetadata()) {
result += ammoStack.getCount();
}
}
for (TileEntity tileEntity : WorldUtil.getTouchingTileEntities(base.getWorld(), base.getPos())) {
if (tileEntity instanceof Expander && !((Expander) tileEntity).isPowerExpander()) {
Expander exp = (Expander) tileEntity;
for (int i = 0; i < exp.getSizeInventory(); i++) {
ItemStack ammoStack = exp.getStackInSlot(i);
if (ammoStack != ItemStack.EMPTY && ammoStack.getItem() == ammoStackRequired.getItem()) {
result += ammoStack.getCount();
}
}
}
}
return result;
}
use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockExpander method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (hand.equals(EnumHand.OFF_HAND))
return true;
Expander expander = (Expander) worldIn.getTileEntity(pos);
if (expander == null) {
return true;
}
TurretBase base = expander.getBase();
if (base == null) {
worldIn.destroyBlock(pos, true);
return true;
}
TrustedPlayer trustedPlayer = PlayerUtil.getTrustedPlayer(playerIn, base);
if (trustedPlayer != null) {
if (base.getTrustedPlayer(playerIn.getUniqueID()).canOpenGUI && state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
}
if (PlayerUtil.isPlayerOwner(playerIn, base)) {
if (playerIn.isSneaking() && playerIn.getHeldItemMainhand().isEmpty()) {
worldIn.destroyBlock(pos, true);
} else if (state.getValue(META) < 5) {
playerIn.openGui(OpenModularTurrets.instance, 7, worldIn, pos.getX(), pos.getY(), pos.getZ());
} else {
return true;
}
} else {
addChatMessage(playerIn, new TextComponentString(safeLocalize("status.ownership")));
}
return true;
}
use of omtteam.openmodularturrets.tileentity.Expander in project OpenModularTurrets by OpenModularTurretsTeam.
the class BlockExpander method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
Expander expander = (Expander) worldIn.getTileEntity(pos);
if (expander != null) {
expander.setOwnerName(expander.getBase().getOwnerName());
expander.setOwner(expander.getBase().getOwner());
expander.setSide();
}
}
Aggregations