use of mekanism.api.text.EnumColor in project Mekanism by mekanism.
the class InventoryNetwork method calculateAcceptors.
public List<AcceptorData> calculateAcceptors(TransitRequest request, TransporterStack stack, Long2ObjectMap<IChunk> chunkMap) {
List<AcceptorData> toReturn = new ArrayList<>();
for (Map.Entry<BlockPos, Map<Direction, LazyOptional<IItemHandler>>> entry : acceptorCache.getAcceptorEntrySet()) {
BlockPos pos = entry.getKey();
if (!pos.equals(stack.homeLocation)) {
TileEntity acceptor = WorldUtils.getTileEntity(getWorld(), chunkMap, pos);
if (acceptor == null) {
continue;
}
Map<TransitResponse, AcceptorData> dataMap = new HashMap<>();
Coord4D position = new Coord4D(pos, getWorld());
for (Map.Entry<Direction, LazyOptional<IItemHandler>> acceptorEntry : entry.getValue().entrySet()) {
Optional<IItemHandler> handler = acceptorEntry.getValue().resolve();
if (handler.isPresent()) {
Direction side = acceptorEntry.getKey();
// actually need to even query the TE
if (acceptor instanceof ISideConfiguration) {
// If the acceptor in question implements the mekanism interface, check that the color matches and bail fast if it doesn't
ISideConfiguration config = (ISideConfiguration) acceptor;
if (config.getEjector().hasStrictInput()) {
EnumColor configColor = config.getEjector().getInputColor(RelativeSide.fromDirections(config.getDirection(), side));
if (configColor != null && configColor != stack.color) {
continue;
}
}
}
TransitResponse response = TransporterManager.getPredictedInsert(position, side, handler.get(), request);
if (!response.isEmpty()) {
Direction opposite = side.getOpposite();
// If the response isn't empty, check if we already have acceptor data for
// a matching response at the destination
AcceptorData data = dataMap.get(response);
if (data == null) {
// If we don't, add a new acceptor data for the response and position with side
data = new AcceptorData(pos, response, opposite);
dataMap.put(response, data);
toReturn.add(data);
// Note: In theory this shouldn't cause any issues if some exposed slots overlap but are for
// different acceptor data/sides as our predicted insert takes into account all en-route
// items to the destination, and only checks about the side if none are actually able to be
// inserted in the first place
} else {
// If we do, add our side as one of the sides it can accept things from for that response
// This equates to the destination being the same
data.sides.add(opposite);
}
}
}
}
}
}
return toReturn;
}
use of mekanism.api.text.EnumColor in project Mekanism by mekanism.
the class TileEntityQIOComponent method onUpdateServer.
@Override
protected void onUpdateServer() {
super.onUpdateServer();
EnumColor prev = lastColor;
QIOFrequency frequency = getQIOFrequency();
lastColor = frequency == null ? null : frequency.getColor();
if (prev != lastColor) {
sendUpdatePacket();
}
if (level.getGameTime() % 10 == 0) {
setActive(frequency != null);
}
}
use of mekanism.api.text.EnumColor in project Mekanism by mekanism.
the class PigmentExtractingRecipeProvider method addExtractionRecipes.
private static void addExtractionRecipes(Consumer<IFinishedRecipe> consumer, String basePath) {
for (Map.Entry<EnumColor, PigmentRegistryObject<Pigment>> entry : MekanismPigments.PIGMENT_COLOR_LOOKUP.entrySet()) {
EnumColor color = entry.getKey();
IPigmentProvider pigment = entry.getValue();
DyeColor dye = color.getDyeColor();
if (dye != null) {
ItemStackToChemicalRecipeBuilder.pigmentExtracting(ItemStackIngredient.from(dye.getTag()), pigment.getStack(DYE_RATE)).build(consumer, Mekanism.rl(basePath + "dye/" + color.getRegistryPrefix()));
// TODO: Eventually we may want to consider taking patterns into account
ItemStackToChemicalRecipeBuilder.pigmentExtracting(ItemStackIngredient.from(BannerBlock.byColor(dye)), pigment.getStack(BANNER_RATE)).build(consumer, Mekanism.rl(basePath + "banner/" + color.getRegistryPrefix()));
addExtractionRecipe(consumer, color, CONCRETE, pigment, CONCRETE_RATE, basePath + "concrete/");
addExtractionRecipe(consumer, color, CONCRETE_POWDER, pigment, CONCRETE_POWDER_RATE, basePath + "concrete_powder/");
addExtractionRecipe(consumer, color, CARPETS, pigment, CARPET_RATE, basePath + "carpet/");
addExtractionRecipe(consumer, color, TERRACOTTA, pigment, CONCRETE_RATE, basePath + "terracotta/");
addTagExtractionRecipe(consumer, color, STAINED_GLASS, pigment, STAINED_GLASS_RATE, basePath + "stained_glass/");
addTagExtractionRecipe(consumer, color, STAINED_GLASS_PANES, pigment, STAINED_GLASS_PANE_RATE, basePath + "stained_glass_pane/");
addExtractionRecipe(consumer, color, WOOL, pigment, WOOL_RATE, basePath + "wool/");
}
}
}
use of mekanism.api.text.EnumColor in project Mekanism by mekanism.
the class LogisticalTransporter method onRightClick.
@Override
public ActionResultType onRightClick(PlayerEntity player, Direction side) {
EnumColor color = getColor();
player.sendMessage(MekanismUtils.logFormat(MekanismLang.CURRENT_COLOR.translate(color == null ? MekanismLang.NONE : color.getColoredName())), Util.NIL_UUID);
return super.onRightClick(player, side);
}
use of mekanism.api.text.EnumColor in project Mekanism by mekanism.
the class TransporterUtils method canInsert.
public static boolean canInsert(TileEntity tile, EnumColor color, ItemStack itemStack, Direction side, boolean force) {
if (force && tile instanceof TileEntityLogisticalSorter) {
return ((TileEntityLogisticalSorter) tile).canSendHome(itemStack);
}
if (!force && tile instanceof ISideConfiguration) {
ISideConfiguration config = (ISideConfiguration) tile;
if (config.getEjector().hasStrictInput()) {
Direction tileSide = config.getDirection();
EnumColor configColor = config.getEjector().getInputColor(RelativeSide.fromDirections(tileSide, side.getOpposite()));
if (configColor != null && configColor != color) {
return false;
}
}
}
Optional<IItemHandler> capability = CapabilityUtils.getCapability(tile, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()).resolve();
if (capability.isPresent()) {
IItemHandler inventory = capability.get();
for (int i = 0; i < inventory.getSlots(); i++) {
// Check validation
if (inventory.isItemValid(i, itemStack)) {
// Simulate insert
ItemStack rejects = inventory.insertItem(i, itemStack, true);
if (TransporterManager.didEmit(itemStack, rejects)) {
return true;
}
}
}
}
return false;
}
Aggregations