use of net.minecraft.entity.player.PlayerEntity in project BluePower by Qmunity.
the class ItemSickle method mineBlock.
@Override
public boolean mineBlock(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity entityLiving) {
boolean used = false;
if (!(entityLiving instanceof PlayerEntity))
return false;
PlayerEntity player = (PlayerEntity) entityLiving;
if (state.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || state.getBlock() instanceof LeavesBlock) {
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
for (int k = -1; k <= 1; k++) {
BlockState blockToCheck = world.getBlockState(pos.offset(i, j, k));
if (blockToCheck.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || blockToCheck.getBlock() instanceof LeavesBlock) {
if (blockToCheck.canHarvestBlock(world, pos.offset(i, j, k), player)) {
world.destroyBlock(pos.offset(i, j, k), true);
}
used = true;
}
}
}
}
if (used) {
stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
}
return used;
}
if ((state.getBlock() instanceof LilyPadBlock)) {
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
BlockState meta = world.getBlockState(pos.offset(i, 0, j));
if (blockToCheck instanceof LilyPadBlock) {
if (blockToCheck.canHarvestBlock(meta, world, pos.offset(i, 0, j), player)) {
world.destroyBlock(pos.offset(i, 0, j), true);
}
used = true;
}
}
}
}
if (!(state.getBlock() instanceof LilyPadBlock)) {
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
if (blockToCheck instanceof BushBlock && !(blockToCheck instanceof LilyPadBlock)) {
if (blockToCheck.canHarvestBlock(world.getBlockState(pos.offset(i, 0, j)), world, pos.offset(i, 0, j), player)) {
world.destroyBlock(pos.offset(i, 0, j), true);
}
used = true;
}
}
}
}
if (used) {
stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
}
return used;
}
use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.
the class DullMirrorItem method inventoryTick.
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (stack.getDamage() == (this.getMaxDamage(stack) - 1)) {
CompoundNBT compound = NBTHelper.ensureTagExists(stack);
if (!compound.getBoolean("RemovedSpawn") && entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType bedDimension = DimensionType.byName(new ResourceLocation(compound.getString("BedDimension")));
if (bedDimension != null) {
player.setSpawnDimenion(bedDimension);
player.setSpawnPoint(NBTUtil.readBlockPos(compound.getCompound("BedPoint")), true, false, bedDimension);
compound.putBoolean("RemovedSpawn", true);
}
}
}
}
}
use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.
the class PlayerHandler method onPlayerDrop.
@SubscribeEvent
public static void onPlayerDrop(LivingDropsEvent event) {
LivingEntity livingEntity = event.getEntityLiving();
Iterator<ItemEntity> iter = event.getDrops().iterator();
if (livingEntity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) livingEntity;
while (iter.hasNext()) {
ItemEntity entityItem = iter.next();
ItemStack stack = entityItem.getItem();
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
player.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
iter.remove();
break;
}
}
}
}
use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.
the class PlayerHandler method onPlayerRespawn.
@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
World world = event.getPlayer().getEntityWorld();
PlayerEntity player = event.getPlayer();
PlayerInventory playerInventory = player.inventory;
if (!world.isRemote) {
ItemStack mirrorStack = ItemStack.EMPTY;
for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
ItemStack stack = playerInventory.getStackInSlot(i);
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
mirrorStack = stack;
break;
}
}
if (!mirrorStack.isEmpty()) {
if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
if (spawnDimension != null && player.dimension != spawnDimension) {
MinecraftServer server = world.getServer();
if (server != null) {
BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
}
}
}
}
}
}
}
use of net.minecraft.entity.player.PlayerEntity in project NetherEx by LogicTechCorp.
the class PlayerHandler method onItemCrafted.
@SubscribeEvent
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
PlayerEntity player = event.getPlayer();
ItemStack stack = event.getCrafting();
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
if (stack.getDamage() < stack.getMaxDamage()) {
CompoundNBT compound = NBTHelper.ensureTagExists(stack);
compound.putBoolean("RemovedSpawn", false);
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
if (spawnDimension != null) {
player.setSpawnDimenion(spawnDimension);
player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
}
}
}
}
}
Aggregations