use of net.blay09.mods.waystones.util.WaystoneEntry 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());
}
}
use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.
the class GlobalWaystones method writeToNBT.
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
NBTTagList tagList = new NBTTagList();
for (WaystoneEntry entry : globalWaystones.values()) {
tagList.appendTag(entry.writeToNBT());
}
tagCompound.setTag(TAG_LIST_NAME, tagList);
return tagCompound;
}
use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.
the class HandlerSortWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageSortWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
PlayerWaystoneData waystoneData = PlayerWaystoneData.fromPlayer(ctx.getServerHandler().player);
WaystoneEntry[] entries = waystoneData.getWaystones();
int index = message.getIndex();
int otherIndex = message.getOtherIndex();
if (index < 0 || index >= entries.length || otherIndex < 0 || otherIndex >= entries.length) {
return;
}
WaystoneEntry swap = entries[index];
entries[index] = entries[otherIndex];
entries[otherIndex] = swap;
waystoneData.store(ctx.getServerHandler().player);
WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
});
return null;
}
use of net.blay09.mods.waystones.util.WaystoneEntry in project Waystones by blay09.
the class HandlerTeleportToWaystone method onMessage.
@Override
@Nullable
public IMessage onMessage(final MessageTeleportToWaystone message, final MessageContext ctx) {
NetworkHandler.getThreadListener(ctx).addScheduledTask(() -> {
EntityPlayer player = ctx.getServerHandler().player;
int dist = (int) Math.sqrt(player.getDistanceSqToCenter(message.getWaystone().getPos()));
int xpLevelCost = WaystoneConfig.general.blocksPerXPLevel > 0 ? MathHelper.clamp(dist / WaystoneConfig.general.blocksPerXPLevel, 0, WaystoneConfig.general.maximumXpCost) : 0;
ItemStack heldItem = player.getHeldItem(message.getHand());
switch(message.getWarpMode()) {
case INVENTORY_BUTTON:
if (!WaystoneConfig.general.teleportButtonReturnOnly && (!WaystoneConfig.general.inventoryButtonXpCost || player.experienceLevel < xpLevelCost)) {
return;
}
if (!WaystoneConfig.general.teleportButton || WaystoneConfig.general.teleportButtonReturnOnly || !PlayerWaystoneHelper.canFreeWarp(ctx.getServerHandler().player)) {
return;
}
break;
case WARP_SCROLL:
if (heldItem.isEmpty() || heldItem.getItem() != Waystones.itemWarpScroll) {
return;
}
break;
case WARP_STONE:
if (WaystoneConfig.general.warpStoneXpCost && player.experienceLevel < xpLevelCost) {
return;
}
if (heldItem.isEmpty() || heldItem.getItem() != Waystones.itemWarpStone) {
return;
}
if (!PlayerWaystoneHelper.canUseWarpStone(player)) {
return;
}
break;
case WAYSTONE:
if (WaystoneConfig.general.waystoneXpCost && player.experienceLevel < xpLevelCost) {
return;
}
WaystoneEntry fromWaystone = message.getFromWaystone();
if (fromWaystone == null || WaystoneManager.getWaystoneInWorld(fromWaystone) == null) {
return;
}
break;
}
if (WaystoneManager.teleportToWaystone(ctx.getServerHandler().player, message.getWaystone())) {
boolean shouldCooldown = !(message.getWaystone().isGlobal() && WaystoneConfig.general.globalNoCooldown);
switch(message.getWarpMode()) {
case INVENTORY_BUTTON:
if (shouldCooldown) {
PlayerWaystoneHelper.setLastFreeWarp(ctx.getServerHandler().player, System.currentTimeMillis());
}
if (WaystoneConfig.general.inventoryButtonXpCost) {
player.addExperienceLevel(-xpLevelCost);
}
break;
case WARP_SCROLL:
heldItem.shrink(1);
break;
case WARP_STONE:
if (WaystoneConfig.general.warpStoneXpCost) {
player.addExperienceLevel(-xpLevelCost);
}
if (shouldCooldown) {
PlayerWaystoneHelper.setLastWarpStoneUse(ctx.getServerHandler().player, System.currentTimeMillis());
}
break;
case WAYSTONE:
if (WaystoneConfig.general.waystoneXpCost) {
player.addExperienceLevel(-xpLevelCost);
}
break;
}
}
WaystoneManager.sendPlayerWaystones(ctx.getServerHandler().player);
});
return null;
}
Aggregations