Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
public String panelName = "Solar Panel";
public String storage;
public String production;
public String generating;
public String maxStorage;
protected boolean...
package com.heros.wlmod.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.inventory.Container;
import org.lwjgl.opengl.GL11;
import com.heros.wlmod.blocks.SolarPanelTileEntity;
import net.minecraft.client.resources.I18n;
public class SolarPanelGui extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("wlmod", "textures/gui/solar_panel.png");
private SolarPanelTileEntity tileEntity;
public SolarPanelGui(Container container, SolarPanelTileEntity tileEntity) {
super(container);
this.tileEntity = tileEntity;
this.xSize = 176;
this.ySize = 166;
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(texture);
int x = (width - xSize) / 2 + guiLeft;
int y = (height - ySize) / 2 + guiTop;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
int energyStored = tileEntity.getEnergyStored();
int energyBarHeight = (int)((double) energyStored / tileEntity.getMaxEnergyStored() * 50);
drawTexturedModalRect(x + 152, y + 30 + 50 - energyBarHeight, 176, 0, 16, energyBarHeight);
boolean isDaytime = tileEntity.isDaytime();
if (isDaytime) {
drawTexturedModalRect(x + 27, y + 44, 195, 15, 14, 14);
} else {
drawTexturedModalRect(x + 27, y + 44, 210, 15, 14, 14);
}
}
@Override
protected void drawGuiContainerForegroundLayer(final int par1, final int par2) {
final String formatPanelName = I18n.format(this.tileEntity.panelName, new Object[0]);
final int nmPos = (this.xSize - this.fontRendererObj.getStringWidth(formatPanelName)) / 2;
this.fontRendererObj.drawString(formatPanelName, nmPos, 7, 7718655);
final String storageString = I18n.format("gui.AdvancedSolarPanel.storage", new Object[0]) + ": ";
final String maxOutputString = I18n.format("gui.AdvancedSolarPanel.maxOutput", new Object[0]) + ": ";
final String generatingString = I18n.format("gui.AdvancedSolarPanel.generating", new Object[0]) + ": ";
final String energyPerTickString = I18n.format("gui.AdvancedSolarPanel.energyPerTick", new Object[0]);
this.fontRendererObj.drawString(storageString + this.tileEntity.storage + "/" + this.tileEntity.maxStorage, 50, 22, 13487565);
this.fontRendererObj.drawString(maxOutputString + this.tileEntity.production + (" " + energyPerTickString), 50, 32, 13487565);
this.fontRendererObj.drawString(generatingString + this.tileEntity.generating + (" " + energyPerTickString), 50, 42, 13487565);
}
}
package com.heros.wlmod.gui;
import com.heros.wlmod.container.SolarPanelContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import com.heros.wlmod.blocks.SolarPanelTileEntity;
public class GuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof SolarPanelTileEntity) {
return new SolarPanelContainer(player.inventory, (SolarPanelTileEntity) tileEntity);
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof SolarPanelTileEntity) {
return new SolarPanelGui(new SolarPanelContainer(player.inventory, (SolarPanelTileEntity) tileEntity), (SolarPanelTileEntity) tileEntity);
}
return null;
}
}
package com.heros.wlmod.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import com.heros.wlmod.blocks.SolarPanelTileEntity;
public class SolarPanelContainer extends Container {
private SolarPanelTileEntity tileEntity;
public SolarPanelContainer(InventoryPlayer playerInventory, SolarPanelTileEntity tileEntity) {
this.tileEntity = tileEntity;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileEntity.isUsableByPlayer(playerIn);
}
}
boolean isDaytime = tileEntity.isDaytime();
package com.heros.wlmod.blocks;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.List;
public class SolarPanelTileEntity extends TileEntity implements IEnergySource, IEnergyTile {
public int energyStored = 0;
public final int maxEnergyStored = 10000;
public boolean addedToEnergyNet = false;
public List<IEnergySink> energySinks = new ArrayList<>();
public String panelName = "Solar Panel";
public String storage;
public String production;
public String generating;
public String maxStorage;
@Override
public void updateEntity() {
if (!worldObj.isRemote) {
if (!addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
findEnergySinks();
}
if (hasAccessToSky()) {
int energyGenerated = worldObj.isDaytime() ? 1 : 512;
energyStored = Math.min(energyStored + energyGenerated, maxEnergyStored);
}
distributeEnergy();
}
}
private void findEnergySinks() {
energySinks.clear();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (direction != ForgeDirection.UP) {
TileEntity tile = worldObj.getTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
if (tile instanceof IEnergySink) {
energySinks.add((IEnergySink) tile);
}
}
}
}
private void distributeEnergy() {
for (IEnergySink sink : energySinks) {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (sink.acceptsEnergyFrom(this, direction)) {
double energyToTransfer = Math.min(energyStored, sink.getDemandedEnergy());
energyStored -= energyToTransfer - sink.injectEnergy(direction.getOpposite(), energyToTransfer, 1);
}
}
}
}
private boolean hasAccessToSky() {
for (int y = this.yCoord + 1; y < worldObj.getActualHeight(); y++) {
if (!worldObj.isAirBlock(this.xCoord, y, this.zCoord) && !isBlockTransparent(this.xCoord, y, this.zCoord)) {
return false;
}
}
return true;
}
private boolean isBlockTransparent(int x, int y, int z) {
return worldObj.getBlock(x, y, z).getMaterial() == net.minecraft.block.material.Material.glass;
}
public boolean isUsableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this &&
player.getDistanceSq(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5) <= 64;
}
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
return true;
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, 1024);
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public int getSourceTier() {
return 1;
}
@Override
public void onChunkUnload() {
if (addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnergyNet = false;
}
super.onChunkUnload();
}
@Override
public void invalidate() {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
super.invalidate();
}
@Override
public void validate() {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
super.validate();
}
public int getEnergyStored() {
return energyStored;
}
public int getMaxEnergyStored() {
return maxEnergyStored;
}
public boolean isDaytime() {
return worldObj.isDaytime();
}
public int gaugeEnergyScaled(int scale) {
return (int) ((double) energyStored / maxEnergyStored * scale);
}
}
package com.heros.wlmod.blocks;
import com.heros.wlmod.MyMod;
import com.heros.wlmod.blocks.SolarPanelTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class SolarPanelBlock extends Block {
private IIcon topIcon;
private IIcon sideIcon;
private IIcon bottomIcon;
public SolarPanelBlock() {
super(Material.iron);
this.setBlockName("customSolarPanel");
this.setHardness(3.0F);
this.setResistance(5.0F);
this.setCreativeTab(MyMod.myCreativeTab);
}
@Override
public void registerBlockIcons(IIconRegister iconRegister) {
this.topIcon = iconRegister.registerIcon("wlmod:solar_panel_top");
this.sideIcon = iconRegister.registerIcon("wlmod:solar_panel_side");
this.bottomIcon = iconRegister.registerIcon("wlmod:solar_panel_bottom");
}
@Override
public IIcon getIcon(int side, int meta) {
if (side == 0) {
return bottomIcon;
} else if (side == 1) {
return topIcon;
} else {
return sideIcon;
}
}
@Override
public TileEntity createTileEntity(World world, int meta) {
return new SolarPanelTileEntity();
}
@Override
public boolean hasTileEntity(int meta) {
return true;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (!world.isRemote) {
player.openGui(MyMod.instance, 0, world, x, y, z);
}
return true;
}
}
public String panelName = "Solar Panel";
public String storage;
public String production;
public String generating;
public String maxStorage;
protected boolean isDaytime = false;
protected int tickCounter = 0;
@Override
public void updateEntity() {
if (this.worldObj.isRemote) {
return;
}
if (++this.tickCounter % 20 == 0) {
this.isDaytime = this.worldObj.isDaytime();
if (!addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
findEnergySinks();
}
if (hasAccessToSky()) {
int energyGenerated = worldObj.isDaytime() ? 1 : 512;
energyStored = Math.min(energyStored + energyGenerated, maxEnergyStored);
}
distributeEnergy();
markDirty();
}
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
this.energyStored = compound.getInteger("energyStored");
this.isDaytime = compound.getBoolean("isDaytime");
}
@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
compound.setInteger("energyStored", this.energyStored);
compound.setBoolean("isDaytime", this.isDaytime);
}
Спасибо, заработалоСинхронизации с сервера на клиент нет. Одиночная игра тоже работает как сервер.
В контейнере (Container) надо переопределить методы detectAndSendChanges() и updateProgressBar(). Можешь посмотреть как это сделано в печке.
Рад помочь и удачи в обучение.Спасибо, заработало
Ну если на продакшене такое будет, поверь, тебя закидают тухлыми помидорами)забей на public String....
Просто я мутил с кодом с мода advspanels и их добавил туду чтоб проверить 1 штуку