BloodMagic/src/main/java/WayofTime/bloodmagic/tile/TileTeleposer.java

150 lines
7.9 KiB
Java
Raw Normal View History

2015-12-31 04:00:49 +00:00
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.block.BlockTeleposer;
Command rework (#1434) * Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
2019-02-01 00:46:02 +00:00
import WayofTime.bloodmagic.command.sub.SubCommandTeleposer;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.core.data.SoulTicket;
import WayofTime.bloodmagic.event.TeleposeEvent;
import WayofTime.bloodmagic.item.ItemTelepositionFocus;
import WayofTime.bloodmagic.teleport.TeleportQueue;
Command rework (#1434) * Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
2019-02-01 00:46:02 +00:00
import WayofTime.bloodmagic.teleport.Teleports;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import java.util.List;
import java.util.UUID;
2016-01-01 17:08:17 +00:00
2017-08-16 04:30:48 +00:00
public class TileTeleposer extends TileInventory implements ITickable {
2016-01-01 17:08:17 +00:00
//TODO FUTURE: Make AreaDescriptor for Teleposer perhaps?
public static final String TELEPOSER_RANGE = "teleposerRange";
private int previousInput;
2017-08-16 04:30:48 +00:00
public TileTeleposer() {
2016-01-01 17:08:17 +00:00
super(1, "teleposer");
}
@Override
2017-08-16 04:30:48 +00:00
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
2016-01-01 17:08:17 +00:00
previousInput = tagCompound.getInteger(Constants.NBT.PREVIOUS_INPUT);
}
@Override
2017-08-16 04:30:48 +00:00
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
2016-01-01 17:08:17 +00:00
tagCompound.setInteger(Constants.NBT.PREVIOUS_INPUT, previousInput);
return tagCompound;
2016-01-01 17:08:17 +00:00
}
@Override
2017-08-16 04:30:48 +00:00
public void update() {
if (!getWorld().isRemote && canInitiateTeleport()) {
2016-12-13 03:56:36 +00:00
int currentInput = getWorld().getStrongPower(pos);
2016-01-01 17:08:17 +00:00
2017-08-16 04:30:48 +00:00
if (previousInput == 0 && currentInput != 0) {
2016-01-01 17:08:17 +00:00
initiateTeleport();
}
previousInput = currentInput;
Command rework (#1434) * Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
2019-02-01 00:46:02 +00:00
if (world.getTotalWorldTime() % 100 == 0) {
ItemStack focusStack = getStackInSlot(0);
if (!focusStack.isEmpty()) {
if (((ItemTelepositionFocus) focusStack.getItem()).getBinding(focusStack) != null)
SubCommandTeleposer.teleposerSet.add(this);
else
SubCommandTeleposer.teleposerSet.remove(this);
} else
SubCommandTeleposer.teleposerSet.remove(this);
}
2016-01-01 17:08:17 +00:00
}
}
2017-08-16 04:30:48 +00:00
public void initiateTeleport() {
if (!getWorld().isRemote && canInitiateTeleport() && getBlockType() instanceof BlockTeleposer) {
ItemStack focusStack = getStackInSlot(0);
ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem();
Binding binding = focus.getBinding(focusStack);
if (binding == null)
return;
Command rework (#1434) * Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
2019-02-01 00:46:02 +00:00
BlockPos focusPos = focus.getBlockPos(focusStack);
World focusWorld = focus.getWorld(focusStack);
if (focusWorld == null)
return;
2016-01-01 17:08:17 +00:00
TileEntity boundTile = focusWorld.getTileEntity(focusPos);
if (boundTile instanceof TileTeleposer && boundTile != this) {
Command rework (#1434) * Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
2019-02-01 00:46:02 +00:00
final int focusLevel = (focusStack.getItemDamage() + 1);
2016-01-01 17:08:17 +00:00
final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ())));
if (NetworkHelper.syphonFromContainer(focusStack, SoulTicket.block(world, pos, lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1)))) {
2016-01-01 17:08:17 +00:00
int blocksTransported = 0;
2017-08-16 04:30:48 +00:00
for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) {
for (int j = 0; j <= (focusLevel * 2 - 2); j++) {
for (int k = -(focusLevel - 1); k <= (focusLevel - 1); k++) {
2016-12-13 03:56:36 +00:00
TeleposeEvent event = new TeleposeEvent(getWorld(), pos.add(i, 1 + j, k), focusWorld, focusPos.add(i, 1 + j, k));
if (!MinecraftForge.EVENT_BUS.post(event) && Utils.swapLocations(event.initalWorld, event.initialBlockPos, event.finalWorld, event.finalBlockPos)) {
2016-01-01 17:08:17 +00:00
blocksTransported++;
}
}
}
}
NetworkHelper.syphonFromContainer(focusStack, SoulTicket.item(focusStack, world, pos, lpToBeDrained * blocksTransported));
List<Entity> originalWorldEntities;
List<Entity> focusWorldEntities;
AxisAlignedBB originalArea = new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, Math.min(focusWorld.getHeight(), pos.getY() + 2 * focusLevel), pos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
2016-12-13 03:56:36 +00:00
originalWorldEntities = getWorld().getEntitiesWithinAABB(Entity.class, originalArea);
AxisAlignedBB focusArea = new AxisAlignedBB(focusPos.getX(), focusPos.getY() + 1, focusPos.getZ(), focusPos.getX() + 1, Math.min(focusWorld.getHeight(), focusPos.getY() + 2 * focusLevel), focusPos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
focusWorldEntities = focusWorld.getEntitiesWithinAABB(Entity.class, focusArea);
UUID bindingOwnerID = binding.getOwnerId();
2017-08-16 04:30:48 +00:00
if (focusWorld.equals(getWorld())) {
if (!originalWorldEntities.isEmpty()) {
for (Entity entity : originalWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, bindingOwnerID, true));
}
}
if (!focusWorldEntities.isEmpty()) {
for (Entity entity : focusWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - focusPos.getX() + pos.getX(), entity.posY - focusPos.getY() + pos.getY(), entity.posZ - focusPos.getZ() + pos.getZ()), entity, bindingOwnerID, true));
}
}
} else {
if (!originalWorldEntities.isEmpty()) {
for (Entity entity : originalWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, bindingOwnerID, getWorld(), focusWorld.provider.getDimension(), true));
2016-01-01 17:08:17 +00:00
}
}
2017-08-16 04:30:48 +00:00
if (!focusWorldEntities.isEmpty()) {
for (Entity entity : focusWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - focusPos.getX() + pos.getX(), entity.posY - focusPos.getY() + pos.getY(), entity.posZ - focusPos.getZ() + pos.getZ()), entity, bindingOwnerID, focusWorld, getWorld().provider.getDimension(), true));
2016-01-01 17:08:17 +00:00
}
}
}
}
}
}
}
private boolean canInitiateTeleport() {
ItemStack focusStack = getStackInSlot(0);
return !focusStack.isEmpty() && focusStack.getItem() instanceof ItemTelepositionFocus && ((ItemTelepositionFocus) focusStack.getItem()).getBinding(focusStack) != null;
2016-01-01 17:08:17 +00:00
}
2015-12-31 04:00:49 +00:00
}