Finished the gui, and start work on adding support for the furnace.

This commit is contained in:
modmuss50 2017-04-12 18:04:10 +01:00
parent 7541ba4dbb
commit d9af8309b1
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
8 changed files with 167 additions and 27 deletions

View file

@ -41,10 +41,12 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import org.apache.commons.lang3.time.StopWatch;
import reborncore.api.recipe.RecipeHandler;
import reborncore.common.multiblock.MultiblockEventHandler;
import reborncore.common.multiblock.MultiblockServerTickHandler;
import reborncore.common.network.RegisterPacketEvent;
import reborncore.common.packets.AddDiscriminatorEvent;
import reborncore.common.util.LogHelper;
import reborncore.common.util.VersionChecker;
@ -64,6 +66,7 @@ import techreborn.init.*;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketAesu;
import techreborn.packets.PacketIdsu;
import techreborn.packets.PacketSyncSideConfig;
import techreborn.proxies.CommonProxy;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.utils.StackWIPHandler;
@ -230,4 +233,10 @@ public class Core {
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketIdsu.class);
}
@SubscribeEvent
public void LoadPackets(RegisterPacketEvent event){
event.registerPacket(PacketSyncSideConfig.class, Side.SERVER);
}
}

View file

@ -107,7 +107,7 @@ public class BuiltContainer extends Container {
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if(slotId > 0 && slotId < 1000){
if(dragType == 1 && slotId > 0 && slotId < 1000){
Slot slot = this.inventorySlots.get(slotId);
if(slot instanceof IRightClickHandler){
if(((IRightClickHandler) slot).handleRightClick(slot.getSlotIndex(), player, this)){

View file

@ -68,7 +68,7 @@ public class UpgradeSlot extends Slot implements IRightClickHandler {
ItemStack stack = upgradeable.getUpgradeInvetory().getStackInSlot(slotID);
if(!stack.isEmpty() && stack.getItem() instanceof IUpgrade){
//Called on both sides :)
((IUpgrade) stack.getItem()).handleRightClick(tileEntity, stack, container);
((IUpgrade) stack.getItem()).handleRightClick(tileEntity, stack, container, slotID);
}
}
}

View file

@ -96,7 +96,9 @@ public class GuiBase extends GuiContainer {
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
builder.drawDefaultBackground(this, guiLeft, guiTop, xSize, ySize);
if(drawPlayerSlots()){
builder.drawPlayerSlots(this, guiLeft + xSize / 2, guiTop + 93, true);
}
if(tryAddUpgrades() && tile instanceof IUpgradeable){
IUpgradeable upgradeable = (IUpgradeable) tile;
if(upgradeable.canBeUpgraded()){
@ -105,6 +107,10 @@ public class GuiBase extends GuiContainer {
}
}
public boolean drawPlayerSlots(){
return true;
}
public boolean tryAddUpgrades(){
return true;
}

View file

@ -1,17 +1,46 @@
package techreborn.client.gui.upgrades;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import reborncore.common.network.NetworkManager;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.gui.GuiBase;
import techreborn.packets.PacketSyncSideConfig;
import java.io.IOException;
/**
* Created by Mark on 12/04/2017.
*/
public class GuiSideConfig extends GuiBase {
public GuiSideConfig(EntityPlayer player, TileEntity tile, BuiltContainer container) {
TileEntity tileEntity;
int slotID;
public GuiSideConfig(EntityPlayer player, TileEntity tile, BuiltContainer container, int slotID) {
super(player, tile, container);
this.tileEntity = tile;
this.slotID = slotID;
}
@Override
public void initGui() {
super.initGui();
this.buttonList.clear();
int i = 0;
for(EnumFacing facing : EnumFacing.VALUES){
buttonList.add(new GuiButton(facing.getIndex(), guiLeft + 150, guiTop + i++ * 23 + 22, 20, 20, ""));
}
}
@Override
@ -26,7 +55,26 @@ public class GuiSideConfig extends GuiBase {
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
int offset = 10;
RenderHelper.enableStandardItemLighting();
RenderHelper.enableGUIStandardItemLighting();
for(EnumFacing facing : EnumFacing.VALUES){
BlockPos pos = tileEntity.getPos().offset(facing);
IBlockState state = tileEntity.getWorld().getBlockState(pos);
ItemStack stack = state.getBlock().getPickBlock(state, new RayTraceResult(new Vec3d(0, 0, 0), facing, pos), tileEntity.getWorld(), pos, Minecraft.getMinecraft().player);
if(stack != null && !stack.isEmpty() && stack.getItem() != null){
drawCentredString(stack.getDisplayName() + " - " + facing.getName(), offset += 22, 4210752, layer);
itemRender.renderItemIntoGUI(stack, 10, offset - 2);
} else {
drawCentredString(state.getBlock().getLocalizedName() + " - " + facing.getName(), offset += 22, 4210752, layer);
}
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
NetworkManager.sendToServer(new PacketSyncSideConfig(slotID, button.id, tileEntity.getPos()));
}
@Override
@ -38,4 +86,9 @@ public class GuiSideConfig extends GuiBase {
public boolean tryAddUpgrades() {
return false;
}
@Override
public boolean drawPlayerSlots() {
return false;
}
}

View file

@ -42,6 +42,7 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.tile.TileLegacyMachineBase;
import reborncore.common.util.InventoryHelper;
import reborncore.common.util.ItemNBTHelper;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
@ -96,6 +97,14 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
}
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
super.addInformation(stack, playerIn, tooltip, advanced);
if(stack.getItemDamage() == 4 || stack.getItemDamage() == 5){
tooltip.add("Facing: " + getFacing(stack).getName());
}
}
@Override
public void process(
@Nonnull
@ -104,14 +113,18 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
RecipeCrafter crafter,
@Nonnull
ItemStack stack) {
if(crafter != null){
if (stack.getItemDamage() == 0) {
if(crafter != null) {
crafter.addSpeedMulti(0.25);
crafter.addPowerMulti(0.5);
}
} else if(stack.getItemDamage() == 4){
EnumFacing dir = EnumFacing.NORTH;
EnumFacing dir = getFacing(stack);
TileEntity tileEntity = machineBase.getWorld().getTileEntity(machineBase.getPos().offset(dir));
if(tileEntity instanceof IInventory){
if(crafter != null){
for(Integer outSlot : crafter.outputSlots){
ItemStack outputStack = crafter.inventory.getStackInSlot(outSlot);
if(!outputStack.isEmpty()){
@ -123,17 +136,19 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
}
}
}
//TODO fix when crafter is null
}
} else if (stack.getItemDamage() == 5){
if(machineBase.getWorld().getTotalWorldTime() % 10 != 0){
return;
}
EnumFacing dir = EnumFacing.UP;
EnumFacing dir = getFacing(stack);
TileEntity tileEntity = machineBase.getWorld().getTileEntity(machineBase.getPos().offset(dir));
if(tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite())){
if(tileEntity != null && tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite())){
IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite());
for (int i = 0; i < itemHandler.getSlots(); i++) {
ItemStack stack1 = itemHandler.getStackInSlot(i);
if(crafter.isStackValidInput(stack1)){
if(crafter == null || crafter.isStackValidInput(stack1)){
ItemStack extractedStack = itemHandler.extractItem(i, 1, true);
int amount = InventoryHelper.testInventoryInsertion(machineBase, extractedStack, null);
if(amount > 0){
@ -144,7 +159,7 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
}
}
}
}
}
if(machineBase instanceof TilePowerAcceptor){
if (stack.getItemDamage() == 2) {
@ -155,17 +170,20 @@ public class ItemUpgrades extends ItemTRNoDestroy implements IUpgrade {
}
@Override
public void handleRightClick(TileEntity tile, ItemStack stack, BuiltContainer container) {
public void handleRightClick(TileEntity tile, ItemStack stack, BuiltContainer container, int slotID) {
if(tile.getWorld().isRemote){
if(stack.getItemDamage() == 4){
Minecraft.getMinecraft().displayGuiScreen(new GuiSideConfig(Minecraft.getMinecraft().player, tile, getContainer(Minecraft.getMinecraft().player)));
} else if(stack.getItemDamage() == 5){
Minecraft.getMinecraft().displayGuiScreen(new GuiSideConfig(Minecraft.getMinecraft().player, tile, getContainer(Minecraft.getMinecraft().player)));
if(stack.getItemDamage() == 4 || stack.getItemDamage() == 5){
//TODO use the full gui handler
Minecraft.getMinecraft().displayGuiScreen(new GuiSideConfig(Minecraft.getMinecraft().player, tile, getContainer(Minecraft.getMinecraft().player), slotID));
}
}
}
public BuiltContainer getContainer(EntityPlayer player){
return new ContainerBuilder("sides").player(player.inventory).inventory().hotbar().addInventory().create();
return new ContainerBuilder("sides").create();
}
public EnumFacing getFacing(ItemStack stack){
return EnumFacing.VALUES[ItemNBTHelper.getInt(stack, "side", 0)];
}
}

View file

@ -0,0 +1,54 @@
package techreborn.packets;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import reborncore.api.tile.IUpgradeable;
import reborncore.common.network.ExtendedPacketBuffer;
import reborncore.common.network.INetworkPacket;
import reborncore.common.util.ItemNBTHelper;
import java.io.IOException;
/**
* Created by Mark on 12/04/2017.
*/
public class PacketSyncSideConfig implements INetworkPacket<PacketSyncSideConfig> {
int slotID;
int side;
BlockPos pos;
public PacketSyncSideConfig(int slotID, int side, BlockPos pos) {
this.slotID = slotID;
this.side = side;
this.pos = pos;
}
public PacketSyncSideConfig() {
}
@Override
public void writeData(ExtendedPacketBuffer buffer) throws IOException {
buffer.writeInt(slotID);
buffer.writeInt(side);
buffer.writeBlockPos(pos);
}
@Override
public void readData(ExtendedPacketBuffer buffer) throws IOException {
slotID = buffer.readInt();
side = buffer.readInt();
pos = buffer.readBlockPos();
}
@Override
public void processData(PacketSyncSideConfig message, MessageContext context) {
TileEntity tileEntity = context.getServerHandler().playerEntity.world.getTileEntity(message.pos);
if(tileEntity instanceof IUpgradeable){
ItemStack stack = ((IUpgradeable) tileEntity).getUpgradeInvetory().getStackInSlot(message.slotID);
ItemNBTHelper.setInt(stack, "side", message.side);
}
}
}

View file

@ -31,6 +31,7 @@ import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
@ -63,9 +64,8 @@ public class TileElectricFurnace extends TilePowerAcceptor
@Override
public void update() {
if (!this.world.isRemote) {
super.update();
if (!this.world.isRemote) {
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (this.isBurning() && this.canSmelt()) {