Move the grinder back to code.

This commit is contained in:
modmuss50 2022-05-21 19:16:54 +01:00
parent a162a5ab40
commit d0bdf744cf
13 changed files with 82 additions and 384 deletions

View file

@ -28,9 +28,9 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import techreborn.blockentity.GuiType; import techreborn.blockentity.GuiType;
import techreborn.blockentity.data.DataDrivenBEProvider;
import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity;
import techreborn.blockentity.generator.SolarPanelBlockEntity; import techreborn.blockentity.generator.SolarPanelBlockEntity;
import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity;
@ -82,6 +82,7 @@ public class ClientGuiType<T extends BlockEntity> {
public static final ClientGuiType<DistillationTowerBlockEntity> DISTILLATION_TOWER = register(GuiType.DISTILLATION_TOWER, GuiDistillationTower::new); public static final ClientGuiType<DistillationTowerBlockEntity> DISTILLATION_TOWER = register(GuiType.DISTILLATION_TOWER, GuiDistillationTower::new);
public static final ClientGuiType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register(GuiType.ELECTRIC_FURNACE, GuiElectricFurnace::new); public static final ClientGuiType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register(GuiType.ELECTRIC_FURNACE, GuiElectricFurnace::new);
public static final ClientGuiType<ExtractorBlockEntity> EXTRACTOR = register(GuiType.EXTRACTOR, GuiExtractor::new); public static final ClientGuiType<ExtractorBlockEntity> EXTRACTOR = register(GuiType.EXTRACTOR, GuiExtractor::new);
public static final ClientGuiType<GrinderBlockEntity> GRINDER = register(GuiType.GRINDER, GuiGrinder::new);
public static final ClientGuiType<FusionControlComputerBlockEntity> FUSION_CONTROLLER = register(GuiType.FUSION_CONTROLLER, GuiFusionReactor::new); public static final ClientGuiType<FusionControlComputerBlockEntity> FUSION_CONTROLLER = register(GuiType.FUSION_CONTROLLER, GuiFusionReactor::new);
public static final ClientGuiType<GasTurbineBlockEntity> GAS_TURBINE = register(GuiType.GAS_TURBINE, GuiGasTurbine::new); public static final ClientGuiType<GasTurbineBlockEntity> GAS_TURBINE = register(GuiType.GAS_TURBINE, GuiGasTurbine::new);
public static final ClientGuiType<SolidFuelGeneratorBlockEntity> GENERATOR = register(GuiType.GENERATOR, GuiGenerator::new); public static final ClientGuiType<SolidFuelGeneratorBlockEntity> GENERATOR = register(GuiType.GENERATOR, GuiGenerator::new);
@ -110,7 +111,6 @@ public class ClientGuiType<T extends BlockEntity> {
public static final ClientGuiType<GreenhouseControllerBlockEntity> GREENHOUSE_CONTROLLER = register(GuiType.GREENHOUSE_CONTROLLER, GuiGreenhouseController::new); public static final ClientGuiType<GreenhouseControllerBlockEntity> GREENHOUSE_CONTROLLER = register(GuiType.GREENHOUSE_CONTROLLER, GuiGreenhouseController::new);
public static final ClientGuiType<FluidReplicatorBlockEntity> FLUID_REPLICATOR = register(GuiType.FLUID_REPLICATOR, GuiFluidReplicator::new); public static final ClientGuiType<FluidReplicatorBlockEntity> FLUID_REPLICATOR = register(GuiType.FLUID_REPLICATOR, GuiFluidReplicator::new);
public static final ClientGuiType<PlayerDetectorBlockEntity> PLAYER_DETECTOR = register(GuiType.PLAYER_DETECTOR, GuiPlayerDetector::new); public static final ClientGuiType<PlayerDetectorBlockEntity> PLAYER_DETECTOR = register(GuiType.PLAYER_DETECTOR, GuiPlayerDetector::new);
public static final ClientGuiType<DataDrivenBEProvider.DataDrivenBlockEntity> DATA_DRIVEN = register(GuiType.DATA_DRIVEN, DataDrivenGui::new);
public static final ClientGuiType<BlockBreakerBlockEntity> BLOCK_BREAKER = register(GuiType.BLOCK_BREAKER, GuiBlockBreaker::new); public static final ClientGuiType<BlockBreakerBlockEntity> BLOCK_BREAKER = register(GuiType.BLOCK_BREAKER, GuiBlockBreaker::new);
public static final ClientGuiType<BlockPlacerBlockEntity> BLOCK_PLACER = register(GuiType.BLOCK_PLACER, GuiBlockPlacer::new); public static final ClientGuiType<BlockPlacerBlockEntity> BLOCK_PLACER = register(GuiType.BLOCK_PLACER, GuiBlockPlacer::new);
@ -132,7 +132,7 @@ public class ClientGuiType<T extends BlockEntity> {
this.guiType = Objects.requireNonNull(guiType); this.guiType = Objects.requireNonNull(guiType);
this.guiFactory = Objects.requireNonNull(guiFactory); this.guiFactory = Objects.requireNonNull(guiFactory);
ScreenRegistry.register(guiType.getScreenHandlerType(), getGuiFactory()); HandledScreens.register(guiType.getScreenHandlerType(), getGuiFactory());
TYPES.put(guiType.getIdentifier(), this); TYPES.put(guiType.getIdentifier(), this);
} }

View file

@ -29,13 +29,14 @@ import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import reborncore.common.screen.BuiltScreenHandler; import reborncore.common.screen.BuiltScreenHandler;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public interface GuiFactory<T extends BlockEntity> extends ScreenRegistry.Factory<BuiltScreenHandler, HandledScreen<BuiltScreenHandler>> { public interface GuiFactory<T extends BlockEntity> extends HandledScreens.Provider<BuiltScreenHandler, HandledScreen<BuiltScreenHandler>> {
HandledScreen<?> create(int syncId, PlayerEntity playerEntity, T blockEntity); HandledScreen<?> create(int syncId, PlayerEntity playerEntity, T blockEntity);
@Override @Override

View file

@ -1,7 +1,7 @@
/* /*
* This file is part of TechReborn, licensed under the MIT License (MIT). * This file is part of TechReborn, licensed under the MIT License (MIT).
* *
* Copyright (c) 2020 TechReborn * Copyright (c) 2018 TechReborn
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -29,38 +29,29 @@ import net.minecraft.entity.player.PlayerEntity;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.common.screen.BuiltScreenHandler; import reborncore.common.screen.BuiltScreenHandler;
import techreborn.blockentity.data.DataDrivenBEProvider; import techreborn.blockentity.machine.tier1.GrinderBlockEntity;
import techreborn.blockentity.data.DataDrivenSlot;
import techreborn.blockentity.data.SlotType;
public class DataDrivenGui extends GuiBase<BuiltScreenHandler> { public class GuiGrinder extends GuiBase<BuiltScreenHandler> {
GrinderBlockEntity blockEntity;
private final DataDrivenBEProvider provider; public GuiGrinder(int syncID, final PlayerEntity player, final GrinderBlockEntity blockEntity) {
private final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity;
public DataDrivenGui(int syncID, final PlayerEntity player, final DataDrivenBEProvider.DataDrivenBlockEntity blockEntity) {
super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); super(player, blockEntity, blockEntity.createScreenHandler(syncID, player));
this.blockEntity = blockEntity; this.blockEntity = blockEntity;
this.provider = blockEntity.getProvider();
} }
@Override @Override
protected void drawBackground(MatrixStack matrixStack, final float f, final int mouseX, final int mouseY) { protected void drawBackground(MatrixStack matrixStack, final float f, final int mouseX, final int mouseY) {
super.drawBackground(matrixStack, f, mouseX, mouseY); super.drawBackground(matrixStack, f, mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
final DataDrivenGui gui = this;
provider.getSlots().forEach(slot -> draw(matrixStack, gui, layer, slot)); drawSlot(matrixStack, 8, 72, layer);
drawSlot(matrixStack, 55, 45, layer);
drawOutputSlot(matrixStack, 101, 45, layer);
builder.drawJEIButton(matrixStack, this, 158, 5, layer);
} }
public void draw(MatrixStack matrixStack, GuiBase<?> guiBase, GuiBase.Layer layer, DataDrivenSlot slot) {
if (slot.type() == SlotType.OUTPUT) {
guiBase.drawOutputSlot(matrixStack, slot.x(), slot.y(), layer);
} else {
guiBase.drawSlot(matrixStack, slot.x(), slot.y(), layer);
}
}
@Override @Override
protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) {
super.drawForeground(matrixStack, mouseX, mouseY); super.drawForeground(matrixStack, mouseX, mouseY);

View file

@ -41,7 +41,6 @@ import org.jetbrains.annotations.Nullable;
import reborncore.api.blockentity.IMachineGuiHandler; import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.screen.BuiltScreenHandler; import reborncore.common.screen.BuiltScreenHandler;
import reborncore.common.screen.BuiltScreenHandlerProvider; import reborncore.common.screen.BuiltScreenHandlerProvider;
import techreborn.blockentity.data.DataDrivenBEProvider;
import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity; import techreborn.blockentity.generator.PlasmaGeneratorBlockEntity;
import techreborn.blockentity.generator.SolarPanelBlockEntity; import techreborn.blockentity.generator.SolarPanelBlockEntity;
import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity; import techreborn.blockentity.generator.advanced.DieselGeneratorBlockEntity;
@ -108,6 +107,7 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
public static final GuiType<RecyclerBlockEntity> RECYCLER = register("recycler"); public static final GuiType<RecyclerBlockEntity> RECYCLER = register("recycler");
public static final GuiType<RollingMachineBlockEntity> ROLLING_MACHINE = register("rolling_machine"); public static final GuiType<RollingMachineBlockEntity> ROLLING_MACHINE = register("rolling_machine");
public static final GuiType<IndustrialSawmillBlockEntity> SAWMILL = register("sawmill"); public static final GuiType<IndustrialSawmillBlockEntity> SAWMILL = register("sawmill");
public static final GuiType<GrinderBlockEntity> GRINDER = register("grinder");
public static final GuiType<ScrapboxinatorBlockEntity> SCRAPBOXINATOR = register("scrapboxinator"); public static final GuiType<ScrapboxinatorBlockEntity> SCRAPBOXINATOR = register("scrapboxinator");
public static final GuiType<SolarPanelBlockEntity> SOLAR_PANEL = register("solar_panel"); public static final GuiType<SolarPanelBlockEntity> SOLAR_PANEL = register("solar_panel");
public static final GuiType<SemiFluidGeneratorBlockEntity> SEMIFLUID_GENERATOR = register("semifluid_generator"); public static final GuiType<SemiFluidGeneratorBlockEntity> SEMIFLUID_GENERATOR = register("semifluid_generator");
@ -118,7 +118,6 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
public static final GuiType<GreenhouseControllerBlockEntity> GREENHOUSE_CONTROLLER = register("greenhouse_controller"); public static final GuiType<GreenhouseControllerBlockEntity> GREENHOUSE_CONTROLLER = register("greenhouse_controller");
public static final GuiType<FluidReplicatorBlockEntity> FLUID_REPLICATOR = register("fluid_replicator"); public static final GuiType<FluidReplicatorBlockEntity> FLUID_REPLICATOR = register("fluid_replicator");
public static final GuiType<PlayerDetectorBlockEntity> PLAYER_DETECTOR = register("player_detector"); public static final GuiType<PlayerDetectorBlockEntity> PLAYER_DETECTOR = register("player_detector");
public static final GuiType<DataDrivenBEProvider.DataDrivenBlockEntity> DATA_DRIVEN = register("data_driven");
public static final GuiType<BlockBreakerBlockEntity> BLOCK_BREAKER = register("block_breaker"); public static final GuiType<BlockBreakerBlockEntity> BLOCK_BREAKER = register("block_breaker");
public static final GuiType<BlockPlacerBlockEntity> BLOCK_PLACER = register("block_placer"); public static final GuiType<BlockPlacerBlockEntity> BLOCK_PLACER = register("block_placer");

View file

@ -1,165 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.data;
import com.google.common.collect.ImmutableSet;
import com.google.gson.JsonObject;
import net.fabricmc.loader.launch.common.FabricLauncherBase;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.text.WordUtils;
import org.jetbrains.annotations.Nullable;
import reborncore.common.crafting.RebornRecipeType;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.screen.BuiltScreenHandler;
import reborncore.common.screen.BuiltScreenHandlerProvider;
import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder;
import reborncore.common.screen.builder.ScreenHandlerBuilder;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.serialization.SerializationUtil;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.init.ModRecipes;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.DataDrivenBlockEntity> implements BiFunction<BlockPos, BlockState, BlockEntity> {
private final Identifier identifier;
private final Block block;
private final int energy;
private final int maxInput;
private final List<DataDrivenSlot> slots;
public static DataDrivenBEProvider create(Block block, Identifier identifier) {
String location = String.format("%s/machines/%s.json", identifier.getNamespace(), identifier.getPath());
JsonObject jsonObject;
try {
jsonObject = SerializationUtil.GSON.fromJson(IOUtils.toString(FabricLauncherBase.getLauncher().getResourceAsStream(location), StandardCharsets.UTF_8), JsonObject.class);
} catch (Exception e) {
throw new RuntimeException("failed to read json: " + location, e);
}
Identifier id = new Identifier(JsonHelper.getString(jsonObject, "name"));
DataDrivenBEProvider provider = new DataDrivenBEProvider(block, jsonObject);
Registry.register(Registry.BLOCK_ENTITY_TYPE, id, provider);
return provider;
}
private DataDrivenBEProvider(Block block, JsonObject jsonObject) {
super(null, ImmutableSet.copyOf(Collections.singletonList(block)), null);
this.block = block;
this.identifier = new Identifier(JsonHelper.getString(jsonObject, "name"));
this.energy = JsonHelper.getInt(jsonObject, "energy");
this.maxInput = JsonHelper.getInt(jsonObject, "maxInput");
this.slots = DataDrivenSlot.read(JsonHelper.getArray(jsonObject, "slots"));
// Ensure there is an energy slot, doing it here ensures it crashes on game load
Validate.isTrue(getEnergySlot() > 0);
}
@Nullable
@Override
public DataDrivenBlockEntity instantiate(BlockPos pos, BlockState state) {
return new DataDrivenBlockEntity(this, pos, state);
}
public BuiltScreenHandler createScreenHandler(DataDrivenBlockEntity blockEntity, int syncID, PlayerEntity player) {
BlockEntityScreenHandlerBuilder builder = new ScreenHandlerBuilder(identifier.getPath()).player(player.getInventory())
.inventory().hotbar().addInventory().blockEntity(blockEntity);
slots.forEach(dataDrivenSlot -> dataDrivenSlot.add(builder));
builder.syncEnergyValue().syncCrafterValue();
return builder.addInventory().create(blockEntity, syncID);
}
//Used by the GenericMachineBlock
@Override
public BlockEntity apply(BlockPos pos, BlockState state) {
return instantiate(pos, state);
}
public static class DataDrivenBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
private final DataDrivenBEProvider provider;
private DataDrivenBlockEntity(DataDrivenBEProvider provider, BlockPos pos, BlockState state) {
super(provider, pos, state, provider.getSimpleName(), provider.maxInput, provider.energy, provider.block, provider.getEnergySlot());
this.provider = provider;
RebornRecipeType<?> recipeType = ModRecipes.byName(provider.identifier);
Validate.notNull(recipeType);
this.inventory = new RebornInventory<>(provider.slots.size(), provider.getSimpleName() + "BlockEntity", 64, this);
this.crafter = new RecipeCrafter(recipeType, this, provider.countOfSlotType(SlotType.INPUT), provider.countOfSlotType(SlotType.OUTPUT), this.inventory, provider.slotIds(SlotType.INPUT), provider.slotIds(SlotType.OUTPUT));
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, PlayerEntity player) {
return provider.createScreenHandler(this, syncID, player);
}
public DataDrivenBEProvider getProvider() {
return provider;
}
}
private int getEnergySlot() {
return slots.stream().filter(slot -> slot.type() == SlotType.ENERGY).findFirst().orElse(null).id();
}
private int countOfSlotType(SlotType type) {
return (int) slots.stream()
.filter(slot -> slot.type() == type)
.count();
}
private int[] slotIds(SlotType type) {
return slots.stream()
.filter(slot -> slot.type() == type)
.mapToInt(DataDrivenSlot::id)
.toArray();
}
public List<DataDrivenSlot> getSlots() {
return Collections.unmodifiableList(slots);
}
private String getSimpleName() {
return WordUtils.capitalize(identifier.getPath());
}
}

View file

@ -1,51 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.data;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import net.minecraft.util.JsonHelper;
import org.jetbrains.annotations.NotNull;
import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder;
import reborncore.common.util.serialization.SerializationUtil;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public record DataDrivenSlot(int id, int x, int y, @NotNull SlotType type) {
public static List<DataDrivenSlot> read(JsonArray jsonArray) {
AtomicInteger idCount = new AtomicInteger();
return SerializationUtil.stream(jsonArray)
.map(JsonElement::getAsJsonObject)
.map(json -> new DataDrivenSlot(idCount.getAndIncrement(), JsonHelper.getInt(json, "x"), JsonHelper.getInt(json, "y"), SlotType.fromString(JsonHelper.getString(json, "type"))))
.collect(Collectors.toList());
}
public void add(BlockEntityScreenHandlerBuilder inventoryBuilder) {
type.getSlotBiConsumer().accept(inventoryBuilder, this);
}
}

View file

@ -1,61 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.data;
import reborncore.common.screen.builder.BlockEntityScreenHandlerBuilder;
import java.util.Arrays;
import java.util.function.BiConsumer;
public enum SlotType {
// I'm really not a fan of the way I add the slots to the builder here
INPUT((builder, slot) -> {
builder.slot(slot.id(), slot.x(), slot.y());
}),
OUTPUT((builder, slot) -> {
builder.outputSlot(slot.id(), slot.x(), slot.y());
}),
ENERGY((builder, slot) -> {
builder.energySlot(slot.id(), slot.x(), slot.y());
});
public static SlotType fromString(String string) {
return Arrays.stream(values())
.filter(slotType -> slotType.name().equalsIgnoreCase(string))
.findFirst()
.orElse(null);
}
private final BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> slotBiConsumer;
SlotType(BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> slotBiConsumer) {
this.slotBiConsumer = slotBiConsumer;
}
public BiConsumer<BlockEntityScreenHandlerBuilder, DataDrivenSlot> getSlotBiConsumer() {
return slotBiConsumer;
}
}

View file

@ -0,0 +1,57 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.machine.tier1;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.screen.BuiltScreenHandler;
import reborncore.common.screen.BuiltScreenHandlerProvider;
import reborncore.common.screen.builder.ScreenHandlerBuilder;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModRecipes;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
public class GrinderBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
public GrinderBlockEntity(BlockPos pos, BlockState state) {
super(TRBlockEntities.GRINDER, pos, state, "Grinder", TechRebornConfig.grinderMaxInput, TechRebornConfig.grinderMaxEnergy, TRContent.Machine.GRINDER.block, 2);
final int[] inputs = new int[]{0};
final int[] outputs = new int[]{1};
this.inventory = new RebornInventory<>(3, "GrinderBlockEntity", 64, this);
this.crafter = new RecipeCrafter(ModRecipes.GRINDER, this, 2, 1, this.inventory, inputs, outputs);
}
@Override
public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) {
return new ScreenHandlerBuilder("grinder").player(player.getInventory()).inventory().hotbar().addInventory().blockEntity(this)
.slot(0, 55, 45).outputSlot(1, 101, 45).energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue()
.addInventory().create(this, syncID);
}
}

View file

@ -1,44 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blocks;
import net.minecraft.util.Identifier;
import techreborn.blockentity.GuiType;
import techreborn.blockentity.data.DataDrivenBEProvider;
/**
* @author modmuss50
*/
public class DataDrivenMachineBlock extends GenericMachineBlock {
private final DataDrivenBEProvider provider;
public DataDrivenMachineBlock(String ident) {
super(GuiType.DATA_DRIVEN, null);
provider = DataDrivenBEProvider.create(this, new Identifier(ident));
blockEntityClass = provider;
}
}

View file

@ -351,6 +351,12 @@ public class TechRebornConfig {
@Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy") @Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy")
public static int extractorMaxEnergy = 1_000; public static int extractorMaxEnergy = 1_000;
@Config(config = "machines", category = "grinder", key = "GrinderInput", comment = "Grinder Max Input (Energy per tick)")
public static int grinderMaxInput = 32;
@Config(config = "machines", category = "grinder", key = "GrinderMaxEnergy", comment = "Grinder Max Energy")
public static int grinderMaxEnergy = 1_000;
@Config(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Energy per tick)") @Config(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Energy per tick)")
public static int compressorMaxInput = 32; public static int compressorMaxInput = 32;

View file

@ -114,6 +114,7 @@ public class TRBlockEntities {
public static final BlockEntityType<FusionControlComputerBlockEntity> FUSION_CONTROL_COMPUTER = register(FusionControlComputerBlockEntity::new, "fusion_control_computer", TRContent.Machine.FUSION_CONTROL_COMPUTER); public static final BlockEntityType<FusionControlComputerBlockEntity> FUSION_CONTROL_COMPUTER = register(FusionControlComputerBlockEntity::new, "fusion_control_computer", TRContent.Machine.FUSION_CONTROL_COMPUTER);
public static final BlockEntityType<LightningRodBlockEntity> LIGHTNING_ROD = register(LightningRodBlockEntity::new, "lightning_rod", TRContent.Machine.LIGHTNING_ROD); public static final BlockEntityType<LightningRodBlockEntity> LIGHTNING_ROD = register(LightningRodBlockEntity::new, "lightning_rod", TRContent.Machine.LIGHTNING_ROD);
public static final BlockEntityType<IndustrialSawmillBlockEntity> INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL); public static final BlockEntityType<IndustrialSawmillBlockEntity> INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL);
public static final BlockEntityType<GrinderBlockEntity> GRINDER = register(GrinderBlockEntity::new, "grinder", TRContent.Machine.GRINDER);
public static final BlockEntityType<SolidFuelGeneratorBlockEntity> SOLID_FUEL_GENERATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR); public static final BlockEntityType<SolidFuelGeneratorBlockEntity> SOLID_FUEL_GENERATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR);
public static final BlockEntityType<ExtractorBlockEntity> EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR); public static final BlockEntityType<ExtractorBlockEntity> EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR);
public static final BlockEntityType<ResinBasinBlockEntity> RESIN_BASIN = register(ResinBasinBlockEntity::new, "resin_basin", TRContent.Machine.RESIN_BASIN); public static final BlockEntityType<ResinBasinBlockEntity> RESIN_BASIN = register(ResinBasinBlockEntity::new, "resin_basin", TRContent.Machine.RESIN_BASIN);

View file

@ -65,7 +65,6 @@ import techreborn.blockentity.machine.tier3.ChunkLoaderBlockEntity;
import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity; import techreborn.blockentity.machine.tier3.IndustrialCentrifugeBlockEntity;
import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity; import techreborn.blockentity.machine.tier3.MatterFabricatorBlockEntity;
import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity; import techreborn.blockentity.storage.energy.AdjustableSUBlockEntity;
import techreborn.blocks.DataDrivenMachineBlock;
import techreborn.blocks.GenericMachineBlock; import techreborn.blocks.GenericMachineBlock;
import techreborn.blocks.cable.CableBlock; import techreborn.blocks.cable.CableBlock;
import techreborn.blocks.generator.BlockFusionCoil; import techreborn.blocks.generator.BlockFusionCoil;
@ -670,7 +669,7 @@ public class TRContent {
EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)), EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)),
RESIN_BASIN(new ResinBasinBlock(ResinBasinBlockEntity::new)), RESIN_BASIN(new ResinBasinBlock(ResinBasinBlockEntity::new)),
FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)), FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)),
GRINDER(new DataDrivenMachineBlock("techreborn:grinder")), GRINDER(new GenericMachineBlock(GuiType.GRINDER, GrinderBlockEntity::new)),
ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)), ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)),
IMPLOSION_COMPRESSOR(new GenericMachineBlock(GuiType.IMPLOSION_COMPRESSOR, ImplosionCompressorBlockEntity::new)), IMPLOSION_COMPRESSOR(new GenericMachineBlock(GuiType.IMPLOSION_COMPRESSOR, ImplosionCompressorBlockEntity::new)),
INDUSTRIAL_BLAST_FURNACE(new GenericMachineBlock(GuiType.BLAST_FURNACE, IndustrialBlastFurnaceBlockEntity::new)), INDUSTRIAL_BLAST_FURNACE(new GenericMachineBlock(GuiType.BLAST_FURNACE, IndustrialBlastFurnaceBlockEntity::new)),

View file

@ -1,35 +0,0 @@
{
"name": "techreborn:grinder",
"energy": 1000,
"maxInput": 32,
"slots": [
{
"type": "input",
"x": 55,
"y": 45
},
{
"type": "output",
"x": 101,
"y": 45
},
{
"type": "energy",
"x": 7,
"y": 72
}
],
"gui": [
{
"type": "progress_bar",
"x": 76,
"y": 48,
"direction": "right"
},
{
"type": "energy_bar",
"x": 9,
"y": 19
}
]
}