This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on super buffer, tile should be done
- Loading branch information
Showing
2 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
125 changes: 124 additions & 1 deletion
125
common/src/main/java/muramasa/gregtech/tile/single/TileEntitySuperBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,151 @@ | ||
package muramasa.gregtech.tile.single; | ||
|
||
import muramasa.antimatter.capability.item.TrackedItemHandler; | ||
import muramasa.antimatter.capability.machine.MachineEnergyHandler; | ||
import muramasa.antimatter.capability.machine.MachineItemHandler; | ||
import muramasa.antimatter.data.AntimatterDefaultTools; | ||
import muramasa.antimatter.gui.ButtonBody; | ||
import muramasa.antimatter.gui.GuiInstance; | ||
import muramasa.antimatter.gui.IGuiElement; | ||
import muramasa.antimatter.gui.SlotType; | ||
import muramasa.antimatter.gui.event.GuiEvents; | ||
import muramasa.antimatter.gui.event.IGuiEvent; | ||
import muramasa.antimatter.machine.event.ContentEvent; | ||
import muramasa.antimatter.machine.types.Machine; | ||
import muramasa.antimatter.tile.TileEntityMachine; | ||
import muramasa.antimatter.tool.AntimatterToolType; | ||
import muramasa.antimatter.util.AntimatterPlatformUtils; | ||
import muramasa.antimatter.util.Utils; | ||
import muramasa.gregtech.data.SlotTypes; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.TextComponent; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import tesseract.TesseractCapUtils; | ||
import tesseract.api.item.ExtendedItemContainer; | ||
import tesseract.util.ItemHandlerUtils; | ||
|
||
import static muramasa.antimatter.machine.MachineFlag.ENERGY; | ||
|
||
public class TileEntitySuperBuffer extends TileEntityMachine<TileEntitySuperBuffer> { | ||
protected int stackLimit = 64; | ||
boolean emitEnergy = false; | ||
|
||
public TileEntitySuperBuffer(Machine<?> type, BlockPos pos, BlockState state) { | ||
super(type, pos, state); | ||
itemHandler.set(() -> new SuperBufferItemHandler(this)); | ||
if (type.has(ENERGY)) { | ||
energyHandler.set(() -> new MachineEnergyHandler<>(this, 0L, this.getMachineTier().getVoltage() * 66L, this.getMachineTier().getVoltage(), this.getMachineTier().getVoltage(), 1, 1){ | ||
@Override | ||
public boolean canOutput(Direction direction) { | ||
return super.canOutput(direction) && direction == tile.getFacing().getOpposite() && tile.emitEnergy; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public InteractionResult onInteractServer(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, @Nullable AntimatterToolType type) { | ||
ItemStack stack = player.getItemInHand(hand); | ||
if (stack.is(AntimatterDefaultTools.SCREWDRIVER.getTag())){ | ||
if (hit.getDirection() == getFacing().getOpposite()){ | ||
stackLimit++; | ||
if (stackLimit == 65) stackLimit = 1; | ||
player.sendMessage(new TextComponent("Item Output Limit: " +stackLimit), player.getUUID()); | ||
stack.hurt(1, world.random, (ServerPlayer) player); | ||
return InteractionResult.SUCCESS; | ||
} | ||
} | ||
return super.onInteractServer(state, world, pos, player, hand, hit, type); | ||
} | ||
|
||
@Override | ||
public void serverTick(Level level, BlockPos pos, BlockState state) { | ||
super.serverTick(level, pos, state); | ||
if (getCover(this.getFacing().getOpposite()).isEmpty()){ | ||
processItemOutput(); | ||
/*if (this.energyHandler.map(e -> e.getEnergy() > 0).orElse(false)){ | ||
if(processItemOutput()){ | ||
this.energyHandler.ifPresent(e -> e.extractEu(1, false)); | ||
} | ||
}*/ | ||
|
||
} | ||
} | ||
|
||
protected boolean processItemOutput() { | ||
Direction outputDir = this.getFacing().getOpposite(); | ||
BlockEntity adjTile = Utils.getTile(this.getLevel(), this.getBlockPos().relative(outputDir)); | ||
if (adjTile == null) return false; | ||
boolean[] booleans = new boolean[1]; | ||
booleans[0] = false; | ||
TesseractCapUtils.getItemHandler(adjTile, outputDir.getOpposite()).ifPresent(adjHandler -> { | ||
booleans[0] = this.itemHandler.map(h -> Utils.transferItems(h.getHandler(SlotType.STORAGE), adjHandler,true)).orElse(false); | ||
}); | ||
return booleans[0]; | ||
} | ||
|
||
@Override | ||
public void saveAdditional(CompoundTag tag) { | ||
super.saveAdditional(tag); | ||
tag.putInt("stackLimit", stackLimit); | ||
} | ||
|
||
@Override | ||
public void load(CompoundTag tag) { | ||
super.load(tag); | ||
stackLimit = tag.getInt("stackLimit"); | ||
} | ||
|
||
@Override | ||
public void onGuiEvent(IGuiEvent event, Player playerEntity) { | ||
if (event.getFactory() == GuiEvents.EXTRA_BUTTON) { | ||
int[] data = ((GuiEvents.GuiEvent)event).data; | ||
switch (data[0]) { | ||
case 0 -> { | ||
emitEnergy = !emitEnergy; | ||
playerEntity.sendMessage(new TextComponent((emitEnergy ? "Emit energy to output side" : "Don't emit energy")), playerEntity.getUUID()); | ||
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512); | ||
} | ||
case 1 -> { | ||
/*outputRedstone = !outputRedstone; | ||
playerEntity.sendMessage(new TextComponent((outputRedstone ? "Emit redstone if slots contain something" : "Don't emit redstone")), playerEntity.getUUID()); | ||
AntimatterPlatformUtils.markAndNotifyBlock(level, this.getBlockPos(), this.level.getChunkAt(this.getBlockPos()), this.getBlockState(), this.getBlockState(), 1, 512);*/ | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void addWidgets(GuiInstance instance, IGuiElement parent) { | ||
super.addWidgets(instance, parent); | ||
instance.addButton(8, 63, 16, 16, ButtonBody.NO_OVERLAY); | ||
} | ||
|
||
public static class SuperBufferItemHandler extends MachineItemHandler<TileEntitySuperBuffer> { | ||
|
||
public SuperBufferItemHandler(TileEntitySuperBuffer tile) { | ||
super(tile); | ||
this.inventories.put(SlotType.STORAGE, new TrackedItemHandler<>(tile, 256, true, true, (t, s) -> true, ContentEvent.ITEM_INPUT_CHANGED)); | ||
this.inventories.put(SlotType.STORAGE, new TrackedItemHandler<>(tile, 256, true, true, (t, s) -> true, ContentEvent.ITEM_INPUT_CHANGED){ | ||
@NotNull | ||
@Override | ||
public ItemStack extractItem(int slot, int amount, boolean simulate) { | ||
amount = Math.min(amount, tile.stackLimit); | ||
return super.extractItem(slot, amount, simulate); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Binary file added
BIN
+5.91 KB
common/src/main/resources/assets/gti/textures/gui/background/super_buffer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.