use of net.blay09.mods.waystones.block.TileWaystone in project Waystones by blay09.
the class WaystoneManager method checkAndUpdateWaystone.
public static boolean checkAndUpdateWaystone(EntityPlayer player, WaystoneEntry waystone) {
NBTTagCompound tagCompound = PlayerWaystoneHelper.getWaystonesTag(player);
NBTTagList tagList = tagCompound.getTagList(PlayerWaystoneHelper.WAYSTONE_LIST, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound entryCompound = tagList.getCompoundTagAt(i);
if (WaystoneEntry.read(entryCompound).equals(waystone)) {
TileWaystone tileEntity = getWaystoneInWorld(waystone);
if (tileEntity != null) {
if (!entryCompound.getString("Name").equals(tileEntity.getWaystoneName())) {
entryCompound.setString("Name", tileEntity.getWaystoneName());
sendPlayerWaystones(player);
}
return true;
} else {
if (waystone.isGlobal()) {
GlobalWaystones.get(player.world).removeGlobalWaystone(waystone);
}
removePlayerWaystone(player, waystone);
sendPlayerWaystones(player);
}
return false;
}
}
return false;
}
use of net.blay09.mods.waystones.block.TileWaystone in project Waystones by blay09.
the class BlockWaystone method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking() && (player.capabilities.isCreativeMode || !WaystoneConfig.general.creativeModeOnly)) {
if (!world.isRemote) {
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone == null) {
return true;
}
if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(player)) {
player.sendStatusMessage(new TextComponentTranslation("waystones:notTheOwner"), true);
return true;
}
if (tileWaystone.isGlobal() && !player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
player.sendStatusMessage(new TextComponentTranslation("waystones:creativeRequired"), true);
return true;
}
player.openGui(Waystones.instance, 1, world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone == null) {
return true;
}
WaystoneEntry knownWaystone = world.isRemote ? ClientWaystones.getKnownWaystone(tileWaystone.getWaystoneName()) : null;
if (knownWaystone != null) {
Waystones.proxy.openWaystoneSelection(WarpMode.WAYSTONE, EnumHand.MAIN_HAND, knownWaystone);
} else if (!world.isRemote) {
WaystoneEntry waystone = new WaystoneEntry(tileWaystone);
if (!WaystoneManager.checkAndUpdateWaystone(player, waystone)) {
TextComponentString nameComponent = new TextComponentString(tileWaystone.getWaystoneName());
nameComponent.getStyle().setColor(TextFormatting.WHITE);
TextComponentTranslation chatComponent = new TextComponentTranslation("waystones:activatedWaystone", nameComponent);
chatComponent.getStyle().setColor(TextFormatting.YELLOW);
player.sendMessage(chatComponent);
player.addStat(WAYSTONE_ACTIVATED);
WaystoneManager.addPlayerWaystone(player, waystone);
WaystoneManager.sendPlayerWaystones(player);
}
if (WaystoneConfig.general.setSpawnPoint) {
EnumFacing blockFacing = state.getValue(FACING);
player.setSpawnPoint(new BlockPos(tileWaystone.getPos().offset(blockFacing)), true);
}
} else {
Waystones.proxy.playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, pos, 1f);
for (int i = 0; i < 32; i++) {
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 3, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, pos.getX() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, pos.getY() + 4, pos.getZ() + 0.5 + (world.rand.nextDouble() - 0.5) * 2, 0, -5, 0);
}
}
return true;
}
use of net.blay09.mods.waystones.block.TileWaystone in project Waystones by blay09.
the class HandlerEditWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageEditWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
EntityPlayer entityPlayer = ctx.getServerHandler().player;
if (WaystoneConfig.general.creativeModeOnly && !entityPlayer.capabilities.isCreativeMode) {
return;
}
World world = entityPlayer.getEntityWorld();
BlockPos pos = message.getPos();
if (entityPlayer.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 10) {
return;
}
GlobalWaystones globalWaystones = GlobalWaystones.get(ctx.getServerHandler().player.world);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileWaystone) {
TileWaystone tileWaystone = ((TileWaystone) tileEntity).getParent();
if (globalWaystones.getGlobalWaystone(tileWaystone.getWaystoneName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode && !WaystoneConfig.general.allowEveryoneGlobal) {
return;
}
if (WaystoneConfig.general.restrictRenameToOwner && !tileWaystone.isOwner(ctx.getServerHandler().player)) {
ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:notTheOwner"));
return;
}
if (globalWaystones.getGlobalWaystone(message.getName()) != null && !ctx.getServerHandler().player.capabilities.isCreativeMode) {
ctx.getServerHandler().player.sendMessage(new TextComponentTranslation("waystones:nameOccupied", message.getName()));
return;
}
WaystoneEntry oldWaystone = new WaystoneEntry(tileWaystone);
globalWaystones.removeGlobalWaystone(oldWaystone);
tileWaystone.setWaystoneName(message.getName());
WaystoneEntry newWaystone = new WaystoneEntry(tileWaystone);
if (message.isGlobal() && (ctx.getServerHandler().player.capabilities.isCreativeMode || WaystoneConfig.general.allowEveryoneGlobal)) {
tileWaystone.setGlobal(true);
newWaystone.setGlobal(true);
globalWaystones.addGlobalWaystone(newWaystone);
for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers()) {
WaystoneManager.sendPlayerWaystones((EntityPlayer) obj);
}
}
}
});
return null;
}
use of net.blay09.mods.waystones.block.TileWaystone in project Waystones by blay09.
the class WaystoneManager method getWaystoneInWorld.
@Nullable
public static TileWaystone getWaystoneInWorld(WaystoneEntry waystone) {
World targetWorld = DimensionManager.getWorld(waystone.getDimensionId());
if (targetWorld == null) {
DimensionManager.initDimension(waystone.getDimensionId());
targetWorld = DimensionManager.getWorld(waystone.getDimensionId());
}
if (targetWorld != null) {
TileEntity tileEntity = targetWorld.getTileEntity(waystone.getPos());
if (tileEntity instanceof TileWaystone) {
return ((TileWaystone) tileEntity).getParent();
}
}
return null;
}
use of net.blay09.mods.waystones.block.TileWaystone in project Waystones by blay09.
the class BlockWaystone method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileWaystone tileWaystone = getTileWaystone(world, pos);
if (tileWaystone != null) {
WaystoneEntry entry = new WaystoneEntry(tileWaystone);
if (tileWaystone.isGlobal()) {
GlobalWaystones.get(world).removeGlobalWaystone(entry);
}
for (EntityPlayer player : world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos).grow(64, 64, 64))) {
WaystoneManager.removePlayerWaystone(player, entry);
WaystoneManager.sendPlayerWaystones(player);
}
}
super.breakBlock(world, pos, state);
if (world.getBlockState(pos.up()).getBlock() == this) {
world.setBlockToAir(pos.up());
} else if (world.getBlockState(pos.down()).getBlock() == this) {
world.setBlockToAir(pos.down());
}
}
Aggregations