use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class PacketSyncDimensionInfo method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
int size = buf.readInt();
dimensions = new HashMap<Integer, DimensionDescriptor>();
for (int i = 0; i < size; i++) {
int id = buf.readInt();
PacketBuffer buffer = new PacketBuffer(buf);
NBTTagCompound tagCompound;
try {
tagCompound = PacketBufferTools.readCompoundTag(buffer);
} catch (IOException e) {
e.printStackTrace();
return;
}
DimensionDescriptor descriptor = new DimensionDescriptor(tagCompound);
dimensions.put(id, descriptor);
}
size = buf.readInt();
dimensionInformation = new HashMap<Integer, DimensionInformation>();
for (int i = 0; i < size; i++) {
int id = buf.readInt();
String name = NetworkTools.readString(buf);
DimensionInformation dimInfo = new DimensionInformation(name, dimensions.get(id), buf);
dimensionInformation.put(id, dimInfo);
}
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class DimensionEnscriberTileEntity method convertToDimensionDescriptor.
/**
* Convert the dimlets in the inventory to a dimension descriptor.
*/
private DimensionDescriptor convertToDimensionDescriptor() {
List<DimletKey> descriptors = new ArrayList<>();
long forcedSeed = 0;
for (int i = 0; i < DimensionEnscriberContainer.SIZE_DIMLETS; i++) {
ItemStack stack = inventoryHelper.getStackInSlot(i + DimensionEnscriberContainer.SLOT_DIMLETS);
if (ItemStackTools.isValid(stack)) {
DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
Settings settings = KnownDimletConfiguration.getSettings(key);
if (settings != null) {
// Make sure the dimlet is not blacklisted.
descriptors.add(key);
NBTTagCompound tagCompound = stack.getTagCompound();
if (tagCompound != null && tagCompound.getLong("forcedSeed") != 0) {
forcedSeed = tagCompound.getLong("forcedSeed");
}
}
}
inventoryHelper.setStackInSlot(i + DimensionEnscriberContainer.SLOT_DIMLETS, ItemStackTools.getEmptyStack());
}
return new DimensionDescriptor(descriptors, forcedSeed);
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class DimensionEnscriberTileEntity method storeDimlets.
private void storeDimlets(EntityPlayerMP player) {
if (GeneralConfiguration.ownerDimletsNeeded) {
if (checkOwnerDimlet()) {
Logging.warn(player, "You need an owner dimlet to make a dimension!");
return;
}
}
DimensionDescriptor descriptor = convertToDimensionDescriptor();
ItemStack realizedTab = createRealizedTab(descriptor, getWorld());
inventoryHelper.setStackInSlot(DimensionEnscriberContainer.SLOT_TAB, realizedTab);
markDirty();
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class DimensionTickEvent method serverTick.
private void serverTick(World entityWorld, boolean doEffects) {
RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(entityWorld);
if (!dimensionManager.getDimensions().isEmpty()) {
DimensionStorage dimensionStorage = DimensionStorage.getDimensionStorage(entityWorld);
for (Map.Entry<Integer, DimensionDescriptor> entry : dimensionManager.getDimensions().entrySet()) {
Integer id = entry.getKey();
// If there is an activity probe we only drain power if the dimension is loaded (a player is there or a chunkloader)
DimensionInformation information = dimensionManager.getDimensionInformation(id);
if (!information.isCheater()) {
WorldServer world = DimensionManager.getWorld(id);
// Power handling.
if ((world != null && world.getChunkProvider().getLoadedChunkCount() > 0) || information.getProbeCounter() == 0) {
handlePower(doEffects, dimensionStorage, entry, id, information);
}
// Special effect handling.
if (world != null && !world.playerEntities.isEmpty()) {
handleRandomEffects(world, information);
}
}
}
dimensionStorage.save(entityWorld);
}
}
use of mcjty.rftoolsdim.dimensions.description.DimensionDescriptor in project RFToolsDimensions by McJty.
the class RfToolsDimensionManager method writeToNBT.
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
NBTTagList lst = new NBTTagList();
for (Map.Entry<Integer, DimensionDescriptor> me : dimensions.entrySet()) {
NBTTagCompound tc = new NBTTagCompound();
Integer id = me.getKey();
tc.setInteger("id", id);
me.getValue().writeToNBT(tc);
DimensionInformation dimensionInfo = dimensionInformation.get(id);
dimensionInfo.writeToNBT(tc);
lst.appendTag(tc);
}
tagCompound.setTag("dimensions", lst);
List<Integer> ids = new ArrayList<Integer>(reclaimedIds);
int[] lstIds = new int[ids.size()];
for (int i = 0; i < ids.size(); i++) {
lstIds[i] = ids.get(i);
}
tagCompound.setIntArray("reclaimedIds", lstIds);
return tagCompound;
}
Aggregations