Skip to content

Commit

Permalink
Implement creative computation provider
Browse files Browse the repository at this point in the history
Bump ver
  • Loading branch information
Zorbatron committed Jul 29, 2024
1 parent d34e27d commit c080f69
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ modGroup = com.zorbatron.zbgt

# Version of your mod.
# This field can be left empty if you want your mod's version to be determined by the latest git tag instead.
modVersion = 0.5.0
modVersion = 0.6.0

# Whether to use the old jar naming structure (modid-mcversion-version) instead of the new version (modid-version)
includeMCVersionJar = false
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/zorbatron/zbgt/common/MetaTileEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import static com.zorbatron.zbgt.ZBUtility.zbgtId;
import static gregtech.common.metatileentities.MetaTileEntities.registerMetaTileEntity;

import com.zorbatron.zbgt.common.metatileentities.multi.multiblockpart.MetaTileEntityCreativeEnergyHatch;
import com.zorbatron.zbgt.common.metatileentities.multi.multiblockpart.MetaTileEntityCreativeReservoirHatch;
import com.zorbatron.zbgt.common.metatileentities.multi.multiblockpart.*;
import com.zorbatron.zbgt.common.metatileentities.storage.*;

public class MetaTileEntities {

public static MetaTileEntityCreativeEnergyHatch CREATIVE_ENERGY_SOURCE;
public static MetaTileEntityCreativeEnergyHatch CREATIVE_ENERGY_SINK;
public static MetaTileEntityCreativeReservoirHatch CREATIVE_RESERVOIR_HATCH;
public static MetaTileEntityCreativeComputationProvider CREATIVE_COMPUTATION_PROVIDER;

public static int id = 18000;

Expand All @@ -21,5 +22,7 @@ public static void init() {
new MetaTileEntityCreativeEnergyHatch(zbgtId("creative_energy_sink"), true)); // 18001
CREATIVE_RESERVOIR_HATCH = registerMetaTileEntity(++id,
new MetaTileEntityCreativeReservoirHatch(zbgtId("creative_reservoir_hatch"))); // 18002
CREATIVE_COMPUTATION_PROVIDER = registerMetaTileEntity(++id,
new MetaTileEntityCreativeComputationProvider(zbgtId("creative_computation_provider"))); // 18003
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.zorbatron.zbgt.common.metatileentities.storage;

import static gregtech.api.capability.GregtechDataCodes.UPDATE_ACTIVE;
import static gregtech.api.capability.GregtechDataCodes.UPDATE_IO_SPEED;

import java.util.Collection;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;

import org.jetbrains.annotations.NotNull;

import codechicken.lib.render.CCRenderState;
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechDataCodes;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IControllable;
import gregtech.api.capability.IOpticalComputationProvider;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.widgets.*;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.client.renderer.texture.Textures;

public class MetaTileEntityCreativeComputationProvider extends MetaTileEntity
implements IOpticalComputationProvider, IControllable {

private boolean isWorkingEnabled = true;
private int maxCWUt = 0;

private int lastRequestedCWUt;
private int requestedCWUPerSec;

public MetaTileEntityCreativeComputationProvider(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntityCreativeComputationProvider(metaTileEntityId);
}

@Override
protected ModularUI createUI(EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 170, 95);
builder.label(7, 7, getMetaFullName());

builder.widget(new LabelWidget(7, 25, "zbgt.machine.creative_computation_provider.cwut"));
builder.widget(new ImageWidget(7, 34, 126, 20, GuiTextures.DISPLAY));
builder.widget(new TextFieldWidget2(9, 40, 122, 16, () -> String.valueOf(this.maxCWUt),
value -> {
maxCWUt = Integer.parseInt(value);
markDirty();
}).setNumbersOnly(0, Integer.MAX_VALUE).setMaxLength(11));

builder.widget(new ImageCycleButtonWidget(140, 35, 18, 18, GuiTextures.BUTTON_POWER, this::isWorkingEnabled,
this::setWorkingEnabled));

builder.widget(new LabelWidget(7, 62, "zbgt.machine.creative_computation_provider.average"));
builder.widget(new DynamicLabelWidget(7, 74, () -> String.valueOf(this.lastRequestedCWUt)));

return builder.build(getHolder(), entityPlayer);
}

@Override
public void update() {
super.update();

if (getWorld().isRemote) return;
if (getOffsetTimer() % 20 == 0) {
this.lastRequestedCWUt = requestedCWUPerSec / 20;
this.requestedCWUPerSec = 0;
this.writeCustomData(UPDATE_IO_SPEED, packetBuffer -> packetBuffer.writeInt(lastRequestedCWUt));
}
}

@Override
public int requestCWUt(int CWUt, boolean simulate, @NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
int requestedCWUt = isWorkingEnabled ? Math.min(CWUt, maxCWUt) : 0;
if (!simulate) {
this.requestedCWUPerSec += requestedCWUt;
}
return requestedCWUt;
}

@Override
public int getMaxCWUt(@NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
return isWorkingEnabled ? maxCWUt : 0;
}

@Override
public boolean canBridge(@NotNull Collection<IOpticalComputationProvider> seen) {
seen.add(this);
return true;
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
if (side == getFrontFacing() && capability == GregtechTileCapabilities.CABABILITY_COMPUTATION_PROVIDER) {
return GregtechTileCapabilities.CABABILITY_COMPUTATION_PROVIDER.cast(this);
}
return super.getCapability(capability, side);
}

@Override
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
super.renderMetaTileEntity(renderState, translation, pipeline);
Textures.VOLTAGE_CASINGS[GTValues.MAX].render(renderState, translation, pipeline);
Textures.OPTICAL_DATA_ACCESS_HATCH.renderSided(getFrontFacing(), renderState, translation, pipeline);
}

@Override
public boolean isWorkingEnabled() {
return this.isWorkingEnabled;
}

@Override
public void setWorkingEnabled(boolean isWorkingAllowed) {
this.isWorkingEnabled = isWorkingAllowed;
if (!getWorld().isRemote) {
writeCustomData(GregtechDataCodes.UPDATE_ACTIVE, buf -> buf.writeBoolean(isWorkingAllowed));
}
}

@Override
public void receiveCustomData(int dataId, @NotNull PacketBuffer buf) {
super.receiveCustomData(dataId, buf);
if (dataId == UPDATE_ACTIVE) {
this.isWorkingEnabled = buf.readBoolean();
} else if (dataId == UPDATE_IO_SPEED) {
this.lastRequestedCWUt = buf.readInt();
}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
data.setInteger("MaxCWUt", this.maxCWUt);
return super.writeToNBT(data);
}

@Override
public void readFromNBT(NBTTagCompound data) {
this.maxCWUt = data.getInteger("MaxCWUt");
super.readFromNBT(data);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/assets/zbgt/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ zbgt.machine.creative_energy_sink.name=Creative Energy Sink
zbgt.machine.creative_energy_sink.tooltip=Infinite Energy Sink for Multiblocks

zbgt.machine.creative_energy.apply_button=Apply Settings

zbgt.machine.creative_energy.warning.1=The connected multiblock needs to be reformed to accept the changes!
zbgt.machine.creative_energy.warning.2=PSSs and ATs will get 16x the power configured!

zbgt.machine.creative_reservoir_hatch.name=Creative Reservoir Hatch
zbgt.machine.creative_reservoir_hatch.tooltip=Fluid Input for Multiblocks

zbgt.machine.creative_computation_provider.name=Creative Computation Provider
zbgt.machine.creative_computation_provider.tooltip=Infinite source of computation for CWU consumers
zbgt.machine.creative_computation_provider.average=Average Requested CWU/t
zbgt.machine.creative_computation_provider.cwut=Maximum Requestable CWU/t


metaitem.cover.dual_cover.lv.name=LV Dual Cover
metaitem.cover.dual_cover.mv.name=MV Dual Cover
Expand Down

0 comments on commit c080f69

Please sign in to comment.