use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.
the class BuilderTileEntity method getBlockInformation.
public static BuilderSetup.BlockInformation getBlockInformation(World world, BlockPos pos, Block block, TileEntity tileEntity) {
IBlockState state = world.getBlockState(pos);
if (isEmpty(state, block)) {
return BuilderSetup.BlockInformation.FREE;
}
FakePlayer fakePlayer = getHarvester();
if (!allowedToBreak(state, world, pos, fakePlayer)) {
return BuilderSetup.BlockInformation.INVALID;
}
BuilderSetup.BlockInformation blockInformation = BuilderSetup.getBlockInformation(block);
if (tileEntity != null) {
switch(BuilderConfiguration.teMode) {
case MOVE_FORBIDDEN:
return BuilderSetup.BlockInformation.INVALID;
case MOVE_WHITELIST:
if (blockInformation == null || blockInformation.getBlockLevel() == SupportBlock.STATUS_ERROR) {
return BuilderSetup.BlockInformation.INVALID;
}
break;
case MOVE_BLACKLIST:
if (blockInformation != null && blockInformation.getBlockLevel() == SupportBlock.STATUS_ERROR) {
return BuilderSetup.BlockInformation.INVALID;
}
break;
case MOVE_ALLOWED:
break;
}
}
if (blockInformation != null) {
return blockInformation;
}
return BuilderSetup.BlockInformation.OK;
}
use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.
the class BuilderTileEntity method placeLiquidBlock.
public boolean placeLiquidBlock(int rfNeeded, BlockPos srcPos, IBlockState srcState, IBlockState pickState) {
if (isEmptyOrReplacable(getWorld(), srcPos)) {
FluidStack stack = consumeLiquid(getWorld(), srcPos);
if (stack == null) {
// We could not find a block. Wait
return waitOrSkip("Cannot find liquid!\nor no usable tank\nabove or below");
}
Fluid fluid = stack.getFluid();
if (fluid.doesVaporize(stack) && getWorld().provider.doesWaterVaporize()) {
fluid.vaporize(null, getWorld(), srcPos, stack);
} else {
// We assume here the liquid is placable.
Block block = fluid.getBlock();
FakePlayer fakePlayer = getHarvester();
getWorld().setBlockState(srcPos, block.getDefaultState(), 11);
if (!silent) {
SoundTools.playSound(getWorld(), block.getSoundType(block.getDefaultState(), getWorld(), srcPos, fakePlayer).getPlaceSound(), srcPos.getX(), srcPos.getY(), srcPos.getZ(), 1.0f, 1.0f);
}
}
consumeEnergy(rfNeeded);
}
return skip();
}
use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.
the class BuilderTileEntity method voidBlock.
public boolean voidBlock(int rfNeeded, BlockPos srcPos, IBlockState srcState, IBlockState pickState) {
Block block = srcState.getBlock();
int xCoord = getPos().getX();
int yCoord = getPos().getY();
int zCoord = getPos().getZ();
int sx = srcPos.getX();
int sy = srcPos.getY();
int sz = srcPos.getZ();
if (sx >= xCoord - 1 && sx <= xCoord + 1 && sy >= yCoord - 1 && sy <= yCoord + 1 && sz >= zCoord - 1 && sz <= zCoord + 1) {
// Skip a 3x3x3 block around the builder.
return skip();
}
FakePlayer fakePlayer = getHarvester();
if (allowedToBreak(srcState, getWorld(), srcPos, fakePlayer)) {
if (block.getBlockHardness(srcState, getWorld(), srcPos) >= 0) {
ItemStack filter = getStackInSlot(BuilderContainer.SLOT_FILTER);
if (!filter.isEmpty()) {
getFilterCache();
if (filterCache != null) {
boolean match = filterCache.match(block.getItem(getWorld(), srcPos, srcState));
if (!match) {
consumeEnergy(Math.min(rfNeeded, BuilderConfiguration.builderRfPerSkipped));
// Skip this
return skip();
}
}
}
if (!silent) {
SoundTools.playSound(getWorld(), block.getSoundType(srcState, getWorld(), srcPos, fakePlayer).getBreakSound(), sx, sy, sz, 1.0f, 1.0f);
}
getWorld().setBlockToAir(srcPos);
consumeEnergy(rfNeeded);
}
}
return skip();
}
use of net.minecraftforge.common.util.FakePlayer in project RFTools by McJty.
the class ShieldTEBase method applyDamageToEntity.
public void applyDamageToEntity(Entity entity) {
DamageSource source;
int rf;
if (DamageTypeMode.DAMAGETYPE_GENERIC.equals(damageMode)) {
rf = ShieldConfiguration.rfDamage;
source = DamageSource.GENERIC;
} else {
rf = ShieldConfiguration.rfDamagePlayer;
if (killer == null) {
killer = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(new UUID(111, 222), "rftools_shield"));
}
FakePlayer fakePlayer = killer;
ItemStack shards = getStackInSlot(ShieldContainer.SLOT_SHARD);
if (!shards.isEmpty() && shards.getCount() >= ShieldConfiguration.shardsPerLootingKill) {
decrStackSize(ShieldContainer.SLOT_SHARD, ShieldConfiguration.shardsPerLootingKill);
if (lootingSword.isEmpty()) {
lootingSword = EnvironmentalSetup.createEnchantedItem(Items.DIAMOND_SWORD, Enchantments.LOOTING, ShieldConfiguration.lootingKillBonus);
}
lootingSword.setItemDamage(0);
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, lootingSword);
} else {
fakePlayer.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
source = DamageSource.causePlayerDamage(fakePlayer);
}
rf = (int) (rf * costFactor * (4.0f - getInfusedFactor()) / 4.0f);
if (getEnergyStored() < rf) {
// Not enough RF to do damage.
return;
}
consumeEnergy(rf);
float damage = ShieldConfiguration.damage;
damage *= damageFactor;
damage = damage * (1.0f + getInfusedFactor() / 2.0f);
entity.attackEntityFrom(source, damage);
}
use of net.minecraftforge.common.util.FakePlayer in project OpenModularTurrets by OpenModularTurretsTeam.
the class OMTEventHandler method entityAttackedEvent.
@SubscribeEvent
public void entityAttackedEvent(LivingAttackEvent event) {
EntityLivingBase entity = event.getEntityLiving();
int fakeDrops = OMTUtil.getFakeDropsLevel(entity);
if (fakeDrops >= 0) {
FakePlayer player = OMTFakePlayer.getFakePlayer((WorldServer) event.getEntityLiving().getEntityWorld());
player.setHeldItem(EnumHand.MAIN_HAND, OMTFakePlayer.getSword(fakeDrops));
entity.setLastAttackedEntity(player);
}
}
Aggregations