Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
started work on robot arm, made it not possible to put conveyors on f…
Browse files Browse the repository at this point in the history
…luid pipes and pumps on item pipes
  • Loading branch information
Trinsdar committed Sep 28, 2023
1 parent 90ac9c6 commit d953c8a
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean onTransfer(Object object, boolean inputSide, boolean simulate) {

@Override
public <T> boolean blocksCapability(Class<T> cap, Direction side) {
return side == null && cap != ExtendedItemContainer.class;
return cap != ExtendedItemContainer.class;
}

@Override
Expand All @@ -94,7 +94,7 @@ public void onUpdate() {
return;
BlockState state = handler.getTile().getLevel().getBlockState(handler.getTile().getBlockPos().relative(side));
//Drop into world.
if (state == Blocks.AIR.defaultBlockState() && exportMode.name.contains("output")) {
if (state == Blocks.AIR.defaultBlockState() && exportMode.isExport()) {
Level world = handler.getTile().getLevel();
BlockPos pos = handler.getTile().getBlockPos();
ItemStack stack = TesseractCapUtils.getItemHandler(handler.getTile(), side).map(Utils::extractAny).orElse(ItemStack.EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ResourceLocation getModel(String type, Direction dir) {

@Override
public <T> boolean blocksCapability(Class<T> cap, Direction side) {
return side == null && cap != FluidContainer.class;
return cap != FluidContainer.class;
}

@Override
Expand Down
106 changes: 106 additions & 0 deletions common/src/main/java/muramasa/gregtech/cover/CoverRobotArm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package muramasa.gregtech.cover;

import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.blockentity.pipe.BlockEntityPipe;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.gui.event.GuiEvents;
import muramasa.antimatter.gui.event.IGuiEvent;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.cover.base.CoverBasicTransport;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public class CoverRobotArm extends CoverBasicTransport {
int slot = 0;
public CoverRobotArm(ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
addGuiCallback(t -> {
t.addTextButton(70, 53, 36, 12, h -> ((CoverRobotArm)h).slot, i -> Utils.literal("Slot: ").append("" + i), 0, true);
});
}

@Override
protected String getRenderId() {
return "conveyor";
}

@Override
public ResourceLocation getModel(String type, Direction dir) {
if (type.equals("pipe")) return PIPE_COVER_MODEL;
return getBasicDepthModel();
}

@Override
public boolean onTransfer(Object object, boolean inputSide, boolean simulate) {
if (object instanceof ItemStack stack && !exportMode.isExport() && handler.getTile() instanceof BlockEntityMachine<?> machine && inputSide) {
if (machine.itemHandler.map(h -> h.getInputCount() > 0).orElse(false)){
machine.itemHandler.ifPresent(h -> {

});
}
}
return false;
}

@Override
public void onGuiEvent(IGuiEvent event, Player playerEntity) {
ImportExportMode previous = exportMode;
super.onGuiEvent(event, playerEntity);
if (event.getFactory() == GuiEvents.EXTRA_BUTTON){

GuiEvents.GuiEvent ev = (GuiEvents.GuiEvent) event;
if (ev.data[1] == 1){
if (previous.isExport() != exportMode.isExport()){
slot = 0;
if (handler.getTile() instanceof BlockEntityMachine<?> machine) machine.onBlockUpdate(machine.getBlockPos());
}
}
if (ev.data[1] == 2){
if (handler.getTile() instanceof BlockEntityMachine<?> machine){
machine.itemHandler.ifPresent(h -> {
if (exportMode.isExport()){
if (h.getOutputCount() > 0){
slot++;
if (slot >= h.getOutputCount()) slot = 0;
} else {
slot = 0;
}
}
if (!exportMode.isExport()){
if (h.getInputCount() > 0){
slot++;
if (slot >= h.getInputCount()) slot = 0;
} else if (h.getHandler(SlotType.STORAGE).getContainerSize() > 0){
slot++;
if (slot >= h.getHandler(SlotType.STORAGE).getContainerSize()) slot = 0;
}else {
slot = 0;
}
}
machine.onBlockUpdate(machine.getBlockPos());
});
}
}
}
}

@Override
public void deserialize(CompoundTag nbt) {
super.deserialize(nbt);
slot = nbt.getInt("slot");
}

@Override
public CompoundTag serialize() {
CompoundTag nbt = super.serialize();
nbt.putInt("slot", slot);
return nbt;
}
}
34 changes: 10 additions & 24 deletions common/src/main/java/muramasa/gregtech/cover/ImportExportMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,20 @@

import muramasa.antimatter.cover.ICoverMode;

public enum ImportExportMode implements ICoverMode {
EXPORT("Export",88, 24),
IMPORT("Import",34, 24),
EXPORT_IMPORT("Export Import",88, 42),
IMPORT_EXPORT("Import Export",34, 42);
public enum ImportExportMode {
EXPORT(true),
IMPORT(false),
EXPORT_IMPORT(true),
IMPORT_EXPORT(false);

int x, y;
String name;
boolean export;

ImportExportMode(String name, int x, int y){
this.name = name;
this.x = x;
this.y = y;
ImportExportMode(boolean export){
this.export = export;
}

@Override
public int getX() {
return x;
}

@Override
public int getY() {
return y;
}

@Override
public String getName() {
return name;
public boolean isExport() {
return export;
}

public ImportExportMode next(){
Expand Down
8 changes: 3 additions & 5 deletions common/src/main/java/muramasa/gregtech/data/GregTechData.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static void init(Side side) {
public static final CoverFactory COVER_PUMP = CoverFactory.builder(CoverPump::new).gui().item((a,b) ->
new ItemCover(a.getDomain(), a.getId(), b).tip(String.format("%d L/s (as Cover)", CoverPump.speeds.get(b))))
.addTextures(new Texture(GTIRef.ID, "block/cover/pump")).setTiers(Tier.getStandard()).build(GTIRef.ID, "pump");
public static final CoverFactory COVER_ROBOT_ARM = CoverFactory.builder(CoverRobotArm::new).gui().item((a,b) ->
new ItemCover(a.getDomain(), a.getId(), b).tip(String.format("1 Stack every %ds (as Cover)", CoverConveyor.speeds.get(b))))
.addTextures(new Texture(GTIRef.ID, "block/cover/conveyor")).setTiers(Tier.getStandard()).build(GTIRef.ID, "robot_arm");
public static final CoverFactory COVER_DRAIN = CoverFactory.builder(CoverDrain::new).item((a, b) ->
new ItemCover(GTIRef.ID, "drain").tip("Can be placed on machines/pipes as a cover")).addTextures(new Texture(GTIRef.ID, "block/cover/drain")).build(GTIRef.ID, "drain");
public static final CoverFactory COVER_AIR_VENT = CoverFactory.builder(CoverAirVent::new).item((a, b) ->
Expand Down Expand Up @@ -129,11 +132,6 @@ public static void init(Side side) {
public static ItemBasic<?> PistonHV = new ItemBasic<>(GTIRef.ID, "piston_hv");
public static ItemBasic<?> PistonEV = new ItemBasic<>(GTIRef.ID, "piston_ev");
public static ItemBasic<?> PistonIV = new ItemBasic<>(GTIRef.ID, "piston_iv");
public static ItemBasic<?> RobotArmLV = new ItemBasic<>(GTIRef.ID, "robot_arm_lv").tip("Insets into specific Slots (as Cover)");
public static ItemBasic<?> RobotArmMV = new ItemBasic<>(GTIRef.ID, "robot_arm_mv").tip("Insets into specific Slots (as Cover)");
public static ItemBasic<?> RobotArmHV = new ItemBasic<>(GTIRef.ID, "robot_arm_hv").tip("Insets into specific Slots (as Cover)");
public static ItemBasic<?> RobotArmEV = new ItemBasic<>(GTIRef.ID, "robot_arm_ev").tip("Insets into specific Slots (as Cover)");
public static ItemBasic<?> RobotArmIV = new ItemBasic<>(GTIRef.ID, "robot_arm_iv").tip("Insets into specific Slots (as Cover)");
public static ItemBasic<?> FieldGenLV = new ItemBasic<>(GTIRef.ID, "field_gen_lv");
public static ItemBasic<?> FieldGenMV = new ItemBasic<>(GTIRef.ID, "field_gen_mv");
public static ItemBasic<?> FieldGenHV = new ItemBasic<>(GTIRef.ID, "field_gen_hv");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void loadRecipes(Consumer<FinishedRecipe> output, AntimatterRecipe
if (motor == null) return;
Item piston = GregTech.get(ItemBasic.class, "piston_"+tier.getId());
if (piston == null) return;
Item arm = GregTech.get(ItemBasic.class, "robot_arm_"+tier.getId());
Item arm = GregTech.get(ItemCover.class, "robot_arm_"+tier.getId());
if (arm == null) return;
Item conveyor = GregTech.get(ItemCover.class, "conveyor_"+tier.getId());
if (conveyor == null) return;
Expand Down Expand Up @@ -751,7 +751,7 @@ private static void addMultiblockRecipes(Consumer<FinishedRecipe> output, Antima
add(NUCLEAR_REACTOR, EV, (m, item) -> provider.addItemRecipe(output, "machines", "has_wrench", provider.hasSafeItem(WRENCH.getTag()), item,
ImmutableMap.<Character, Object>builder()
.put('H', HULL_EV)
.put('A', RobotArmEV)
.put('A', COVER_ROBOT_ARM.getItem(EV))
.put('G', GEAR.get(NiobiumTitanium))
.put('P', PLATE.get(Iridium))
.put('T', PLATE_DENSE.get(Thorium)).build(), "GTG", "AHA", "PTP"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static void tieredItems(Consumer<FinishedRecipe> output, AntimatterRecip

Item motor = GregTech.get(ItemBasic.class, "motor_" + t.getId());
Item piston = GregTech.get(ItemBasic.class, "piston_" + t.getId());
Item robotArm = GregTech.get(ItemBasic.class, "robot_arm_" + t.getId());
Item robotArm = GregTech.get(ItemCover.class, "robot_arm_" + t.getId());
Item emitter = GregTech.get(ItemBasic.class, "emitter_" + t.getId());
Item sensor = GregTech.get(ItemBasic.class, "sensor_" + t.getId());
Item pump = GregTech.get(ItemCover.class, "pump_" + t.getId());
Expand Down

0 comments on commit d953c8a

Please sign in to comment.