diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 531ef5f3..c2f74d1e 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -960,32 +960,31 @@ public class Client implements IThreadListener { public void renderHud() { this.setupOverlay(); - if(this.world != null && this.open == null && this.thirdPersonView == 0 && this.viewEntity != null) { - if(this.drawDebug) { - this.renderWorldDirections((float)this.tick_fraction); - } - else if(this.crosshairSize > 0) { - Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - this.crosshairSize, 2, this.crosshairSize * 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); - Drawing.drawRect(this.fb_x / 2 - this.crosshairSize, this.fb_y / 2 - 1, this.crosshairSize * 2, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); - } - } - if(this.world != null && this.open == null) { - int selected = // this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer() ? 9 : 0, - this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer() ? - ((EntityNPC)this.getRenderViewEntity()).inventory.currentItem : -1; - for(int n = 0; n < 9; n++) { - int x = this.fb_x / 2 - 180 + n * 40 + 4; - int y = this.fb_y - 40; -// Drawing.drawRect2Border(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xffafafaf); - Drawing.drawRectBorder(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xff000000, 0xffafafaf, 0xff4f4f4f); - } + if(this.world != null && !(this.open instanceof GuiConsole) && this.player != null && this.viewEntity == this.player) { + if(this.open == null) { + if(this.thirdPersonView == 0) { + if(this.drawDebug) { + this.renderWorldDirections((float)this.tick_fraction); + } + else if(this.crosshairSize > 0) { + Drawing.drawRect(this.fb_x / 2 - 1, this.fb_y / 2 - this.crosshairSize, 2, this.crosshairSize * 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); + Drawing.drawRect(this.fb_x / 2 - this.crosshairSize, this.fb_y / 2 - 1, this.crosshairSize * 2, 2, this.pointed != null && this.pointed.type != ObjectType.MISS ? this.crosshairColorTarget : this.crosshairColorBase); + } + } + + int selected = this.player.inventory.currentItem; + for(int n = 0; n < 9; n++) { + int x = this.fb_x / 2 - 180 + n * 40 + 4; + int y = this.fb_y - 40; + Drawing.drawRectBorder(x - 1, y - 1, 36, 36, 0xff6f6f6f, selected == n ? 0xffffffff : 0xff000000, 0xffafafaf, 0xff4f4f4f); + } - ItemStack itemstack = this.player != null ? this.player.inventory.getCurrentItem() : null; - String current = itemstack != null ? itemstack.getItem().getHotbarText(this.player, itemstack) : ""; - if(!current.isEmpty()) - Drawing.drawTextUpward(current, this.fb_x / 2, this.fb_y - 60, 0xffffffff); - } - if(this.world != null && !(this.open instanceof GuiConsole)) { + ItemStack itemstack = this.player.inventory.getCurrentItem(); + String current = itemstack != null ? itemstack.getItem().getHotbarText(this.player, itemstack) : ""; + if(!current.isEmpty()) + Drawing.drawTextUpward(current, this.fb_x / 2, this.fb_y - 60, 0xffffffff); + } + int x = this.fb_x / 2; int y = 0; Iterator> iter = this.bars.entrySet().iterator(); @@ -1011,7 +1010,7 @@ public class Client implements IThreadListener { } } - if(this.player != null && (!this.drawDebug || this.open != null)) { + if(!this.drawDebug || this.open != null) { x = 40; y = 40; for(PotionEffect effect : this.player.getEffects()) { @@ -1028,61 +1027,50 @@ public class Client implements IThreadListener { } } - if(this.getRenderViewEntity() instanceof EntityLiving) { - EntityLiving entity = (EntityLiving)this.getRenderViewEntity(); - int absorb = entity.getAbsorptionAmount(); - int armor = entity.getTotalArmorValue(); - int stats = 1 + (absorb > 0 ? 1 : 0) + (armor > 0 ? 1 : 0) + (entity.vehicle instanceof EntityLiving ? 1 : 0) - + (entity instanceof EntityNPC npc && npc.getManaPoints() > 0 ? 1 : 0); - for(Energy energy : Energy.values()) { - if(entity.getEnergy(energy) > 0) - stats += 1; - } - x = this.fb_x - 40 - 250; - y = this.fb_y - 40 - stats * 40; - int hp = entity.getHealth(); - int max = entity.getMaxHealth(); - y = stats(x, y, TextColor.RED + "Schaden", hp, max, 0xff0000); - if(absorb > 0) - y = stats(x, y, TextColor.YELLOW + "Schadenspuffer", absorb, 1024, 0xffff00); - if(armor > 0) - y = stats(x, y, TextColor.GRAY + "Rüstung", armor, 1024, 0x707070); - if(entity.vehicle instanceof EntityLiving) { - EntityLiving living = (EntityLiving)entity.vehicle; - int vh = living.getHealth(); - int vhMax = living.getMaxHealth(); - y = stats(x, y, living.getDisplayName() /* + " (Reittier)" */, vh, vhMax, 0xff6060); - } - if(entity instanceof EntityNPC npc && npc.getManaPoints() > 0) { - int mana = npc.getManaPoints(); - int maxm = npc.getMaxMana(); - y = stats(x, y, TextColor.CYAN + "Mana", mana, maxm, 0x0000ff); - } - for(int z = 0; z < Energy.values().length; z++) { - Energy type = Energy.values()[z]; - int energy = entity.getEnergy(type); - if(energy > 0) { - int emax = entity.getEnergyCap(type); - y = stats(x, y, TextColor.LGRAY + type.display, energy, emax, entity.hasEnergyEffect(type) ? type.effect : type.color); - } + EntityNPC entity = this.player; + int absorb = entity.getAbsorptionAmount(); + int armor = entity.getTotalArmorValue(); + int stats = 1 + (absorb > 0 ? 1 : 0) + (armor > 0 ? 1 : 0) + (entity.vehicle instanceof EntityLiving ? 1 : 0) + + (entity instanceof EntityNPC npc && npc.getManaPoints() > 0 ? 1 : 0); + for(Energy energy : Energy.values()) { + if(entity.getEnergy(energy) > 0) + stats += 1; + } + x = this.fb_x - 40 - 250; + y = this.fb_y - 40 - stats * 40; + int hp = entity.getHealth(); + int max = entity.getMaxHealth(); + y = stats(x, y, TextColor.RED + "Schaden", hp, max, 0xff0000); + if(absorb > 0) + y = stats(x, y, TextColor.YELLOW + "Schadenspuffer", absorb, 1024, 0xffff00); + if(armor > 0) + y = stats(x, y, TextColor.GRAY + "Rüstung", armor, 1024, 0x707070); + if(entity.vehicle instanceof EntityLiving) { + EntityLiving living = (EntityLiving)entity.vehicle; + int vh = living.getHealth(); + int vhMax = living.getMaxHealth(); + y = stats(x, y, living.getDisplayName() /* + " (Reittier)" */, vh, vhMax, 0xff6060); + } + if(entity instanceof EntityNPC npc && npc.getManaPoints() > 0) { + int mana = npc.getManaPoints(); + int maxm = npc.getMaxMana(); + y = stats(x, y, TextColor.CYAN + "Mana", mana, maxm, 0x0000ff); + } + for(int z = 0; z < Energy.values().length; z++) { + Energy type = Energy.values()[z]; + int energy = entity.getEnergy(type); + if(energy > 0) { + int emax = entity.getEnergyCap(type); + y = stats(x, y, TextColor.LGRAY + type.display, energy, emax, entity.hasEnergyEffect(type) ? type.effect : type.color); } } - - if(this.player != null) { - x = 40; - y = this.fb_y - 40 - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40; - if(this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f) // { - y = bar(x, y, String.format(TextColor.NEON + "Sprungkraft: " + TextColor.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)), - this.player.getHorseJumpPower(), 0x4040ff); - // } - // else { - y = bar(x, y, String.format(TextColor.ACID + "EXP: " + TextColor.GREEN + "Level %d, %d/%d", this.player.experienceLevel, (int)((float)this.player.xpBarCap() * this.player.experience), this.player.xpBarCap()), this.player.experience, 0x40ff40); - // } - } - - -// SKC.pointed(this.pointed != null && this.pointed.type != ObjectType.MISS); -// SKC.crosshair(this.thirdPersonView == 0); + + x = 40; + y = this.fb_y - 40 - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40; + if(this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f) // { + y = bar(x, y, String.format(TextColor.NEON + "Sprungkraft: " + TextColor.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)), + this.player.getHorseJumpPower(), 0x4040ff); + y = bar(x, y, String.format(TextColor.ACID + "EXP: " + TextColor.GREEN + "Level %d, %d/%d", this.player.experienceLevel, (int)((float)this.player.xpBarCap() * this.player.experience), this.player.xpBarCap()), this.player.experience, 0x40ff40); } // gdr.shader = 0; @@ -1098,8 +1086,7 @@ public class Client implements IThreadListener { GlState.setActiveTexture(GL13.GL_TEXTURE0); GlState.enableTexture2D(); // GlState.disableDepth(); - if(this.open == null && this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer()) { - EntityNPC player = (EntityNPC)this.getRenderViewEntity(); + if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) { GlState.enableRescaleNormal(); GlState.enableBlend(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -1113,7 +1100,7 @@ public class Client implements IThreadListener { for(int index = 0; index < 9; ++index) { int xPos = index * 20; // int yPos = this.fb_y - 40; - ItemStack itemstack = player.inventory.mainInventory[index]; + ItemStack itemstack = this.player.inventory.mainInventory[index]; if(itemstack != null) { GlState.enableDepth(); this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); @@ -1135,10 +1122,9 @@ public class Client implements IThreadListener { // java_check_exc(); GlState.disableDepth(); // SKC.foreground(); - if(this.open == null && this.getRenderViewEntity() != null && this.getRenderViewEntity().isPlayer()) { - EntityNPC player = (EntityNPC)this.getRenderViewEntity(); + if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) { for(int index = 0; index < 9; ++index) { - ItemStack itemstack = player.inventory.mainInventory[index]; + ItemStack itemstack = this.player.inventory.mainInventory[index]; if(itemstack != null) { GuiContainer.renderItemOverlay(itemstack, this.fb_x / 2 - 180 + 4 + 1 + index * 40, this.fb_y - 40 + 1, null); @@ -1158,9 +1144,19 @@ public class Client implements IThreadListener { this.drawOverlay(this.chat, this.chatSize, true, -1, this.fb_x, this.fb_y); } if(this.drawFps) { // && !(this.open instanceof GuiConsole) - if(this.drawDebug && this.open == null) { - this.renderStats(); - this.renderLagometer(); + if(this.drawDebug) { + if(this.open == null) { + this.renderStats(); + this.renderLagometer(); + } + else { + Drawing.drawText(String.format("%s%.2f" + TextColor.RESET + " %s [%s" + TextColor.RESET + "], %.3f ms, W %d x %d%s", + this.framecode(), this.framerate < 1.0f ? 1.0f / this.framerate : this.framerate, this.framerate < 1.0f ? "SPF" : "FPS", + this.vsync ? TextColor.DGRAY + "VSYNC" : (this.syncLimited ? TextColor.GREEN + "" + this.syncLimit : TextColor.RED + "UNL"), + (float)PerfSection.getTotal(false) / 1000.0f, this.fb_raw_x, this.fb_raw_y, + this.fullscreen ? " @ " + (this.vidMode == null ? "?" : this.vidMode.refresh()) + " Hz" : ""), + 0, 0, 0xffffffff); + } } else { Drawing.drawText(String.format("%s%.2f", framecode(), this.framerate), 0, 0, 0xffffffff); diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index c7f58ccd..49f9a6ba 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -115,6 +115,7 @@ import common.packet.SPacketSpawnObject; import common.packet.SPacketSpawnPlayer; import common.packet.SPacketTimeUpdate; import common.packet.SPacketTrades; +import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateHealth; import common.packet.SPacketWorld; import common.potion.PotionEffect; @@ -122,6 +123,7 @@ import common.rng.Random; import common.sound.Sound; import common.tileentity.TileEntity; import common.tileentity.TileEntityDevice; +import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntitySign; import common.village.MerchantRecipeList; import common.world.Explosion; @@ -1314,6 +1316,20 @@ public class ClientPlayer implements IClientPlayer // } } + public void handleUpdateDisplay(SPacketUpdateDisplay packet) { + NetHandler.checkThread(packet, this, this.gm, this.world); + + if(this.gm.world.isBlockLoaded(packet.getPos())) { + TileEntity tileentity = this.gm.world.getTileEntity(packet.getPos()); + + if(tileentity instanceof TileEntityDisplay display) { + System.arraycopy(packet.getPixels(), 0, display.data, 0, 256); + display.lastUpdated = System.currentTimeMillis(); + display.markDirty(); + } + } + } + /** * Updates the metadata of instances of the following entitytypes: Mob spawners, command blocks, * beacons, skulls, flowerpot diff --git a/client/src/main/java/client/renderer/Drawing.java b/client/src/main/java/client/renderer/Drawing.java index 1337d9bd..16e055af 100644 --- a/client/src/main/java/client/renderer/Drawing.java +++ b/client/src/main/java/client/renderer/Drawing.java @@ -28,19 +28,6 @@ public abstract class Drawing { this.offset = off; } } - -// public static void drawTexturedModalRect(int tw, int th, int x, int y, int textureX, int textureY, int width, int height) -// { -// float xs = 1.0f / (float)tw; // 0.00390625F; -// float ys = 1.0f / (float)th; // 0.00390625F; -// RenderBuffer rb = Tessellator.getBuffer(); -// rb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); -// rb.pos((double)(x + 0), (double)(y + height), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + height) * ys)).endVertex(); -// rb.pos((double)(x + width), (double)(y + height), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + height) * ys)).endVertex(); -// rb.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(textureX + width) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); -// rb.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(textureX + 0) * xs), (double)((float)(textureY + 0) * ys)).endVertex(); -// Tessellator.draw(); -// } public static void txt_draw(int x, int y, int x1, int y1, int x2, int y2, int color, String str) { GlState.enableTexture2D(); @@ -586,4 +573,29 @@ public abstract class Drawing { GlState.disableTexture2D(); GlState.color(1.0F, 1.0F, 1.0F, 1.0F); } + + public static void drawTexturedRect(Client gm, String texture, int texWidth, int texHeight, int x, int y, int u, int v, int width, int height) + { + GlState.enableTexture2D(); +// GlState.disableFog(); + RenderBuffer buf = Tessellator.getBuffer(); + gm.getTextureManager().bindTexture(texture); +// GlState.color(color); + float xs = 1.0f / (float)texWidth; // 0.00390625F; + float ys = 1.0f / (float)texHeight; // 0.00390625F; + buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + buf.pos((double)(x + 0), (double)(y + height), 0.0).tex((double)((float)(u + 0) * xs), (double)((float)(v + height) * ys)).endVertex(); + buf.pos((double)(x + width), (double)(y + height), 0.0).tex((double)((float)(u + width) * xs), (double)((float)(v + height) * ys)).endVertex(); + buf.pos((double)(x + width), (double)(y + 0), 0.0).tex((double)((float)(u + width) * xs), (double)((float)(v + 0) * ys)).endVertex(); + buf.pos((double)(x + 0), (double)(y + 0), 0.0).tex((double)((float)(u + 0) * xs), (double)((float)(v + 0) * ys)).endVertex(); +// double scale = 32.0; +// buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); +// buf.pos((double)x, (double)y + (double)height, 0.0D).tex(0.0D, (double)height / scale).endVertex(); +// buf.pos((double)x + (double)width, (double)y + (double)height, 0.0D).tex((double)width / scale, (double)height / scale).endVertex(); +// buf.pos((double)x + (double)width, (double)y, 0.0D).tex((double)width / scale, 0.0).endVertex(); +// buf.pos((double)x, (double)y, 0.0D).tex(0.0D, 0.0).endVertex(); + Tessellator.draw(); +// GlState.disableTexture2D(); + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + } } diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityBannerRenderer.java b/client/src/main/java/client/renderer/tileentity/TileEntityBannerRenderer.java index 0b65a2db..9d35dca7 100755 --- a/client/src/main/java/client/renderer/tileentity/TileEntityBannerRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/TileEntityBannerRenderer.java @@ -20,142 +20,123 @@ import common.util.BlockPos; import common.util.ExtMath; import common.world.State; -public class TileEntityBannerRenderer extends TileEntitySpecialRenderer -{ - private static final Map DESIGNS = Maps.newHashMap(); - private static final String BANNERTEXTURES = "textures/blocks/banner.png"; - private ModelBanner bannerModel = new ModelBanner(); +public class TileEntityBannerRenderer extends TileEntitySpecialRenderer { + private static class TimedTexture { + public long time; + public String texture; - public void renderTileEntityAt(TileEntityBanner te, double x, double y, double z, float partialTicks, int destroyStage) - { - boolean flag = te.getWorld() != null; - boolean flag1 = !flag || te.getBlockType() == Blocks.banner; - int i = 0; - if(flag) { - State state = te.getBlockState(); - if(state.getBlock() == Blocks.banner) - i = state.getValue(BlockBannerStanding.ROTATION); - } + private TimedTexture() { + } + } + + private static final Map DESIGNS = Maps.newHashMap(); + private static final String BANNERTEXTURES = "textures/blocks/banner.png"; + private ModelBanner bannerModel = new ModelBanner(); + + public void renderTileEntityAt(TileEntityBanner te, double x, double y, double z, float partialTicks, int destroyStage) { + boolean flag = te.getWorld() != null; + boolean flag1 = !flag || te.getBlockType() == Blocks.banner; + int i = 0; + if(flag) { + State state = te.getBlockState(); + if(state.getBlock() == Blocks.banner) + i = state.getValue(BlockBannerStanding.ROTATION); + } // long j = flag ? te.getWorld().getTime() : 0L; - double j = flag ? (double)(System.nanoTime() / 1000L) / 50000.0 /* te.getWorld().getTime() */ : (double)partialTicks; - GL11.glPushMatrix(); - float f = 0.6666667F; + double j = flag ? (double)(System.nanoTime() / 1000L) / 50000.0 /* te.getWorld().getTime() */ : (double)partialTicks; + GL11.glPushMatrix(); + float f = 0.6666667F; - if (flag1) - { - GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); - float f1 = (float)(i * 360) / 16.0F; - GL11.glRotatef(-f1, 0.0F, 1.0F, 0.0F); - this.bannerModel.bannerStand.showModel = true; - } - else - { - float f2 = 0.0F; + if(flag1) { + GL11.glTranslatef((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F); + float f1 = (float)(i * 360) / 16.0F; + GL11.glRotatef(-f1, 0.0F, 1.0F, 0.0F); + this.bannerModel.bannerStand.showModel = true; + } + else { + float f2 = 0.0F; - if (i == 2) - { - f2 = 180.0F; - } + if(i == 2) { + f2 = 180.0F; + } - if (i == 4) - { - f2 = 90.0F; - } + if(i == 4) { + f2 = 90.0F; + } - if (i == 5) - { - f2 = -90.0F; - } + if(i == 5) { + f2 = -90.0F; + } - GL11.glTranslatef((float)x + 0.5F, (float)y - 0.25F * f, (float)z + 0.5F); - GL11.glRotatef(-f2, 0.0F, 1.0F, 0.0F); - GL11.glTranslatef(0.0F, -0.3125F, -0.4375F); - this.bannerModel.bannerStand.showModel = false; - } + GL11.glTranslatef((float)x + 0.5F, (float)y - 0.25F * f, (float)z + 0.5F); + GL11.glRotatef(-f2, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(0.0F, -0.3125F, -0.4375F); + this.bannerModel.bannerStand.showModel = false; + } - BlockPos blockpos = te.getPos(); - float f3 = (float)(blockpos.getX() * 7 + blockpos.getY() * 9 + blockpos.getZ() * 13) + (float)j; // + partialTicks; - this.bannerModel.bannerSlate.rotateAngleX = (-0.0125F + 0.01F * ExtMath.cos(f3 * (float)Math.PI * 0.02F)) * (float)Math.PI; - GlState.enableRescaleNormal(); - String resourcelocation = this.func_178463_a(te); + BlockPos blockpos = te.getPos(); + float f3 = (float)(blockpos.getX() * 7 + blockpos.getY() * 9 + blockpos.getZ() * 13) + (float)j; // + partialTicks; + this.bannerModel.bannerSlate.rotateAngleX = (-0.0125F + 0.01F * ExtMath.cos(f3 * (float)Math.PI * 0.02F)) * (float)Math.PI; + GlState.enableRescaleNormal(); + String resourcelocation = this.getTexture(te); - if (resourcelocation != null) - { - this.bindTexture(resourcelocation); - GL11.glPushMatrix(); - GL11.glScalef(f, -f, -f); - this.bannerModel.renderBanner(); - GL11.glPopMatrix(); - } + if(resourcelocation != null) { + this.bindTexture(resourcelocation); + GL11.glPushMatrix(); + GL11.glScalef(f, -f, -f); + this.bannerModel.renderBanner(); + GL11.glPopMatrix(); + } - GlState.color(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopMatrix(); - } + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } - private String func_178463_a(TileEntityBanner bannerObj) - { - String s = bannerObj.getPatternResourceLocation(); + private String getTexture(TileEntityBanner te) { + String s = te.getPatternResourceLocation(); - if (s.isEmpty()) - { - return null; - } - else - { - TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s); + if(s.isEmpty()) { + return null; + } + else { + TimedTexture tex = (TimedTexture)DESIGNS.get(s); - if (tileentitybannerrenderer$timedbannertexture == null) - { - if (DESIGNS.size() >= 256) - { - long i = System.currentTimeMillis(); - Iterator iterator = DESIGNS.keySet().iterator(); + if(tex == null) { + if(DESIGNS.size() >= 256) { + long i = System.currentTimeMillis(); + Iterator iterator = DESIGNS.keySet().iterator(); - while (iterator.hasNext()) - { - String s1 = (String)iterator.next(); - TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture1 = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s1); + while(iterator.hasNext()) { + String s1 = (String)iterator.next(); + TimedTexture tileentitybannerrenderer$timedbannertexture1 = (TimedTexture)DESIGNS.get(s1); - if (i - tileentitybannerrenderer$timedbannertexture1.systemTime > 60000L) - { - Client.CLIENT.getTextureManager().deleteTexture(tileentitybannerrenderer$timedbannertexture1.bannerTexture); - iterator.remove(); - } - } + if(i - tileentitybannerrenderer$timedbannertexture1.time > 60000L) { + Client.CLIENT.getTextureManager().deleteTexture(tileentitybannerrenderer$timedbannertexture1.texture); + iterator.remove(); + } + } - if (DESIGNS.size() >= 256) - { - return null; - } - } + if(DESIGNS.size() >= 256) { + return null; + } + } - List list1 = bannerObj.getPatternList(); - List list = bannerObj.getColorList(); - List list2 = Lists.newArrayList(); + List list1 = te.getPatternList(); + List list = te.getColorList(); + List list2 = Lists.newArrayList(); - for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : list1) - { - list2.add("textures/blocks/banner_" + tileentitybanner$enumbannerpattern.getPatternName() + ".png"); - } + for(TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : list1) { + list2.add("textures/blocks/banner_" + tileentitybanner$enumbannerpattern.getPatternName() + ".png"); + } - tileentitybannerrenderer$timedbannertexture = new TileEntityBannerRenderer.TimedBannerTexture(); - tileentitybannerrenderer$timedbannertexture.bannerTexture = s; - Client.CLIENT.getTextureManager().loadTexture(tileentitybannerrenderer$timedbannertexture.bannerTexture, new LayeredColorMaskTexture(BANNERTEXTURES, list2, list)); - DESIGNS.put(s, tileentitybannerrenderer$timedbannertexture); - } + tex = new TimedTexture(); + tex.texture = s; + Client.CLIENT.getTextureManager().loadTexture(tex.texture, new LayeredColorMaskTexture(BANNERTEXTURES, list2, list)); + DESIGNS.put(s, tex); + } - tileentitybannerrenderer$timedbannertexture.systemTime = System.currentTimeMillis(); - return tileentitybannerrenderer$timedbannertexture.bannerTexture; - } - } - - static class TimedBannerTexture - { - public long systemTime; - public String bannerTexture; - - private TimedBannerTexture() - { - } - } + tex.time = System.currentTimeMillis(); + return tex.texture; + } + } } diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java b/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java new file mode 100644 index 00000000..76606f6b --- /dev/null +++ b/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java @@ -0,0 +1,104 @@ +package client.renderer.tileentity; + +import java.util.Iterator; +import java.util.Map; + +import org.lwjgl.opengl.GL11; + +import client.Client; +import client.renderer.Drawing; +import client.renderer.GlState; +import client.renderer.texture.DynamicTexture; +import common.block.Block; +import common.block.tech.BlockDisplay; +import common.collect.Maps; +import common.tileentity.TileEntityDisplay; +import common.util.BlockPos; +import common.util.Facing; +import common.world.State; + +public class TileEntityDisplayRenderer extends TileEntitySpecialRenderer { + private static class TimedTexture { + public long time; + public long updated; + public String texture; + } + + private static final Map DISPLAYS = Maps.newHashMap(); + + private static String getTextureLocation(BlockPos pos) { + return "display/" + pos.getX() + "," + pos.getY() + "," + pos.getZ(); + } + + private static String getTexture(TileEntityDisplay te) { + String id = getTextureLocation(te.getPos()); + TimedTexture tex = DISPLAYS.get(id); + + if(tex == null) { + if(DISPLAYS.size() >= 256) { + long i = System.currentTimeMillis(); + Iterator iterator = DISPLAYS.keySet().iterator(); + + while(iterator.hasNext()) { + String oid = iterator.next(); + TimedTexture ttex = DISPLAYS.get(oid); + + if(i - ttex.time > 60000L) { + Client.CLIENT.getTextureManager().deleteTexture(ttex.texture); + iterator.remove(); + } + } + + if(DISPLAYS.size() >= 256) { + return null; + } + } + + tex = new TimedTexture(); + tex.texture = id; + tex.updated = te.lastUpdated; + DynamicTexture dtex = new DynamicTexture(16, 16); + System.arraycopy(te.data, 0, dtex.getData(), 0, 256); + dtex.updateTexture(); + Client.CLIENT.getTextureManager().loadTexture(tex.texture, dtex); + DISPLAYS.put(id, tex); + } + else if(te.lastUpdated != tex.updated) { + tex.updated = te.lastUpdated; + if(Client.CLIENT.getTextureManager().getTexture(tex.texture) instanceof DynamicTexture dtex) { + System.arraycopy(te.data, 0, dtex.getData(), 0, 256); + dtex.updateTexture(); + } + } + + tex.time = System.currentTimeMillis(); + return tex.texture; + } + + public void renderTileEntityAt(TileEntityDisplay te, double x, double y, double z, float partialTicks, int destroyStage) { + Block block = te.getBlockType(); + + State state = te.getBlockState(); + Facing dir = state.getBlock() instanceof BlockDisplay ? state.getValue(BlockDisplay.FACING) : Facing.SOUTH; + float rot = 0.0F; + if(dir == Facing.NORTH) + rot = 180.0F; + else if(dir == Facing.WEST) + rot = 90.0F; + else if(dir == Facing.EAST) + rot = -90.0F; + + GL11.glPushMatrix(); + GL11.glTranslatef((float)x + 0.5F, (float)y + 1.0f, (float)z + 0.5F); + GL11.glRotatef(-rot, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, 0.0f, -0.5f + 0.0625f + 0.005f); + GL11.glScalef(0.0625f, -0.0625f, 0.0625f); + + GlState.disableLighting(); + Drawing.drawTexturedRect(Client.CLIENT, getTexture(te), 16, 16, 0, 0, 0, 0, 16, 16); + GlState.enableLighting(); + + GlState.color(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } +} diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java b/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java index 88572fc5..a3ecbcf4 100755 --- a/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java +++ b/client/src/main/java/client/renderer/tileentity/TileEntityRendererDispatcher.java @@ -11,6 +11,7 @@ import common.entity.Entity; import common.tileentity.TileEntity; import common.tileentity.TileEntityBanner; import common.tileentity.TileEntityChest; +import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntityPiston; import common.tileentity.TileEntitySign; import common.util.BlockPos; @@ -46,6 +47,7 @@ public class TileEntityRendererDispatcher private TileEntityRendererDispatcher() { this.mapSpecialRenderers.put(TileEntitySign.class, new TileEntitySignRenderer()); + this.mapSpecialRenderers.put(TileEntityDisplay.class, new TileEntityDisplayRenderer()); this.mapSpecialRenderers.put(TileEntityPiston.class, new TileEntityPistonRenderer()); this.mapSpecialRenderers.put(TileEntityChest.class, new TileEntityChestRenderer()); this.mapSpecialRenderers.put(TileEntityBanner.class, new TileEntityBannerRenderer()); diff --git a/common/src/main/java/common/block/BlockContainer.java b/common/src/main/java/common/block/BlockContainer.java index 561a8a8c..85278c69 100755 --- a/common/src/main/java/common/block/BlockContainer.java +++ b/common/src/main/java/common/block/BlockContainer.java @@ -13,7 +13,7 @@ public abstract class BlockContainer extends Block implements ITileEntityProvide this.hasTile = true; } - protected boolean isInvalidNeighbor(World world, BlockPos pos, Facing face) { + private boolean isInvalidNeighbor(World world, BlockPos pos, Facing face) { return world.getState(pos.offset(face)).getBlock().getMaterial() == Material.BLOCKING; } diff --git a/common/src/main/java/common/block/tech/BlockDisplay.java b/common/src/main/java/common/block/tech/BlockDisplay.java new file mode 100644 index 00000000..f1762f7c --- /dev/null +++ b/common/src/main/java/common/block/tech/BlockDisplay.java @@ -0,0 +1,153 @@ +package common.block.tech; + +import common.block.BlockContainer; +import common.block.Material; +import common.block.Rotatable; +import common.entity.npc.EntityNPC; +import common.entity.types.EntityLiving; +import common.item.CheatTab; +import common.model.Model; +import common.model.ModelProvider; +import common.model.ModelRotation; +import common.properties.Property; +import common.tileentity.TileEntity; +import common.tileentity.TileEntityDisplay; +import common.util.BlockPos; +import common.util.BoundingBox; +import common.util.Facing; +import common.world.IWorldAccess; +import common.world.State; +import common.world.World; + +public class BlockDisplay extends BlockContainer implements Rotatable +{ + public BlockDisplay() + { + super(Material.SOLID); + float f = 0.25F; + float f1 = 1.0F; + this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f); + this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH)); + this.setTab(CheatTab.TECHNOLOGY); + } + + public void setBlockBoundsBasedOnState(IWorldAccess worldIn, BlockPos pos) + { + State iblockstate = worldIn.getState(pos); + + if (iblockstate.getBlock() == this) + { + float f = 0.0625F; + + switch (iblockstate.getValue(FACING)) + { + case NORTH: + this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); + break; + + case SOUTH: + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); + break; + + case WEST: + this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + break; + + case EAST: + default: + this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); + } + } + } + + protected Property[] getProperties() + { + return new Property[] {FACING}; + } + + public BoundingBox getCollisionBoundingBox(World worldIn, BlockPos pos, State state) + { + this.setBlockBoundsBasedOnState(worldIn, pos); + return super.getCollisionBoundingBox(worldIn, pos, state); + } + + public BoundingBox getSelectedBoundingBox(World worldIn, BlockPos pos) + { + this.setBlockBoundsBasedOnState(worldIn, pos); + return super.getSelectedBoundingBox(worldIn, pos); + } + + public boolean isFullCube() + { + return false; + } + + /** + * Used to determine ambient occlusion and culling when rebuilding chunks for render + */ + public boolean isOpaqueCube() + { + return false; + } + + /** + * Return true if an entity can be spawned inside the block (used to get the player's bed spawn location) + */ + public boolean canSpawnInBlock() + { + return true; + } + + /** + * Returns a new instance of a block's tile entity class. Called on placing the block. + */ + public TileEntity createNewTileEntity(World worldIn) + { + return new TileEntityDisplay(); + } + + public boolean isXrayVisible() + { + return true; + } + + public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, EntityLiving placer) { + return this.getState().withProperty(FACING, facing.getAxis().isVertical() ? placer.getHorizontalFacing() : facing); + } + + public int getRenderType() { + return 3; + } + + public boolean shouldSideBeRendered(IWorldAccess worldIn, BlockPos pos, Facing side) + { + return true; + } + +// +// public Transforms getTransform() { +// return Transforms.LAYER; +// } + + public Model getModel(ModelProvider provider, String name, State state) { + return provider.getModel("iron_block").add(0, 0, 15, 16, 16, 16).n().noCull().s().du().we().rotate(ModelRotation.getNorthRot(state.getValue(FACING))); + } + + public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) + { + if (!worldIn.client) + { + TileEntity tileentity = worldIn.getTileEntity(pos); + + if (tileentity instanceof TileEntityDisplay display) + { + display.setPixel(1, 12, 0xff0000); + display.setPixel(2, 12, 0x00ff00); + display.setPixel(3, 12, 0x0000ff); + display.markDirty(); + worldIn.markBlockForUpdate(pos); + } + } + return true; + } +} diff --git a/common/src/main/java/common/entity/item/EntityFireworks.java b/common/src/main/java/common/entity/item/EntityFireworks.java index a04b6d7d..06c7ed74 100755 --- a/common/src/main/java/common/entity/item/EntityFireworks.java +++ b/common/src/main/java/common/entity/item/EntityFireworks.java @@ -8,6 +8,7 @@ import common.model.ParticleType; import common.tags.TagObject; import common.util.ExtMath; import common.world.AWorldClient; +import common.world.AWorldServer; import common.world.World; public class EntityFireworks extends Entity @@ -143,6 +144,7 @@ public class EntityFireworks extends Entity { this.worldObj.setEntityState(this, (byte)17); this.setDead(); + this.worldObj.newExplosion(this, this.posX, this.posY, this.posZ, 3.0f, false, false, false); } } diff --git a/common/src/main/java/common/entity/npc/EntityArachnoid.java b/common/src/main/java/common/entity/npc/EntityArachnoid.java index 990e649d..6fa85445 100755 --- a/common/src/main/java/common/entity/npc/EntityArachnoid.java +++ b/common/src/main/java/common/entity/npc/EntityArachnoid.java @@ -12,260 +12,150 @@ import common.rng.Random; import common.util.BlockPos; import common.world.World; -public class EntityArachnoid extends EntityNPC -{ - public EntityArachnoid(World worldIn) - { - super(worldIn); -// this.setSize(1.4F, 1.6F); - this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); -// this.tasks.addTask(4, new AISpiderAttack(this, EntityNPC.class)); - this.tasks.addTask(4, new AISpiderAttack(this, EntityNPC.class)); -// this.targets.addTask(2, new EntitySpider.AISpiderTarget(this, EntityNPC.class)); -// this.targets.addTask(3, new EntitySpider.AISpiderTarget(this, EntityNPC.class)); - } - -// public double getMountedYOffset() -// { -// return (double)(this.height * 0.5F); -// } - -// public float getRenderScale() -// { -// return 0.9375f * this.height / 1.6f; -// } - - protected PathNavigate getNewNavigator(World worldIn) - { - return new PathNavigateClimber(this, worldIn); - } +public class EntityArachnoid extends EntityNPC { + static class AISpiderAttack extends EntityAIAttackOnCollide { + public AISpiderAttack(EntityArachnoid spider, Class targetClass) { + super(spider, targetClass, 1.0D, true); + } - protected void entityInit() - { - super.entityInit(); - this.dataWatcher.addObject(23, (byte)0); - } - - public void onUpdate() - { - super.onUpdate(); + public boolean continueExecuting() { + float f = this.attacker.getBrightness(1.0F); - if (!this.worldObj.client) - { - this.setBesideClimbableBlock(this.collidedHorizontally); - } - } + if(f >= 0.5F && this.attacker.getRNG().chance(100)) { + this.attacker.setAttackTarget((EntityLiving)null); + return false; + } + else { + return super.continueExecuting(); + } + } -// protected void applyEntityAttributes() -// { -// super.applyEntityAttributes(); -// this.getEntityAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896D); -// } - -// protected String getLivingSound() -// { -// return "mob.spider.say"; -// } - - public boolean isOnLadder() - { - return super.isOnLadder() || (this.client != null ? this.collidedHorizontally && !this.noclip : this.isBesideClimbableBlock()); - } - - public void setInWeb() - { - } - - public boolean isBesideClimbableBlock() - { - return (!this.isPlayer() || !this.noclip) && this.dataWatcher.getWatchableObjectByte(23) != 0; - } - - public void setBesideClimbableBlock(boolean climb) - { - this.dataWatcher.updateObject(23, (byte)(climb ? 1 : 0)); - } - - public Object onInitialSpawn(Object livingdata) - { - livingdata = super.onInitialSpawn(livingdata); -// if(!this.isChild()) { -// if (this.worldObj.rand.chance(100)) -// { -// EntityUndead entityskeleton = new EntityUndead(this.worldObj); -// entityskeleton.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotYaw, 0.0F); -// entityskeleton.onInitialSpawn(difficulty, (IEntityLivingData)null); -// this.worldObj.spawnEntityInWorld(entityskeleton); -// entityskeleton.mountEntity(this); -// } - - if (livingdata == null && !this.isPlayer()) - { - livingdata = new EntityArachnoid.GroupData(this.worldObj.rand.chance(40)); + protected double getAttackRange(EntityLiving attackTarget) { + return (double)(4.0F + attackTarget.width); + } + } - if (/* this.worldObj.getDifficulty() == Difficulty.HARD && */ this.worldObj.rand.chance()) - { - ((EntityArachnoid.GroupData)livingdata).pickEffect(this.worldObj.rand); - } - } + public static class GroupData { + public Potion potionEffectId; + public boolean isChild; - if (livingdata instanceof EntityArachnoid.GroupData) - { - Potion i = ((EntityArachnoid.GroupData)livingdata).potionEffectId; + public GroupData(boolean isChild) { + this.isChild = isChild; + } - if (i != null) - { - this.addEffect(new PotionEffect(i, Integer.MAX_VALUE, 0)); - } - - if(((EntityArachnoid.GroupData)livingdata).isChild) - this.setGrowingAge(-24000); - } -// } - return livingdata; - } + public void pickEffect(Random rand) { + this.potionEffectId = rand.pick(Potion.SPEED, Potion.SPEED, Potion.STRENGTH, Potion.REGENERATION); + } + } + + public EntityArachnoid(World worldIn) { + super(worldIn); + this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); + this.tasks.addTask(4, new AISpiderAttack(this, EntityNPC.class)); + } + + protected PathNavigate getNewNavigator(World worldIn) { + return new PathNavigateClimber(this, worldIn); + } + + protected void entityInit() { + super.entityInit(); + this.dataWatcher.addObject(23, (byte)0); + } + + public void onUpdate() { + super.onUpdate(); + + if(!this.worldObj.client) { + this.setBesideClimbableBlock(this.collidedHorizontally); + } + } + + public boolean isOnLadder() { + return super.isOnLadder() || (this.client != null ? this.collidedHorizontally && !this.noclip : this.isBesideClimbableBlock()); + } + + public void setInWeb() { + } + + public boolean isBesideClimbableBlock() { + return (!this.isPlayer() || !this.noclip) && this.dataWatcher.getWatchableObjectByte(23) != 0; + } + + public void setBesideClimbableBlock(boolean climb) { + this.dataWatcher.updateObject(23, (byte)(climb ? 1 : 0)); + } + + public Object onInitialSpawn(Object livingdata) { + livingdata = super.onInitialSpawn(livingdata); + + if(livingdata == null && !this.isPlayer()) { + livingdata = new EntityArachnoid.GroupData(this.worldObj.rand.chance(40)); + + if(this.worldObj.rand.chance()) { + ((EntityArachnoid.GroupData)livingdata).pickEffect(this.worldObj.rand); + } + } + + if(livingdata instanceof EntityArachnoid.GroupData) { + Potion i = ((EntityArachnoid.GroupData)livingdata).potionEffectId; + + if(i != null) { + this.addEffect(new PotionEffect(i, Integer.MAX_VALUE, 0)); + } + + if(((EntityArachnoid.GroupData)livingdata).isChild) + this.setGrowingAge(-24000); + } + return livingdata; + } + + public boolean isSneakingVisually() { + return false; + } -// public float getEyeHeight() -// { -// return super.getEyeHeight() * 0.85f; -// } - - public boolean isSneakingVisually() { - return false; - } - public int getColor() { return 0xc63ba0; } - static class AISpiderAttack extends EntityAIAttackOnCollide - { - public AISpiderAttack(EntityArachnoid spider, Class targetClass) - { - super(spider, targetClass, 1.0D, true); - } - - public boolean continueExecuting() - { - float f = this.attacker.getBrightness(1.0F); - - if (f >= 0.5F && this.attacker.getRNG().chance(100)) - { - this.attacker.setAttackTarget((EntityLiving)null); - return false; - } - else - { - return super.continueExecuting(); - } - } - - protected double getAttackRange(EntityLiving attackTarget) - { - return (double)(4.0F + attackTarget.width); - } - } - -// static class AISpiderTarget extends EntityAINearestAttackableTarget -// { -// public AISpiderTarget(EntitySpider spider, Class classTarget) -// { -// super(spider, classTarget, true); -// } -// -// public boolean shouldExecute() -// { -// float f = this.taskOwner.getBrightness(1.0F); -// return f >= 0.5F ? false : super.shouldExecute(); -// } -// } - -// public boolean isAggressive() { -// return this.getBrightness(1.0f) < 0.5f; -// } -// -// public boolean isPeaceful() { -// return false; -// } - -// public boolean isAggressive(Class clazz) { -// return false; -// } -// -// public boolean isPeaceful(Class clazz) { -// return false; -// } - -// public boolean canInfight(Alignment align) { -// return true; -// } -// -// public boolean canMurder(Alignment align) { -// return false; -// } - -// public boolean canUseMagic() { -// return false; -// } - public int getBaseHealth(Random rand) { return rand.range(16, 24); } -// public int getBaseEnergy(Random rand) { -// return 0; -// } - -// public float getHeightDeviation(Random rand) { -// return rand.frange(0.0f, 0.25f); -// } - - public float getHeightDeviationMax() { - return 0.25f; - } + public float getHeightDeviationMax() { + return 0.25f; + } public Alignment getNaturalAlign() { return rand.pick(Alignment.LAWFUL_EVIL, Alignment.EVIL, Alignment.LAWFUL, Alignment.NEUTRAL); } - public boolean attackEntityAsMob(Entity entityIn) - { - if(super.attackEntityAsMob(entityIn)) { - if(entityIn instanceof EntityLiving && this.rand.chance(50)) - ((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.POISON, this.rand.range(14, 35) * 20, 0)); - return true; - } - return false; - } + public boolean attackEntityAsMob(Entity entityIn) { + if(super.attackEntityAsMob(entityIn)) { + if(this.isPoisonous() && entityIn instanceof EntityLiving && this.rand.chance(50)) + ((EntityLiving)entityIn).addEffect(new PotionEffect(Potion.POISON, this.rand.range(14, 35) * 20, 0)); + return true; + } + return false; + } + + public boolean isPoisonous() { + return true; + } public boolean getCanSpawnHere() { return this.worldObj.getLightFromNeighbors(new BlockPos(this)) <= this.rand.zrange(8); } - - public boolean canAmbush(EntityLiving entity) { - return (float)this.getHealth() >= ((float)this.getMaxHealth() / 4.0f); - } - - public boolean canUseMagic() { - return true; - } - - public float getSpeciesBaseSize() { - return 1.6f; - } - public static class GroupData - { - public Potion potionEffectId; - public boolean isChild; - - public GroupData(boolean isChild) { - this.isChild = isChild; - } + public boolean canAmbush(EntityLiving entity) { + return (float)this.getHealth() >= ((float)this.getMaxHealth() / 4.0f); + } - public void pickEffect(Random rand) - { - this.potionEffectId = rand.pick(Potion.SPEED, Potion.SPEED, Potion.STRENGTH, Potion.REGENERATION); - } - } + public boolean canUseMagic() { + return true; + } + + public float getSpeciesBaseSize() { + return 1.6f; + } } diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 124ca8b7..9e790347 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -4314,11 +4314,11 @@ public abstract class EntityNPC extends EntityLiving } public Object onInitialSpawn(Object livingdata) { -// if(this.isPlayer()) { -// this.setCustomNameTag(this.pickRandomName(this.rand, null)); -// return livingdata; -// } - livingdata = super.onInitialSpawn(livingdata); + return this.initializeBase(livingdata); + } + + protected Object initializeBase(Object livingdata) { + livingdata = super.onInitialSpawn(livingdata); CharacterInfo info = (livingdata instanceof CharacterTypeData) ? ((CharacterTypeData)livingdata).character : this.species.pickCharacter(this.worldObj.rand); AlignmentData align = livingdata instanceof AlignmentData ? ((AlignmentData)livingdata) : null; diff --git a/common/src/main/java/common/entity/npc/EntityTinyArachnoid.java b/common/src/main/java/common/entity/npc/EntityTinyArachnoid.java new file mode 100644 index 00000000..415f34da --- /dev/null +++ b/common/src/main/java/common/entity/npc/EntityTinyArachnoid.java @@ -0,0 +1,52 @@ +package common.entity.npc; + +import common.entity.types.EntityLiving; +import common.rng.Random; +import common.world.World; + +public class EntityTinyArachnoid extends EntityArachnoid { + public EntityTinyArachnoid(World worldIn) { + super(worldIn); + } + + protected void applyEntityAttributes() { + super.applyEntityAttributes(); + this.setAttackDamageBase(1); + } + + public Object onInitialSpawn(Object livingdata) { + return this.initializeBase(livingdata); + } + + public int getBaseHealth(Random rand) { + return rand.range(1, 3); + } + + public float getHeightDeviationMax() { + return 0.05f; + } + + public Alignment getNaturalAlign() { + return rand.pick(Alignment.LAWFUL_EVIL, Alignment.LAWFUL, Alignment.NEUTRAL); + } + + public boolean getCanSpawnHere() { + return true; + } + + public boolean canAmbush(EntityLiving entity) { + return true; + } + + public boolean canUseMagic() { + return false; + } + + public float getSpeciesBaseSize() { + return 0.25f; + } + + public boolean isPoisonous() { + return false; + } +} diff --git a/common/src/main/java/common/init/BlockRegistry.java b/common/src/main/java/common/init/BlockRegistry.java index 087bfd21..250b7d19 100755 --- a/common/src/main/java/common/init/BlockRegistry.java +++ b/common/src/main/java/common/init/BlockRegistry.java @@ -101,6 +101,7 @@ import common.block.tech.BlockChest; import common.block.tech.BlockCore; import common.block.tech.BlockDaylightDetector; import common.block.tech.BlockDispenser; +import common.block.tech.BlockDisplay; import common.block.tech.BlockDropper; import common.block.tech.BlockEnchantmentTable; import common.block.tech.BlockFurnace; @@ -461,6 +462,7 @@ public abstract class BlockRegistry { .setTab(CheatTab.DECORATION)); register("sign", (new BlockStandingSign()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Schild")); register("wall_sign", (new BlockWallSign()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Schild")); + register("display", (new BlockDisplay()).setHardness(1.0F).setStepSound(SoundType.STONE).setDisplay("Anzeige")); register("banner", (new BlockBannerStanding()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Banner")); register("wall_banner", (new BlockBannerHanging()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Banner")); diff --git a/common/src/main/java/common/init/Blocks.java b/common/src/main/java/common/init/Blocks.java index 4bb1296b..36b37255 100755 --- a/common/src/main/java/common/init/Blocks.java +++ b/common/src/main/java/common/init/Blocks.java @@ -591,6 +591,7 @@ public abstract class Blocks { public static final BlockStairs floor_tiles_white_stairs = get("floor_tiles_white_stairs"); public static final BlockSlab pentagram_slab = get("pentagram_slab"); public static final BlockStairs pentagram_stairs = get("pentagram_stairs"); + public static final BlockDisplay display = get("display"); private static T get(String id) { T block = (T)BlockRegistry.byNameExact(id); diff --git a/common/src/main/java/common/init/ItemRegistry.java b/common/src/main/java/common/init/ItemRegistry.java index c247e8a3..536c4fa0 100755 --- a/common/src/main/java/common/init/ItemRegistry.java +++ b/common/src/main/java/common/init/ItemRegistry.java @@ -216,7 +216,7 @@ public abstract class ItemRegistry { register("camera", (new ItemCamera()).setDisplay("Kamera").setTab(CheatTab.TOOLS)); for(Weather weather : Weather.values()) { - register("weather_token_" + weather.getName(), new ItemWeatherToken(weather).setDisplay("Wetterkristall").setTab(CheatTab.TOOLS)); + register("weather_token_" + weather.getName(), new ItemWeatherToken(weather).setDisplay("Wetterkristall").setTab(CheatTab.MAGIC)); } register("flint_and_steel", (new ItemFlintAndSteel(Blocks.fire)).setDisplay("Feuerzeug")); @@ -279,7 +279,7 @@ public abstract class ItemRegistry { register("chicken", (new ItemFood(2, true)).setDisplay("Rohes Hühnchen")); register("cooked_chicken", (new ItemFood(6, true)).setDisplay("Gebratenes Hühnchen")); register("rotten_flesh", (new ItemFood(4, true)).setDisplay("Verrottetes Fleisch")); - register("orb", (new ItemFragile()).setDisplay("Kugel").setTab(CheatTab.TOOLS)); + register("orb", (new ItemFragile()).setDisplay("Kugel").setTab(CheatTab.MAGIC)); register("blaze_rod", (new ItemRod()).setDisplay("Lohenrute").setTab(CheatTab.MATERIALS).setMaxAmount(256)); register("tear", (new ItemTiny()).setDisplay("Träne").setPotionEffect(PotionHelper.tearEffect).setTab(CheatTab.MATERIALS).setMaxAmount(256)); register("gold_nugget", (new ItemNugget()).setDisplay("Goldnugget").setTab(CheatTab.METALS).setMaxAmount(256)); @@ -311,9 +311,9 @@ public abstract class ItemRegistry { register("carrot_on_a_stick", (new ItemCarrotOnAStick()).setDisplay("Karottenrute")); register("charge_crystal", (new ItemEffect()).setDisplay("Energiekristall").setTab(CheatTab.MISC).setColor(TextColor.DMAGENTA)); register("pumpkin_pie", (new ItemFood(8, false)).setDisplay("Kürbiskuchen").setTab(CheatTab.FOOD)); - register("fireworks", (new ItemFirework()).setDisplay("Feuerwerksrakete").setTab(CheatTab.TOOLS)); + register("fireworks", (new ItemFirework()).setDisplay("Feuerwerksrakete").setTab(CheatTab.EXPLOSIVES)); register("firework_charge", (new ItemFireworkCharge()).setDisplay("Feuerwerksstern").setTab(CheatTab.MATERIALS)); - register("enchanted_book", (new ItemEnchantedBook()).setMaxAmount(1).setDisplay("Verzaubertes Buch").setTab(CheatTab.MAGIC)); + register("enchanted_book", (new ItemEnchantedBook()).setMaxAmount(1).setDisplay("Verzaubertes Buch").setTab(CheatTab.ENCHANTMENTS)); register("bloodbrick", (new Item()).setDisplay("Blutroter Ziegel").setTab(CheatTab.MATERIALS)); register("blackbrick", (new Item()).setDisplay("Schwarzer Ziegel").setTab(CheatTab.MATERIALS)); Item quartz = (new Item()).setDisplay("Quarz").setTab(CheatTab.METALS); diff --git a/common/src/main/java/common/init/Items.java b/common/src/main/java/common/init/Items.java index eb9259f6..4f3f0b8d 100755 --- a/common/src/main/java/common/init/Items.java +++ b/common/src/main/java/common/init/Items.java @@ -972,6 +972,7 @@ public abstract class Items { public static final ItemBlock floor_tiles_white_stairs = get("floor_tiles_white_stairs"); public static final ItemSlab pentagram_slab = get("pentagram_slab"); public static final ItemBlock pentagram_stairs = get("pentagram_stairs"); + public static final ItemBlock display = get("display"); private static T get(String id) { T item = (T)ItemRegistry.byName(id); diff --git a/common/src/main/java/common/init/SpeciesRegistry.java b/common/src/main/java/common/init/SpeciesRegistry.java index 91261718..a5f60768 100755 --- a/common/src/main/java/common/init/SpeciesRegistry.java +++ b/common/src/main/java/common/init/SpeciesRegistry.java @@ -30,6 +30,7 @@ import common.entity.npc.EntitySlime; import common.entity.npc.EntitySpaceMarine; import common.entity.npc.EntitySpirit; import common.entity.npc.EntityTiefling; +import common.entity.npc.EntityTinyArachnoid; import common.entity.npc.EntityUndead; import common.entity.npc.EntityVampire; import common.entity.npc.EntityWoodElf; @@ -117,6 +118,7 @@ public abstract class SpeciesRegistry { registerSpecies("Undead", EntityUndead.class, "terra", "Untoter", 0xc1c1c1, 0x494949, ":undead_1", ":undead_2", ":undead_3", ":undead_4"); registerSpecies("Arachnoid", EntityArachnoid.class, "tbd", "Arachnoidea", ModelType.ARACHNOID, 0x342d27, 0xa80e0e); + registerSpecies("TinyArachnoid", EntityTinyArachnoid.class, "tbd", "Kleiner Arachnoidea", ModelType.ARACHNOID, 0x142d27, 0x780e0e); registerSpecies("Mage", EntityMage.class, "terra", "Magier", 0x340000, 0x51a03e, ":mage_1", ":mage_2", ":mage_3", ":mage_4", ":mage_5", ":mage_6"); registerSpecies("Gargoyle", EntityGargoyle.class, "tbd", "Gargoyle", 0x401010, 0x534437); diff --git a/common/src/main/java/common/init/TileRegistry.java b/common/src/main/java/common/init/TileRegistry.java index 4ebcac45..6d9921aa 100755 --- a/common/src/main/java/common/init/TileRegistry.java +++ b/common/src/main/java/common/init/TileRegistry.java @@ -11,6 +11,7 @@ import common.tileentity.TileEntityChest; import common.tileentity.TileEntityComparator; import common.tileentity.TileEntityDaylightDetector; import common.tileentity.TileEntityDispenser; +import common.tileentity.TileEntityDisplay; import common.tileentity.TileEntityDropper; import common.tileentity.TileEntityEnchantmentTable; import common.tileentity.TileEntityFurnace; @@ -41,6 +42,7 @@ public abstract class TileRegistry { addMapping(TileEntityDispenser.class, "Trap"); addMapping(TileEntityDropper.class, "Dropper"); addMapping(TileEntitySign.class, "Sign"); + addMapping(TileEntityDisplay.class, "Display"); addMapping(TileEntityPiston.class, "Piston"); addMapping(TileEntityBrewingStand.class, "Cauldron"); addMapping(TileEntityEnchantmentTable.class, "EnchantTable"); diff --git a/common/src/main/java/common/item/CheatTab.java b/common/src/main/java/common/item/CheatTab.java index 1bc3f2f7..1943e142 100755 --- a/common/src/main/java/common/item/CheatTab.java +++ b/common/src/main/java/common/item/CheatTab.java @@ -97,11 +97,21 @@ public enum CheatTab { return Items.potion; } }, - MAGIC("Verzauberungen", false) { + ENCHANTMENTS("Verzauberungen", false) { protected Item getIconItem() { return Items.enchanted_book; } }, + MAGIC("Magie", false) { + protected Item getIconItem() { + return Items.charged_orb; + } + }, + EXPLOSIVES("Sprengstoff", false) { + protected Item getIconItem() { + return Items.dynamite; + } + }, MATERIALS("Werkstoffe", false) { protected Item getIconItem() { return Items.leather; diff --git a/common/src/main/java/common/item/spawner/ItemMinecart.java b/common/src/main/java/common/item/spawner/ItemMinecart.java index 593a6fde..5c14cacf 100755 --- a/common/src/main/java/common/item/spawner/ItemMinecart.java +++ b/common/src/main/java/common/item/spawner/ItemMinecart.java @@ -2,6 +2,7 @@ package common.item.spawner; import common.block.tech.BlockRailBase; import common.entity.item.EntityCart; +import common.entity.item.EntityCart.EnumMinecartType; import common.entity.npc.EntityNPC; import common.init.Blocks; import common.item.CheatTab; @@ -22,7 +23,7 @@ public class ItemMinecart extends Item { this.setMaxAmount(1); this.minecartType = type; - this.setTab(CheatTab.VEHICLES); + this.setTab(type == EnumMinecartType.TNT ? CheatTab.EXPLOSIVES : CheatTab.VEHICLES); // if(type != EntityMinecart.EnumMinecartType.COMMAND_BLOCK) } diff --git a/common/src/main/java/common/item/tool/ItemChargedOrb.java b/common/src/main/java/common/item/tool/ItemChargedOrb.java index cb2a1dc4..158e6d6c 100755 --- a/common/src/main/java/common/item/tool/ItemChargedOrb.java +++ b/common/src/main/java/common/item/tool/ItemChargedOrb.java @@ -20,7 +20,7 @@ public class ItemChargedOrb extends ItemFragile { public ItemChargedOrb() { - this.setTab(CheatTab.TOOLS); + this.setTab(CheatTab.MAGIC); this.setMaxDamage(16); this.setColor(TextColor.DMAGENTA); } diff --git a/common/src/main/java/common/item/tool/ItemDynamite.java b/common/src/main/java/common/item/tool/ItemDynamite.java index a1b03e88..5d06b90d 100755 --- a/common/src/main/java/common/item/tool/ItemDynamite.java +++ b/common/src/main/java/common/item/tool/ItemDynamite.java @@ -25,7 +25,7 @@ public class ItemDynamite extends Item { public ItemDynamite(int power) { this.power = power; this.setMaxAmount(32); - this.setTab(CheatTab.TOOLS); + this.setTab(CheatTab.EXPLOSIVES); DYNAMITE[power] = this; } diff --git a/common/src/main/java/common/item/tool/ItemExpBottle.java b/common/src/main/java/common/item/tool/ItemExpBottle.java index 4c6e3e15..7023df2b 100755 --- a/common/src/main/java/common/item/tool/ItemExpBottle.java +++ b/common/src/main/java/common/item/tool/ItemExpBottle.java @@ -16,7 +16,7 @@ public class ItemExpBottle extends Item { public ItemExpBottle() { - this.setTab(CheatTab.TOOLS); + this.setTab(CheatTab.MAGIC); } public boolean hasEffect(ItemStack stack) diff --git a/common/src/main/java/common/network/IClientPlayer.java b/common/src/main/java/common/network/IClientPlayer.java index da6a2bcd..b6e8f199 100644 --- a/common/src/main/java/common/network/IClientPlayer.java +++ b/common/src/main/java/common/network/IClientPlayer.java @@ -61,6 +61,7 @@ import common.packet.SPacketSpawnObject; import common.packet.SPacketSpawnPlayer; import common.packet.SPacketTimeUpdate; import common.packet.SPacketTrades; +import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateHealth; import common.packet.SPacketWorld; import common.sound.Sound; @@ -115,6 +116,7 @@ public interface IClientPlayer extends NetHandler { void handleWindowItems(SPacketWindowItems packet); void handleSignEditorOpen(SPacketSignEditorOpen packet); void handleUpdateSign(SPacketUpdateSign packet); + void handleUpdateDisplay(SPacketUpdateDisplay packet); void handleUpdateTileEntity(SPacketUpdateTileEntity packet); void handleWindowProperty(SPacketWindowProperty packet); void handleEntityEquipment(SPacketEntityEquipment packet); diff --git a/common/src/main/java/common/network/PacketRegistry.java b/common/src/main/java/common/network/PacketRegistry.java index 74677198..42d524fb 100755 --- a/common/src/main/java/common/network/PacketRegistry.java +++ b/common/src/main/java/common/network/PacketRegistry.java @@ -97,6 +97,7 @@ import common.packet.SPacketSpawnObject; import common.packet.SPacketSpawnPlayer; import common.packet.SPacketTimeUpdate; import common.packet.SPacketTrades; +import common.packet.SPacketUpdateDisplay; import common.packet.SPacketUpdateHealth; import common.packet.SPacketWorld; @@ -167,6 +168,7 @@ public enum PacketRegistry { this.server(SPacketWindowProperty.class); this.server(SPacketConfirmTransaction.class); this.server(SPacketUpdateSign.class); + this.server(SPacketUpdateDisplay.class); this.server(SPacketUpdateTileEntity.class); this.server(SPacketSignEditorOpen.class); this.server(SPacketPlayerListItem.class); diff --git a/common/src/main/java/common/packet/SPacketUpdateDisplay.java b/common/src/main/java/common/packet/SPacketUpdateDisplay.java new file mode 100644 index 00000000..98107bfe --- /dev/null +++ b/common/src/main/java/common/packet/SPacketUpdateDisplay.java @@ -0,0 +1,52 @@ +package common.packet; + +import java.io.IOException; + +import common.network.IClientPlayer; +import common.network.Packet; +import common.network.PacketBuffer; +import common.util.BlockPos; + +public class SPacketUpdateDisplay implements Packet { + private BlockPos position; + private int[] pixels; + + public SPacketUpdateDisplay() { + } + + public SPacketUpdateDisplay(BlockPos pos, int[] pixels) { + this.position = pos; + this.pixels = pixels; + } + + public void readPacketData(PacketBuffer buf) throws IOException { + this.position = buf.readBlockPos(); + this.pixels = new int[256]; + + for(int i = 0; i < 256; ++i) { + this.pixels[i] = 0xff000000 | buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte(); + } + } + + public void writePacketData(PacketBuffer buf) throws IOException { + buf.writeBlockPos(this.position); + + for(int i = 0; i < 256; ++i) { + buf.writeByte((this.pixels[i] >> 16) & 255); + buf.writeByte((this.pixels[i] >> 8) & 255); + buf.writeByte(this.pixels[i] & 255); + } + } + + public void processPacket(IClientPlayer handler) { + handler.handleUpdateDisplay(this); + } + + public BlockPos getPos() { + return this.position; + } + + public int[] getPixels() { + return this.pixels; + } +} diff --git a/common/src/main/java/common/packet/SPacketUpdateSign.java b/common/src/main/java/common/packet/SPacketUpdateSign.java index 25a586b0..4553d0b6 100755 --- a/common/src/main/java/common/packet/SPacketUpdateSign.java +++ b/common/src/main/java/common/packet/SPacketUpdateSign.java @@ -6,25 +6,20 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; import common.util.BlockPos; -import common.world.World; public class SPacketUpdateSign implements Packet { - private World world; private BlockPos blockPos; private String[] lines; -// private String command; public SPacketUpdateSign() { } - public SPacketUpdateSign(World worldIn, BlockPos blockPosIn, String[] linesIn) + public SPacketUpdateSign(BlockPos blockPosIn, String[] linesIn) { - this.world = worldIn; this.blockPos = blockPosIn; this.lines = new String[] {linesIn[0], linesIn[1], linesIn[2], linesIn[3]}; -// this.command = commandIn != null && commandIn.isEmpty() ? null : commandIn; } /** @@ -39,9 +34,6 @@ public class SPacketUpdateSign implements Packet { this.lines[i] = buf.readString(64); } - -// this.command = buf.readStringFromBuffer(1024); -// this.command = this.command.isEmpty() ? null : this.command; } /** @@ -55,8 +47,6 @@ public class SPacketUpdateSign implements Packet { buf.writeString(this.lines[i]); } - -// buf.writeString(this.command == null ? "" : this.command); } /** @@ -76,9 +66,4 @@ public class SPacketUpdateSign implements Packet { return this.lines; } - -// public String getCommand() -// { -// return this.command; -// } } diff --git a/common/src/main/java/common/tileentity/TileEntityDisplay.java b/common/src/main/java/common/tileentity/TileEntityDisplay.java new file mode 100644 index 00000000..11469a6a --- /dev/null +++ b/common/src/main/java/common/tileentity/TileEntityDisplay.java @@ -0,0 +1,40 @@ +package common.tileentity; + +import java.util.Arrays; + +import common.network.Packet; +import common.packet.SPacketUpdateDisplay; +import common.tags.TagObject; + +public class TileEntityDisplay extends TileEntity { + public int[] data = new int[256]; + public long lastUpdated; + + public TileEntityDisplay() { + Arrays.fill(this.data, 0xff000000); + } + + public void writeTags(TagObject compound) { + super.writeTags(compound); + compound.setIntArray("Pixels", this.data); + } + + public void readTags(TagObject compound) { + super.readTags(compound); + this.data = compound.getIntArray("Pixels"); + if(this.data.length != 256) + this.data = new int[256]; + } + + public Packet getDescriptionPacket() { + return new SPacketUpdateDisplay(this.pos, this.data); + } + + public int getColor() { + return 0x00ff00; + } + + public void setPixel(int x, int y, int color) { + this.data[x + y * 16] = color | 0xff000000; + } +} diff --git a/common/src/main/java/common/tileentity/TileEntitySign.java b/common/src/main/java/common/tileentity/TileEntitySign.java index f26c94b1..59db6be8 100755 --- a/common/src/main/java/common/tileentity/TileEntitySign.java +++ b/common/src/main/java/common/tileentity/TileEntitySign.java @@ -30,7 +30,7 @@ public class TileEntitySign extends TileEntity { String[] aichatcomponent = new String[4]; System.arraycopy(this.signText, 0, aichatcomponent, 0, 4); // Sign sign = Server.getServer().getSigns().getEntry(new WorldPos(this).toString()); - return new SPacketUpdateSign(this.worldObj, this.pos, aichatcomponent); + return new SPacketUpdateSign(this.pos, aichatcomponent); } public void setPlayer(EntityNPC playerIn) { diff --git a/server/src/main/java/server/Server.java b/server/src/main/java/server/Server.java index 4fddc01a..50e4a940 100755 --- a/server/src/main/java/server/Server.java +++ b/server/src/main/java/server/Server.java @@ -858,7 +858,7 @@ public final class Server implements IThreadListener, Executor { world = world == null ? this.space : world; } EntityNPC nplayer = conn.createPlayer(world, EntityRegistry.getEntityString(old)); - conn.clonePlayer(old); + conn.copyPlayer(old); nplayer.setId(old.getId()); nplayer.setOrigin(origin); if(bed != null) { diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 669294e9..beaf78c1 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -458,7 +458,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer this.lastHealth = -1.0E8F; } - public void clonePlayer(EntityNPC oldPlayer) + public void copyPlayer(EntityNPC oldPlayer) { this.lastExperience = -1; this.lastHealth = -1.0F; @@ -473,6 +473,10 @@ public class Player extends User implements ICrafting, Executor, IPlayer this.entity.setHeight(oldPlayer.getHeight()); this.entity.setCustomNameTag(oldPlayer.getCustomNameTag()); this.entity.setAlignment(oldPlayer.getAlignment()); + this.entity.setAttackDamageBase(oldPlayer.getAttackDamageBase()); + this.entity.setSpeedBase(oldPlayer.getSpeedBase()); + this.entity.setMaxHealth(oldPlayer.getMaxHealth()); + this.entity.setMaxMana(oldPlayer.getMaxMana()); } public void removeEntity(Entity p_152339_1_)