mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 01:32:55 +00:00
Dev into Experimental
This commit is contained in:
commit
bfb6e968ee
28 files changed
+2181
-99
No files matched your search
@@ -45,6 +45,7 @@ import noppes.npcs.client.gui.player.companion.GuiNpcCompanionTalents;
|
||||
import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeItem;
|
||||
import noppes.npcs.client.gui.GuiNpcRemoteEditor;
|
||||
import noppes.npcs.client.gui.roles.*;
|
||||
import noppes.npcs.client.gui.script.GuiScriptBlock;
|
||||
import noppes.npcs.client.gui.script.GuiScriptGlobal;
|
||||
import noppes.npcs.client.gui.script.GuiScriptItem;
|
||||
import noppes.npcs.client.model.*;
|
||||
@@ -124,6 +125,7 @@ public class ClientProxy extends CommonProxy {
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileBeam.class, new BlockBeamRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileBook.class, new BlockBookRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TilePedestal.class, new BlockPedestalRenderer());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileScripted.class, new BlockScriptedRenderer());
|
||||
RenderingRegistry.registerBlockHandler(new BlockBloodRenderer());
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
@@ -376,6 +378,9 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.CustomGui)
|
||||
return new GuiCustom((ContainerCustomGui)container);
|
||||
|
||||
else if (gui == EnumGuiType.ScriptBlock)
|
||||
return new GuiScriptBlock(x,y,z);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -1,20 +1,27 @@
|
||||
package noppes.npcs.client;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import noppes.npcs.CustomItems;
|
||||
|
||||
public class QuestAchievement extends Achievement{
|
||||
public class MessageAchievement extends Achievement{
|
||||
|
||||
private String description;
|
||||
private String message;
|
||||
public QuestAchievement(String message, String description) {
|
||||
super("",message, 0, 0, CustomItems.letter==null?Items.paper:CustomItems.letter, null);
|
||||
|
||||
public MessageAchievement(Item item, String message, String description) {
|
||||
super("",message, 0, 0, item, null);
|
||||
this.description = description;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public MessageAchievement(String message, String description) {
|
||||
this(CustomItems.letter==null ? Items.paper : CustomItems.letter, message, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatComponent func_150951_e()
|
||||
{
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.achievement.GuiAchievement;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -76,10 +77,10 @@ public class PacketHandlerClient extends PacketHandlerServer{
|
||||
|
||||
player.addChatMessage(new ChatComponentTranslation(message));
|
||||
}
|
||||
else if(type == EnumPacketClient.MESSAGE){
|
||||
else if(type == EnumPacketClient.MESSAGE || type == EnumPacketClient.PARTY_MESSAGE){
|
||||
String description = StatCollector.translateToLocal(Server.readString(buffer));
|
||||
String message = Server.readString(buffer);
|
||||
Achievement ach = new QuestAchievement(message, description);
|
||||
Achievement ach = type == EnumPacketClient.MESSAGE ? new MessageAchievement(message, description) : new MessageAchievement(CustomItems.bag == null ? Items.paper : CustomItems.bag, message, description);
|
||||
Minecraft.getMinecraft().guiAchievement.func_146256_a(ach);
|
||||
ObfuscationReflectionHelper.setPrivateValue(GuiAchievement.class, Minecraft.getMinecraft().guiAchievement, ach.getDescription(), 4);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package noppes.npcs.client.gui.player.inventory;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.Client;
|
||||
@@ -17,9 +20,11 @@ import tconstruct.client.tabs.InventoryTabCustomNpc;
|
||||
import tconstruct.client.tabs.TabRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData {
|
||||
public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData, GuiYesNoCallback {
|
||||
private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png");
|
||||
private final EntityPlayer player;
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
@@ -27,6 +32,14 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
private boolean receivedData;
|
||||
private long renderTicks;
|
||||
|
||||
private String selectedPlayer;
|
||||
private String selectedInvite;
|
||||
|
||||
private boolean partyChanged = false;
|
||||
private boolean isLeader;
|
||||
|
||||
private final HashMap<String, String> invites = new HashMap<>();
|
||||
|
||||
public GuiParty(EntityPlayer player) {
|
||||
super();
|
||||
this.player = player;
|
||||
@@ -39,6 +52,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
this.selectedInvite = this.selectedPlayer = null;
|
||||
Party party = ClientCacheHandler.party;
|
||||
TabRegistry.addTabsToList(buttonList);
|
||||
TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabCustomNpc.class);
|
||||
@@ -48,13 +62,13 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
//
|
||||
//create party button
|
||||
//
|
||||
GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "Create Party");
|
||||
GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "party.createParty");
|
||||
createPartyButton.width = 100;
|
||||
this.addButton(createPartyButton);
|
||||
|
||||
this.addLabel(new GuiNpcLabel(201, "You're not in a party!", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30));
|
||||
this.addLabel(new GuiNpcLabel(202, "Either wait for an invite", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20));
|
||||
this.addLabel(new GuiNpcLabel(203, "or create one.", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10));
|
||||
this.addLabel(new GuiNpcLabel(201, "party.partyInfo1", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30));
|
||||
this.addLabel(new GuiNpcLabel(202, "party.partyInfo2", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20));
|
||||
this.addLabel(new GuiNpcLabel(203, "party.partyInfo3", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10));
|
||||
|
||||
//party invites list
|
||||
//
|
||||
@@ -62,13 +76,14 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
inviteScroll.setSize(150, 160);
|
||||
inviteScroll.guiLeft = guiLeft + 5;
|
||||
inviteScroll.guiTop = guiTop + 5;
|
||||
inviteScroll.setList(new ArrayList<>(this.invites.keySet()));
|
||||
this.addScroll(inviteScroll);
|
||||
|
||||
GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "Accept");
|
||||
GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "party.accept");
|
||||
acceptButton.width = 60;
|
||||
this.addButton(acceptButton);
|
||||
|
||||
GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "Ignore");
|
||||
GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "party.ignore");
|
||||
ignoreButton.width = 60;
|
||||
this.addButton(ignoreButton);
|
||||
} else {
|
||||
@@ -79,58 +94,146 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
playerScroll.setSize(150, 160);
|
||||
playerScroll.guiLeft = guiLeft + 5;
|
||||
playerScroll.guiTop = guiTop + 5;
|
||||
playerScroll.setList(new ArrayList<>(party.getPlayerNames()));
|
||||
|
||||
ArrayList<String> arrayList = new ArrayList<>();
|
||||
Collection<String> playerNames = party.getPlayerNames();
|
||||
for (String s : playerNames) {
|
||||
if (party.getPartyLeaderName().equals(s)) {
|
||||
arrayList.add(s + " §e[" + StatCollector.translateToLocal("party.leader").toUpperCase() + "]");
|
||||
} else {
|
||||
arrayList.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
playerScroll.setList(arrayList);
|
||||
this.addScroll(playerScroll);
|
||||
|
||||
//set leader button
|
||||
//
|
||||
GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "Make Leader");
|
||||
leaderButton.width = 70;
|
||||
this.addButton(leaderButton);
|
||||
if (this.isLeader) {
|
||||
//set leader button
|
||||
//
|
||||
GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "party.makeLeader");
|
||||
leaderButton.width = 70;
|
||||
this.addButton(leaderButton);
|
||||
|
||||
//kick player button
|
||||
//
|
||||
GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "Kick");
|
||||
kickButton.width = 70;
|
||||
this.addButton(kickButton);
|
||||
//kick player button
|
||||
//
|
||||
GuiNpcButton kickButton = new GuiNpcButton(310, guiLeft + 85, guiTop + ySize - 12, "party.kick");
|
||||
kickButton.width = 70;
|
||||
this.addButton(kickButton);
|
||||
|
||||
//toggle friendly fire
|
||||
//
|
||||
GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"On", "Off"}, 0); //party.friendlyFire() ? 0 : 1
|
||||
friendlyFireButton.width = 40;
|
||||
this.addButton(friendlyFireButton);
|
||||
//toggle friendly fire
|
||||
//
|
||||
GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize / 2 + 95, guiTop + ySize / 2, new String[]{"gui.on", "gui.off"}, party.friendlyFire() ? 0 : 1);
|
||||
friendlyFireButton.width = 40;
|
||||
this.addButton(friendlyFireButton);
|
||||
|
||||
GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, "Friendly Fire:", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5);
|
||||
this.addLabel(friendlyFireLabel);
|
||||
GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, StatCollector.translateToLocal("party.friendlyFire") + ":", guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 5);
|
||||
this.addLabel(friendlyFireLabel);
|
||||
|
||||
//send invite button (opens subgui)
|
||||
//
|
||||
GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, "");
|
||||
this.addTextField(playerTextField);
|
||||
//send invite button (opens subgui)
|
||||
//
|
||||
GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize / 2 + 20, guiTop + ySize / 2 + 40, 100, 20, "");
|
||||
this.addTextField(playerTextField);
|
||||
|
||||
GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "Invite");
|
||||
inviteButton.width = 50;
|
||||
this.addButton(inviteButton);
|
||||
GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize / 2 + 125, guiTop + ySize / 2 + 40, "party.invite");
|
||||
inviteButton.width = 50;
|
||||
this.addButton(inviteButton);
|
||||
|
||||
//disband party
|
||||
//
|
||||
GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "Disband Party");
|
||||
disbandButton.width = 100;
|
||||
this.addButton(disbandButton);
|
||||
//disband party
|
||||
//
|
||||
GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.disbandParty");
|
||||
disbandButton.width = 100;
|
||||
this.addButton(disbandButton);
|
||||
} else {
|
||||
//leave party
|
||||
//
|
||||
GuiNpcButton leaveButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "party.leaveParty");
|
||||
leaveButton.width = 100;
|
||||
this.addButton(leaveButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean flag, int i) {
|
||||
if (flag) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
Client.sendData(EnumPacketServer.SetPartyLeader, this.selectedPlayer);
|
||||
break;
|
||||
case 1:
|
||||
Client.sendData(EnumPacketServer.KickPlayer, this.selectedPlayer);
|
||||
break;
|
||||
case 2:
|
||||
Client.sendData(EnumPacketServer.DisbandParty);
|
||||
break;
|
||||
case 3:
|
||||
Client.sendData(EnumPacketServer.KickPlayer, this.player.getCommandSenderName());
|
||||
break;
|
||||
}
|
||||
receivedData = false;
|
||||
initGui();
|
||||
}
|
||||
displayGuiScreen(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
Party party = ClientCacheHandler.party;
|
||||
|
||||
switch (guibutton.id) {
|
||||
case 200:
|
||||
Client.sendData(EnumPacketServer.CreateParty);
|
||||
receivedData = false;
|
||||
break;
|
||||
case 215:
|
||||
if (this.selectedInvite != null && !this.selectedInvite.isEmpty()) {
|
||||
Client.sendData(EnumPacketServer.AcceptInvite, this.selectedInvite);
|
||||
receivedData = false;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 220:
|
||||
if (this.selectedInvite != null && !this.selectedInvite.isEmpty()) {
|
||||
Client.sendData(EnumPacketServer.IgnoreInvite, this.selectedInvite);
|
||||
receivedData = false;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 305:
|
||||
if (this.selectedPlayer != null && !this.selectedPlayer.isEmpty() && !party.getPartyLeaderName().equals(this.selectedPlayer)) {
|
||||
GuiYesNo yesnoLeader = new GuiYesNo(this, StatCollector.translateToLocal("party.leaderConfirm"), this.selectedPlayer, 0);
|
||||
displayGuiScreen(yesnoLeader);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 310:
|
||||
if (this.selectedPlayer != null && !this.selectedPlayer.isEmpty() && !party.getPartyLeaderName().equals(this.selectedPlayer)) {
|
||||
GuiYesNo yesnoKick = new GuiYesNo(this, StatCollector.translateToLocal("party.kickConfirm"), this.selectedPlayer, 1);
|
||||
displayGuiScreen(yesnoKick);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 320:
|
||||
party.toggleFriendlyFire();
|
||||
this.partyChanged = true;
|
||||
break;
|
||||
case 330:
|
||||
String inviteName = this.getTextField(325).getText();
|
||||
if (!inviteName.isEmpty() && !party.getPlayerNames(true).contains(inviteName.toLowerCase())) {
|
||||
Client.sendData(EnumPacketServer.PartyInvite, inviteName);
|
||||
this.getTextField(325).setText("");
|
||||
}
|
||||
break;
|
||||
case 335:
|
||||
Client.sendData(EnumPacketServer.DisbandParty);
|
||||
receivedData = false;
|
||||
if (this.isLeader) {
|
||||
GuiYesNo yesnoDisband = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.disbandConfirm"), 2);
|
||||
displayGuiScreen(yesnoDisband);
|
||||
} else {
|
||||
GuiYesNo yesnoLeave = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.leaveConfirm"), 3);
|
||||
displayGuiScreen(yesnoLeave);
|
||||
}
|
||||
break;
|
||||
}
|
||||
initGui();
|
||||
@@ -190,17 +293,25 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.receivedData = true;
|
||||
ClientCacheHandler.party = null;
|
||||
|
||||
if (compound.hasKey("PartyUUID")) {
|
||||
Party party = ClientCacheHandler.party;
|
||||
UUID uuid = UUID.fromString(compound.getString("PartyUUID"));
|
||||
if (party == null || !party.getPartyUUID().equals(uuid)) {
|
||||
ClientCacheHandler.party = new Party(uuid);
|
||||
party = ClientCacheHandler.party;
|
||||
}
|
||||
ClientCacheHandler.party = new Party(uuid);
|
||||
Party party = ClientCacheHandler.party;
|
||||
party.readFromNBT(compound);
|
||||
this.isLeader = ClientCacheHandler.party.getPartyLeaderName().equals(this.player.getCommandSenderName());
|
||||
} else if (compound.hasKey("Disband")) {
|
||||
ClientCacheHandler.party = null;
|
||||
this.isLeader = false;
|
||||
} else if (compound.hasKey("PartyInvites")) {
|
||||
this.invites.clear();
|
||||
NBTTagList list = compound.getTagList("PartyInvites", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound listCompound = list.getCompoundTagAt(i);
|
||||
String inviteName = listCompound.getString("PartyLeader");
|
||||
String partyUUID = listCompound.getString("PartyUUID");
|
||||
this.invites.put(inviteName, partyUUID);
|
||||
}
|
||||
}
|
||||
|
||||
initGui();
|
||||
@@ -214,12 +325,21 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
if (this.partyChanged) {
|
||||
Client.sendData(EnumPacketServer.SavePartyData, ClientCacheHandler.party.writeClientNBT());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
|
||||
switch (guiCustomScroll.id) {
|
||||
case 210:
|
||||
this.selectedInvite = this.invites.get(guiCustomScroll.getSelected());
|
||||
break;
|
||||
case 300:
|
||||
this.selectedPlayer = guiCustomScroll.getSelected().replace(" §e[" + StatCollector.translateToLocal("party.leader").toUpperCase() + "]", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
|
||||
public class GuiScriptBlock extends GuiScriptInterface {
|
||||
private TileScripted tileScripted;
|
||||
|
||||
public GuiScriptBlock(int x, int y, int z) {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("fallenUpon");
|
||||
hookList.add("redstone");
|
||||
hookList.add("broken");
|
||||
hookList.add("exploded");
|
||||
hookList.add("rainFilled");
|
||||
hookList.add("neighborChanged");
|
||||
hookList.add("clicked");
|
||||
hookList.add("harvested");
|
||||
hookList.add("collide");
|
||||
hookList.add("timer");
|
||||
|
||||
this.handler = this.tileScripted = (TileScripted) player.worldObj.getTileEntity(x, y, z);
|
||||
Client.sendData(EnumPacketServer.ScriptBlockDataGet, tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord);
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.tileScripted.setNBT(compound);
|
||||
super.setGuiData(compound);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
Client.sendData(EnumPacketServer.ScriptBlockDataSave, tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package noppes.npcs.client.renderer.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.blocks.BlockScripted;
|
||||
import noppes.npcs.blocks.tiles.TileScripted;
|
||||
import noppes.npcs.blocks.tiles.TileScripted.TextPlane;
|
||||
import noppes.npcs.client.TextBlockClient;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockScriptedRenderer extends BlockRendererInterface{
|
||||
private static final RenderBlocks renderBlocks = new RenderBlocks();
|
||||
private static final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks) {
|
||||
TileScripted tile = (TileScripted) te;
|
||||
GL11.glPushMatrix();
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glTranslatef((float) (x + 0.5), (float) y, (float) (z + 0.5));
|
||||
if (overrideModel()) {
|
||||
GL11.glTranslatef(0, 0.5F, 0);
|
||||
renderItem(te, new ItemStack(CustomItems.scripted));
|
||||
} else {
|
||||
GL11.glRotatef(tile.rotationY, 0, 1, 0);
|
||||
GL11.glRotatef(tile.rotationX, 1, 0, 0);
|
||||
GL11.glRotatef(tile.rotationZ, 0, 0, 1);
|
||||
GL11.glScalef(tile.scaleX, tile.scaleY, tile.scaleZ);
|
||||
GL11.glTranslatef(0, 0.5F, 0);
|
||||
renderItem(te, tile.itemModel);
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
|
||||
if (!tile.text1.text.isEmpty()) {
|
||||
drawText(tile.text1, x, y, z);
|
||||
}
|
||||
if (!tile.text2.text.isEmpty()) {
|
||||
drawText(tile.text2, x, y, z);
|
||||
}
|
||||
if (!tile.text3.text.isEmpty()) {
|
||||
drawText(tile.text3, x, y, z);
|
||||
}
|
||||
if (!tile.text4.text.isEmpty()) {
|
||||
drawText(tile.text4, x, y, z);
|
||||
}
|
||||
if (!tile.text5.text.isEmpty()) {
|
||||
drawText(tile.text5, x, y, z);
|
||||
}
|
||||
if (!tile.text6.text.isEmpty()) {
|
||||
drawText(tile.text6, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawText(TextPlane text1, double x, double y, double z) {
|
||||
if (text1.textBlock == null || text1.textHasChanged) {
|
||||
text1.textBlock = new TextBlockClient(text1.text, 336, true, Minecraft.getMinecraft().thePlayer);
|
||||
text1.textHasChanged = false;
|
||||
}
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) (x + 0.5), (float) (y + 0.5), (float) (z + 0.5));
|
||||
GL11.glRotatef(text1.rotationY, 0, 1, 0);
|
||||
GL11.glRotatef(text1.rotationX, 1, 0, 0);
|
||||
GL11.glRotatef(text1.rotationZ, 0, 0, 1);
|
||||
GL11.glScalef(text1.scale, text1.scale, 1);
|
||||
GL11.glTranslatef(text1.offsetX, text1.offsetY, text1.offsetZ);
|
||||
float f1 = 0.6666667F;
|
||||
float f3 = 0.0133F * f1;
|
||||
GL11.glTranslatef(0.0F, 0.5F, 0.01F);
|
||||
GL11.glScalef(f3, -f3, f3);
|
||||
GL11.glNormal3f(0.0F, 0.0F, -1.0F * f3);
|
||||
GL11.glDepthMask(false);
|
||||
FontRenderer fontrenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
float lineOffset = 0;
|
||||
if (text1.textBlock.lines.size() < 14)
|
||||
lineOffset = (14f - text1.textBlock.lines.size()) / 2;
|
||||
for (int i = 0; i < text1.textBlock.lines.size(); i++) {
|
||||
String text = text1.textBlock.lines.get(i).getFormattedText();
|
||||
fontrenderer.drawString(text, -fontrenderer.getStringWidth(text) / 2, (int) ((lineOffset + i) * (fontrenderer.FONT_HEIGHT - 0.3)), 0);
|
||||
}
|
||||
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glColor3f(1.0F, 1.0F, 1.0F);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void renderItem(TileEntity tile, ItemStack stack) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (stack != null) {
|
||||
mc.renderEngine.bindTexture(stack.getItem() instanceof ItemBlock ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture);
|
||||
|
||||
GL11.glScalef(2F, 2F, 2F);
|
||||
if (!ForgeHooksClient.renderEntityItem(new EntityItem(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, stack), stack, 0F, 0F, tile.getWorldObj().rand, mc.renderEngine, renderBlocks, 1)) {
|
||||
GL11.glScalef(0.5F, 0.5F, 0.5F);
|
||||
if (stack.getItem() instanceof ItemBlock && (RenderBlocks.renderItemIn3d(Block.getBlockFromItem(stack.getItem()).getRenderType())
|
||||
|| Block.getBlockFromItem(stack.getItem()) instanceof BlockScripted)) {
|
||||
renderBlocks.renderBlockAsItem(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage(), 1F);
|
||||
} else {
|
||||
int renderPass = 0;
|
||||
do {
|
||||
IIcon icon = stack.getItem().getIcon(stack, renderPass);
|
||||
if (icon != null) {
|
||||
Color color = new Color(stack.getItem().getColorFromItemStack(stack, renderPass));
|
||||
GL11.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
|
||||
float f = icon.getMinU();
|
||||
float f1 = icon.getMaxU();
|
||||
float f2 = icon.getMinV();
|
||||
float f3 = icon.getMaxV();
|
||||
GL11.glTranslatef(-0.5F, -0.5F, 0F);
|
||||
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F);
|
||||
GL11.glColor3f(1F, 1F, 1F);
|
||||
}
|
||||
renderPass++;
|
||||
} while(renderPass < stack.getItem().getRenderPasses(stack.getItemDamage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void renderBlock(TileScripted tile, Block b) {
|
||||
GL11.glPushMatrix();
|
||||
this.bindTexture(TextureMap.locationBlocksTexture);
|
||||
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glTranslatef(-0.5F, -0, 0.5F);
|
||||
renderBlocks.renderStandardBlock(b, tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
if (b.getTickRandomly() && random.nextInt(12) == 1)
|
||||
b.randomDisplayTick(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, random);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private boolean overrideModel() {
|
||||
ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem();
|
||||
if (held == null)
|
||||
return false;
|
||||
|
||||
return held.getItem() == CustomItems.wand || held.getItem() == CustomItems.scripter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderId() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user