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

Commit

Permalink
updated antimatter, pretty much finished oil drilling rig
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 5, 2023
1 parent 5753dd8 commit 6db4119
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
package muramasa.gregtech.tile.multi;

import com.mojang.blaze3d.vertex.PoseStack;
import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import muramasa.antimatter.capability.machine.MultiMachineEnergyHandler;
import muramasa.antimatter.gui.GuiInstance;
import muramasa.antimatter.gui.ICanSyncData;
import muramasa.antimatter.gui.IGuiElement;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.gui.widget.InfoRenderWidget;
import muramasa.antimatter.gui.widget.WidgetSupplier;
import muramasa.antimatter.integration.jeirei.renderer.IInfoRenderer;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.event.MachineEvent;
import muramasa.antimatter.machine.types.Machine;
import muramasa.antimatter.tile.multi.TileEntityMultiMachine;
import muramasa.antimatter.util.int3;
import muramasa.gregtech.data.GregTechData;
import muramasa.gregtech.worldgen.OilSpoutEntry;
import muramasa.gregtech.worldgen.OilSpoutSavedData;
import net.minecraft.client.gui.Font;
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
Expand All @@ -20,16 +34,23 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.FluidState;
import tesseract.FluidPlatformUtils;
import tesseract.TesseractGraphWrappers;

import javax.annotation.Nullable;

import static muramasa.antimatter.gui.ICanSyncData.SyncDirection.SERVER_TO_CLIENT;
import static muramasa.gregtech.data.GregTechData.MINING_PIPE;
import static muramasa.gregtech.data.GregTechData.MINING_PIPE_THIN;

public class TileEntityOilDrillingRig extends TileEntityMultiMachine<TileEntityOilDrillingRig> {
boolean foundBottom = false;
boolean stopped = false;
int euPerTick;
int cycle = 160;
int progress = 0;
BlockPos.MutableBlockPos miningPos;
OilSpoutEntry oilEntry = null;

public TileEntityOilDrillingRig(Machine<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
Expand All @@ -39,14 +60,16 @@ public TileEntityOilDrillingRig(Machine<?> type, BlockPos pos, BlockState state)
@Override
public void serverTick(Level level, BlockPos pos, BlockState state) {
super.serverTick(level, pos, state);
if (!validStructure) return;
if (!validStructure || stopped || !(level instanceof ServerLevel serverLevel)) return;
ItemStack stack = itemHandler.map(i -> i.getHandler(SlotType.STORAGE).getStackInSlot(0)).orElse(ItemStack.EMPTY);
if (stack.getItem() == GregTechData.MINING_PIPE_THIN.asItem() || foundBottom){
if ((stack.getItem() == GregTechData.MINING_PIPE_THIN.asItem() || foundBottom) && energyHandler.map(e -> e.getEnergy() >= euPerTick).orElse(false)){
if (!foundBottom){

if (getMachineState() != MachineState.ACTIVE) setMachineState(MachineState.ACTIVE);
if (getMachineState() == MachineState.IDLE) setMachineState(MachineState.ACTIVE);
energyHandler.ifPresent(e -> e.extractInternal(euPerTick, false));

if (level.getGameTime() % 40 != 0) return;
if (!stopped) miningPos.below();
miningPos.below();

BlockState block = level.getBlockState(miningPos);

Expand All @@ -60,6 +83,22 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
return;
}
stack.shrink(1);
} else {
if (oilEntry == null){
OilSpoutSavedData.getOrCreate(serverLevel).setDirty();
oilEntry = OilSpoutSavedData.getOrCreate(serverLevel).getFluidVeinWorldEntry(SectionPos.blockToSectionCoord(this.getBlockPos().getX()), SectionPos.blockToSectionCoord(this.getBlockPos().getZ()));
}
if (oilEntry.getFluid() == null) return;
energyHandler.ifPresent(e -> e.extractInternal(euPerTick, false));
if (++progress == cycle){
progress = 0;
FluidHolder fluidHolder = FluidPlatformUtils.createFluidStack(oilEntry.getFluid().fluid(), oilEntry.getCurrentYield() * TesseractGraphWrappers.dropletMultiplier);
if (fluidHandler.map(f -> f.fillOutput(fluidHolder, true) == oilEntry.getCurrentYield() * TesseractGraphWrappers.dropletMultiplier).orElse(false)){
fluidHandler.ifPresent(f -> f.fillOutput(fluidHolder, false));
onMachineEvent(MachineEvent.FLUIDS_OUTPUTTED);
oilEntry.decreaseLevel();
}
}
}
} else {
if (getMachineState() == MachineState.ACTIVE) setMachineState(MachineState.IDLE);
Expand Down Expand Up @@ -99,17 +138,78 @@ public boolean destroyBlock(Level level, BlockPos pos, boolean dropBlock, @Nulla
}
}

@Override
public void afterStructureFormed() {
super.afterStructureFormed();
this.energyHandler.ifPresent(e -> {
int tier = ((MultiMachineEnergyHandler<?>) e).getAccumulatedPower().getIntegerId();
this.euPerTick = 3 * (1 << (tier << 1));
this.cycle = (int) (160 * (tier == 0 ? 2 : Math.pow(0.5, tier - 1)));
});
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
tag.putBoolean("foundBottom", foundBottom);
tag.putLong("miningPos", miningPos.asLong());
tag.putInt("progress", progress);
}

@Override
public void load(CompoundTag tag) {
super.load(tag);
public void load(CompoundTag nbt) {
super.load(nbt);
this.foundBottom = nbt.getBoolean("foundBottom");
this.miningPos = BlockPos.of(nbt.getLong("miningPos")).mutable();
this.progress = nbt.getInt("progress");
}

@Override
public WidgetSupplier getInfoWidget() {
return OilInfoWidget.build().setPos(10, 10);
}

@Override
public int drawInfo(InfoRenderWidget.MultiRenderWidget instance, PoseStack stack, Font renderer, int left, int top) {
OilInfoWidget oilInfoWidget = (OilInfoWidget) instance;
renderer.draw(stack, this.getDisplayName().getString(), left, top, 16448255);
if (getMachineState() != MachineState.ACTIVE) {
renderer.draw(stack, "Inactive.", left, top + 8, 16448255);
return 16;
} else if (instance.drawActiveInfo()) {
if (oilInfoWidget.foundBottom){
renderer.draw(stack, "Progress: " + instance.currentProgress + "/" + instance.maxProgress, left, top + 8, 16448255);
return 16;
} else if (oilInfoWidget.stopped){
renderer.draw(stack, "Can't mine at: " + oilInfoWidget.currentPos.toString(), left, top + 8, 16448255);
return 16;
}
}
return 8;
}

public static class OilInfoWidget extends InfoRenderWidget.MultiRenderWidget {
BlockPos currentPos;
boolean stopped;
boolean foundBottom;


protected OilInfoWidget(GuiInstance gui, IGuiElement parent, IInfoRenderer<MultiRenderWidget> renderer) {
super(gui, parent, renderer);
}

@Override
public void init() {
TileEntityOilDrillingRig m = (TileEntityOilDrillingRig) gui.handler;
gui.syncLong(() -> m.miningPos.asLong(), l -> currentPos = BlockPos.of(l), SERVER_TO_CLIENT);
gui.syncBoolean(() -> m.stopped, s -> stopped = s, SERVER_TO_CLIENT);
gui.syncBoolean(() -> m.foundBottom, b -> foundBottom = b, SERVER_TO_CLIENT);
gui.syncInt(() -> m.progress, i -> currentProgress = i, SERVER_TO_CLIENT);
gui.syncInt(() -> m.cycle, i -> maxProgress = i, SERVER_TO_CLIENT);
}

public static WidgetSupplier build() {
return builder((a, b) -> new OilInfoWidget(a, b, (IInfoRenderer) a.handler));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ private Boolean drainFluid(BlockPos aCoords) {
}

// Consume Energy based on Fluid Amount absorbed.
energyHandler.ifPresent(e -> {
GTTransaction transaction = e.extract(GTTransaction.Mode.INTERNAL);
transaction.addData(getMachineTier().getVoltage() / 2, Utils.sink());
transaction.commit();
});
energyHandler.ifPresent(e -> e.extractInternal(getMachineTier().getVoltage() / 2, false));
// If there is a Fluid Block above this one, clearly the Y-Level is off due to a recent Blockchange! Scan again!
if (mPumpedFluids.contains(level.getFluidState(aCoords).getType())) return false;
// Somehow this Block is completely surrounded by pumpable Fluid, this should not be possible unless it is the literal Cornercase! Scan again!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 16],
"to": [16, 16, 16],
"from": [0, 0, 0],
"to": [16, 16, 0],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 0, 8]},
"faces": {
"south": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
"north": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 16],
"to": [16, 16, 16],
"from": [0, 0, 0],
"to": [16, 16, 0],
"rotation": {"angle": 0, "axis": "y", "origin": [8, 0, 8]},
"faces": {
"south": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 1}
"north": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 1}
}
}
]
Expand Down
Loading

0 comments on commit 6db4119

Please sign in to comment.