-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c4a9cf
commit d1bceee
Showing
5 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
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
152 changes: 152 additions & 0 deletions
152
src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityDiode.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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package gregtech.common.metatileentities.electric; | ||
|
||
import codechicken.lib.raytracer.CuboidRayTraceResult; | ||
import codechicken.lib.render.CCRenderState; | ||
import codechicken.lib.render.pipeline.IVertexOperation; | ||
import codechicken.lib.vec.Matrix4; | ||
import gregtech.api.GTValues; | ||
import gregtech.api.capability.GregtechCapabilities; | ||
import gregtech.api.capability.impl.EnergyContainerHandler; | ||
import gregtech.api.capability.tool.ISoftHammerItem; | ||
import gregtech.api.gui.ModularUI; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import gregtech.api.metatileentity.MetaTileEntityHolder; | ||
import gregtech.api.metatileentity.TieredMetaTileEntity; | ||
import gregtech.api.render.Textures; | ||
import gregtech.api.util.PipelineUtil; | ||
import gregtech.common.tools.DamageValues; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.network.PacketBuffer; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.text.TextComponentTranslation; | ||
import net.minecraft.world.World; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class MetaTileEntityDiode extends TieredMetaTileEntity { | ||
|
||
private static final String AMP_NBT_KEY = "amp_mode"; | ||
private int amps; | ||
|
||
public MetaTileEntityDiode(ResourceLocation metaTileEntityId, int tier) { | ||
super(metaTileEntityId, tier); | ||
amps = 1; | ||
reinitializeEnergyContainer(); | ||
} | ||
|
||
@Override | ||
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) { | ||
return new MetaTileEntityDiode(metaTileEntityId, getTier()); | ||
} | ||
|
||
@Override | ||
public NBTTagCompound writeToNBT(NBTTagCompound data) { | ||
super.writeToNBT(data); | ||
data.setInteger(AMP_NBT_KEY, amps); | ||
return data; | ||
} | ||
|
||
@Override | ||
public void readFromNBT(NBTTagCompound data) { | ||
super.readFromNBT(data); | ||
this.amps = data.getInteger(AMP_NBT_KEY); | ||
reinitializeEnergyContainer(); | ||
} | ||
|
||
@Override | ||
public void writeInitialSyncData(PacketBuffer buf) { | ||
super.writeInitialSyncData(buf); | ||
buf.writeInt(amps); | ||
} | ||
|
||
@Override | ||
public void receiveInitialSyncData(PacketBuffer buf) { | ||
super.receiveInitialSyncData(buf); | ||
this.amps = buf.readInt(); | ||
} | ||
|
||
@Override | ||
public void receiveCustomData(int dataId, PacketBuffer buf) { | ||
super.receiveCustomData(dataId, buf); | ||
if (dataId == 101) { | ||
this.amps = buf.readInt(); | ||
} | ||
} | ||
|
||
private void setAmpMode() { | ||
amps = amps == 16 ? 1 : amps << 1; | ||
if (!getWorld().isRemote) { | ||
reinitializeEnergyContainer(); | ||
writeCustomData(101, b -> b.writeInt(amps)); | ||
getHolder().notifyBlockUpdate(); | ||
markDirty(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void reinitializeEnergyContainer() { | ||
long tierVoltage = GTValues.V[getTier()]; | ||
this.energyContainer = new EnergyContainerHandler(this, tierVoltage * 8, tierVoltage, amps, tierVoltage, amps); | ||
((EnergyContainerHandler) this.energyContainer).setSideInputCondition(s -> s != getFrontFacing()); | ||
((EnergyContainerHandler) this.energyContainer).setSideOutputCondition(s -> s == getFrontFacing()); | ||
} | ||
|
||
@Override | ||
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) { | ||
super.renderMetaTileEntity(renderState, translation, pipeline); | ||
Textures.ENERGY_IN_MULTI.renderSided(getFrontFacing(), renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()])); | ||
Arrays.stream(EnumFacing.values()).filter(f -> f != frontFacing).forEach(f -> | ||
Textures.ENERGY_OUT.renderSided(f, renderState, translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()]))); | ||
} | ||
|
||
@Override | ||
public boolean isValidFrontFacing(EnumFacing facing) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) { | ||
ItemStack itemStack = playerIn.getHeldItem(hand); | ||
if(!itemStack.isEmpty() && itemStack.hasCapability(GregtechCapabilities.CAPABILITY_MALLET, null)) { | ||
ISoftHammerItem softHammerItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_MALLET, null); | ||
|
||
if (getWorld().isRemote) { | ||
scheduleRenderUpdate(); | ||
return true; | ||
} | ||
if(!softHammerItem.damageItem(DamageValues.DAMAGE_FOR_SOFT_HAMMER, false)) { | ||
return false; | ||
} | ||
|
||
setAmpMode(); | ||
playerIn.sendMessage(new TextComponentTranslation("gregtech.machine.diode.message", amps)); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean openGUIOnRightClick() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected ModularUI createUI(EntityPlayer entityPlayer) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) { | ||
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_general")); | ||
tooltip.add(I18n.format("gregtech.machine.diode.tooltip_tool_usage")); | ||
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", | ||
energyContainer.getInputVoltage(), GTValues.VN[getTier()])); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/gregtech/integration/theoneprobe/provider/DiodeInfoProvider.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package gregtech.integration.theoneprobe.provider; | ||
|
||
import gregtech.api.capability.IEnergyContainer; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import gregtech.api.metatileentity.MetaTileEntityHolder; | ||
import gregtech.common.metatileentities.electric.MetaTileEntityDiode; | ||
import mcjty.theoneprobe.api.ElementAlignment; | ||
import mcjty.theoneprobe.api.IProbeInfo; | ||
import mcjty.theoneprobe.api.TextStyleClass; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumFacing; | ||
|
||
public class DiodeInfoProvider extends ElectricContainerInfoProvider { | ||
|
||
@Override | ||
public String getID() { | ||
return "gregtech:diode_info_provider"; | ||
} | ||
|
||
@Override | ||
protected void addProbeInfo(IEnergyContainer capability, IProbeInfo probeInfo, TileEntity tileEntity, EnumFacing sideHit) { | ||
if (tileEntity instanceof MetaTileEntityHolder) { | ||
MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity(); | ||
if (metaTileEntity instanceof MetaTileEntityDiode) { | ||
long inputAmperage = capability.getInputAmperage(); | ||
long outputAmperage = capability.getOutputAmperage(); | ||
IProbeInfo horizontalPane = probeInfo.vertical(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)); | ||
String transformInfo; | ||
if (capability.inputsEnergy(sideHit)) { | ||
transformInfo = "{*gregtech.top.transform_input*} " + inputAmperage + "A"; | ||
horizontalPane.text(TextStyleClass.INFO + transformInfo); | ||
} else if (capability.outputsEnergy(sideHit)) { | ||
transformInfo = "{*gregtech.top.transform_output*} " + outputAmperage + "A"; | ||
horizontalPane.text(TextStyleClass.INFO + transformInfo); | ||
} | ||
} | ||
} | ||
} | ||
} |
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