use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.
the class RealizedDimensionTab method clOnItemRightClick.
@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if ((!world.isRemote) && player.isSneaking()) {
NBTTagCompound tagCompound = stack.getTagCompound();
Logging.message(player, tagCompound.getString("descriptionString"));
int id = tagCompound.getInteger("id");
if (id != 0) {
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
DimensionInformation information = dimensionManager.getDimensionInformation(id);
if (information != null) {
information.dump(player);
}
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.
the class DimensionMonitorItem method clOnItemRightClick.
@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
int id = player.getEntityWorld().provider.getDimension();
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld());
DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
if (dimensionInformation == null) {
Logging.message(player, "Not an RFTools dimension!");
} else {
String name = dimensionInformation.getName();
DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
int power = storage != null ? storage.getEnergyLevel(id) : 0;
Logging.message(player, TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + TextFormatting.YELLOW + " Power: " + power + " RF");
if (player.isSneaking()) {
Logging.message(player, TextFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
System.out.println("Description: = " + dimensionInformation.getDescriptor().getDescriptionString());
}
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.
the class DimensionEditorTileEntity method update.
@Override
public void update() {
if (getWorld().isRemote) {
return;
}
ItemStack injectableItemStack = validateInjectableItemStack();
if (injectableItemStack.isEmpty()) {
return;
}
ItemStack dimensionItemStack = validateDimensionItemStack();
if (dimensionItemStack.isEmpty()) {
return;
}
if (ticksLeft == -1) {
// We were not injecting. Start now.
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
int id = dimensionItemStack.getTagCompound().getInteger("id");
if (dimensionManager.getDimensionInformation(id).isCheater()) {
ticksCost = 1;
rfPerTick = 0;
} else if (isMatterReceiver(injectableItemStack)) {
ticksCost = DimletCosts.baseDimensionTickCost + 1000;
rfPerTick = DimletCosts.baseDimensionCreationCost + 200;
} else if (isTNT(injectableItemStack)) {
ticksCost = 600;
rfPerTick = 10;
} else {
DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
Settings settings = KnownDimletConfiguration.getSettings(key);
if (DimletObjectMapping.getSpecial(key) == SpecialType.SPECIAL_CHEATER) {
ticksCost = 1;
rfPerTick = 0;
} else {
ticksCost = DimletCosts.baseDimensionTickCost + settings.getTickCost();
rfPerTick = DimletCosts.baseDimensionCreationCost + settings.getCreateCost();
}
}
ticksLeft = ticksCost;
} else {
int rf = getEnergyStored();
int rfpt = rfPerTick;
rfpt = (int) (rfpt * (2.0f - getInfusedFactor()) / 2.0f);
if (rf >= rfpt) {
// Enough energy.
consumeEnergy(rfpt);
ticksLeft--;
if (ticksLeft <= 0) {
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
NBTTagCompound tagCompound = dimensionItemStack.getTagCompound();
int id = tagCompound.getInteger("id");
if (isMatterReceiver(injectableItemStack)) {
World dimWorld = RfToolsDimensionManager.getWorldForDimension(getWorld(), id);
int y = findGoodReceiverLocation(dimWorld);
if (y == -1) {
y = dimWorld.getHeight() / 2;
}
Item item = injectableItemStack.getItem();
if (item instanceof ItemBlock) {
ItemBlock itemBlock = (ItemBlock) item;
IBlockState state = itemBlock.getBlock().getStateFromMeta(itemBlock.getMetadata(injectableItemStack));
BlockPos pos = new BlockPos(8, y, 8);
dimWorld.setBlockState(pos, state, 2);
Block block = dimWorld.getBlockState(pos).getBlock();
// @todo @@@@@@@@@@@@@@ check if right?
block.onBlockActivated(dimWorld, pos, state, FakePlayerFactory.getMinecraft((WorldServer) dimWorld), EnumHand.MAIN_HAND, EnumFacing.DOWN, 0.0F, 0.0F, 0.0F);
// block.onBlockPlaced(dimWorld, pos, EnumFacing.DOWN, 0, 0, 0, 0, null);
block.onBlockPlacedBy(dimWorld, pos, state, null, injectableItemStack);
dimWorld.setBlockToAir(pos.up());
dimWorld.setBlockToAir(pos.up(2));
}
} else if (isTNT(injectableItemStack)) {
safeDeleteDimension(id, dimensionItemStack);
} else {
DimletKey key = KnownDimletConfiguration.getDimletKey(injectableItemStack);
DimensionInformation information = dimensionManager.getDimensionInformation(id);
information.injectDimlet(key);
dimensionManager.save(getWorld());
}
inventoryHelper.decrStackSize(DimensionEditorContainer.SLOT_INJECTINPUT, 1);
stopInjecting();
}
}
}
markDirty();
setState();
}
use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.
the class DimensionEditorTileEntity method safeDeleteDimension.
private void safeDeleteDimension(int id, ItemStack dimensionTab) {
World w = DimensionManager.getWorld(id);
if (w != null) {
// Dimension is still loaded. Do nothing.
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension cannot be deleted. It is still in use!", 10);
return;
}
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(getWorld());
DimensionInformation information = dimensionManager.getDimensionInformation(id);
if (information.getOwner() == null) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "You cannot delete a dimension without an owner!", 10);
return;
}
if (getOwnerUUID() == null) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine has no proper owner and cannot delete dimensions!", 10);
return;
}
if (!getOwnerUUID().equals(information.getOwner())) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "This machine's owner differs from the dimensions owner!", 10);
return;
}
RFToolsDim.teleportationManager.removeReceiverDestinations(getWorld(), id);
dimensionManager.removeDimension(id);
dimensionManager.reclaimId(id);
dimensionManager.save(getWorld());
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(getWorld());
dimensionStorage.removeDimension(id);
dimensionStorage.save(getWorld());
if (GeneralConfiguration.dimensionFolderIsDeletedWithSafeDel) {
File rootDirectory = DimensionManager.getCurrentSaveRootDirectory();
try {
FileUtils.deleteDirectory(new File(rootDirectory.getPath() + File.separator + "RFTOOLS" + id));
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted and dimension folder succesfully wiped!", 10);
} catch (IOException e) {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted but dimension folder could not be completely wiped!", 10);
}
} else {
Broadcaster.broadcast(getWorld(), pos.getX(), pos.getY(), pos.getZ(), "Dimension deleted. Please remove the dimension folder from disk!", 10);
}
dimensionTab.getTagCompound().removeTag("id");
int tickCost = dimensionTab.getTagCompound().getInteger("tickCost");
dimensionTab.getTagCompound().setInteger("ticksLeft", tickCost);
}
use of mcjty.rftoolsdim.dimensions.RfToolsDimensionManager in project RFToolsDimensions by McJty.
the class ActivityProbeBlock method getStateForPlacement.
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer);
if (!world.isRemote) {
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
DimensionInformation information = dimensionManager.getDimensionInformation(world.provider.getDimension());
if (information != null) {
information.addProbe();
}
dimensionManager.save(world);
}
return state;
}
Aggregations