use of mekanism.api.Coord4D in project Mekanism by mekanism.
the class RadiationManager method radiate.
@Override
public void radiate(Coord4D coord, double magnitude) {
if (!isRadiationEnabled()) {
return;
}
Map<Coord4D, RadiationSource> radiationSourceMap = radiationTable.row(new Chunk3D(coord));
RadiationSource src = radiationSourceMap.get(coord);
if (src == null) {
radiationSourceMap.put(coord, new RadiationSource(coord, magnitude));
} else {
src.radiate(magnitude);
}
markDirty();
}
use of mekanism.api.Coord4D in project Mekanism by mekanism.
the class TransmitterNetworkRegistry method registerOrphanTransmitter.
public static void registerOrphanTransmitter(Transmitter<?, ?, ?> transmitter) {
if (!getInstance().invalidTransmitters.remove(transmitter)) {
// If we weren't an invalid transmitter, then we need to add it as a new orphan, otherwise removing it is good enough
// as if it was an orphan before it still will be one, and if it wasn't then it still will be part of the network it
// was in.
Coord4D coord = transmitter.getTileCoord();
Transmitter<?, ?, ?> previous = getInstance().newOrphanTransmitters.put(coord, transmitter);
if (previous != null && previous != transmitter) {
Mekanism.logger.error("Different orphan transmitter was already registered at location! {}", coord);
}
}
}
use of mekanism.api.Coord4D in project Mekanism by mekanism.
the class CCArgumentWrapper method wrapReturnType.
private static Object wrapReturnType(Object result) {
if (result == null || result instanceof Number || result instanceof Boolean || result instanceof String) {
// Short circuit if it doesn't need wrapping
return result;
} else if (result instanceof ResourceLocation || result instanceof UUID) {
return result.toString();
} else if (result instanceof ForgeRegistryEntry<?>) {
return getName((ForgeRegistryEntry<?>) result);
} else if (result instanceof ChemicalStack<?>) {
ChemicalStack<?> stack = (ChemicalStack<?>) result;
Map<String, Object> wrapped = new HashMap<>(2);
wrapped.put("name", getName(stack.getType()));
wrapped.put("amount", stack.getAmount());
return wrapped;
} else if (result instanceof FluidStack) {
FluidStack stack = (FluidStack) result;
return wrapStack(stack.getFluid(), "amount", stack.getAmount(), stack.getTag());
} else if (result instanceof ItemStack) {
ItemStack stack = (ItemStack) result;
return wrapStack(stack.getItem(), "count", stack.getCount(), stack.getTag());
} else if (result instanceof INBT) {
Object wrapped = wrapNBT((INBT) result);
if (wrapped != null) {
return wrapped;
}
} else if (result instanceof Vector3i) {
// BlockPos is covered by this case
Vector3i pos = (Vector3i) result;
Map<String, Object> wrapped = new HashMap<>(3);
wrapped.put("x", pos.getX());
wrapped.put("y", pos.getY());
wrapped.put("z", pos.getZ());
return wrapped;
} else if (result instanceof Coord4D) {
// BlockPos is covered by this case
Coord4D coord = (Coord4D) result;
Map<String, Object> wrapped = new HashMap<>(4);
wrapped.put("x", coord.getX());
wrapped.put("y", coord.getY());
wrapped.put("z", coord.getZ());
wrapped.put("dimension", wrapReturnType(coord.dimension.location()));
return wrapped;
} else if (result instanceof Frequency) {
FrequencyIdentity identity = ((Frequency) result).getIdentity();
Map<String, Object> wrapped = new HashMap<>(2);
wrapped.put("key", wrapReturnType(identity.getKey()));
wrapped.put("public", identity.isPublic());
return wrapped;
} else if (result instanceof Enum) {
return ((Enum<?>) result).name();
} else if (result instanceof IFilter) {
Map<String, Object> wrapped = new HashMap<>();
wrapped.put("type", wrapReturnType(((IFilter<?>) result).getFilterType()));
if (result instanceof IItemStackFilter) {
ItemStack stack = ((IItemStackFilter<?>) result).getItemStack();
wrapped.put("item", wrapReturnType(stack.getItem()));
if (!stack.isEmpty()) {
CompoundNBT tag = stack.getTag();
if (tag != null && !tag.isEmpty()) {
wrapped.put("itemNBT", wrapNBT(tag));
}
}
} else if (result instanceof IMaterialFilter) {
wrapped.put("materialItem", wrapReturnType(((IMaterialFilter<?>) result).getMaterialItem().getItem()));
} else if (result instanceof IModIDFilter) {
wrapped.put("modId", ((IModIDFilter<?>) result).getModID());
} else if (result instanceof ITagFilter) {
wrapped.put("tag", ((ITagFilter<?>) result).getTagName());
}
if (result instanceof MinerFilter) {
MinerFilter<?> minerFilter = (MinerFilter<?>) result;
wrapped.put("requiresReplacement", minerFilter.requiresReplacement);
wrapped.put("replaceTarget", wrapReturnType(minerFilter.replaceTarget));
} else if (result instanceof SorterFilter) {
SorterFilter<?> sorterFilter = (SorterFilter<?>) result;
wrapped.put("allowDefault", sorterFilter.allowDefault);
wrapped.put("color", wrapReturnType(sorterFilter.color));
wrapped.put("size", sorterFilter.sizeMode);
wrapped.put("min", sorterFilter.min);
wrapped.put("max", sorterFilter.max);
if (sorterFilter instanceof SorterItemStackFilter) {
SorterItemStackFilter filter = (SorterItemStackFilter) sorterFilter;
wrapped.put("fuzzy", filter.fuzzyMode);
}
} else if (result instanceof QIOFilter) {
QIOFilter<?> qioFilter = (QIOFilter<?>) result;
if (qioFilter instanceof QIOItemStackFilter) {
QIOItemStackFilter filter = (QIOItemStackFilter) qioFilter;
wrapped.put("fuzzy", filter.fuzzyMode);
}
} else if (result instanceof OredictionificatorFilter) {
OredictionificatorFilter<?, ?, ?> filter = (OredictionificatorFilter<?, ?, ?>) result;
wrapped.put("target", filter.getFilterText());
wrapped.put("selected", wrapReturnType(filter.getResultElement()));
}
return wrapped;
} else if (result instanceof Map) {
return ((Map<?, ?>) result).entrySet().stream().collect(Collectors.toMap(entry -> wrapReturnType(entry.getKey()), entry -> wrapReturnType(entry.getValue()), (a, b) -> b));
} else if (result instanceof Collection) {
// so there is no real difference at that point about the type it is
return ((Collection<?>) result).stream().map(CCArgumentWrapper::wrapReturnType).collect(Collectors.toList());
} else if (result instanceof Object[]) {
// Note: This doesn't handle/deal with primitive arrays
return Arrays.stream((Object[]) result).map(CCArgumentWrapper::wrapReturnType).toArray();
}
return result;
}
use of mekanism.api.Coord4D in project Mekanism by mekanism.
the class InventoryFrequency method update.
@Override
public void update(TileEntity tile) {
super.update(tile);
Coord4D coord = Coord4D.get(tile);
if (tile instanceof TileEntityQuantumEntangloporter) {
// This should always be the case, but validate it and remove if it isn't
activeQEs.put(coord, (TileEntityQuantumEntangloporter) tile);
} else {
activeQEs.remove(coord);
}
}
use of mekanism.api.Coord4D in project Mekanism by mekanism.
the class RadiationCommand method addRadiation.
private static int addRadiation(CommandSource source, Vector3d pos, World world, double magnitude) {
Coord4D location = new Coord4D(pos.x, pos.y, pos.z, world.dimension());
MekanismAPI.getRadiationManager().radiate(location, magnitude);
source.sendSuccess(MekanismLang.COMMAND_RADIATION_ADD.translateColored(EnumColor.GRAY, RadiationScale.getSeverityColor(magnitude), UnitDisplayUtils.getDisplayShort(magnitude, RadiationUnit.SVH, 3), EnumColor.INDIGO, getPosition(location.getPos()), EnumColor.INDIGO, location.dimension.location()), true);
return 0;
}
Aggregations