From 29ef07ba8c168dd69de26bdaafb526416ed9a935 Mon Sep 17 00:00:00 2001 From: Mistadon Date: Tue, 7 Apr 2015 14:05:49 +0200 Subject: [PATCH] reimplemented coffin, started some work... --- .../de/teamlapen/vampirism/ModBlocks.java | 4 +- .../java/de/teamlapen/vampirism/ModItems.java | 2 +- .../vampirism/block/BlockCoffin.java | 2 +- .../entity/player/VampirePlayer.java | 22 ++-- .../vampirism/item/ItemVampiresFear.java | 7 +- .../vampirism/proxy/ClientProxy.java | 36 +++--- .../vampirism/proxy/ServerProxy.java | 117 +++++++++--------- .../tileEntity/TileEntityBloodAltar.java | 32 +---- .../assets/vampirism/lang/de_DE.lang | 1 + .../assets/vampirism/lang/en_US.lang | 1 + 10 files changed, 100 insertions(+), 124 deletions(-) diff --git a/src/main/java/de/teamlapen/vampirism/ModBlocks.java b/src/main/java/de/teamlapen/vampirism/ModBlocks.java index e8afc0a9a4..7d4b05b076 100644 --- a/src/main/java/de/teamlapen/vampirism/ModBlocks.java +++ b/src/main/java/de/teamlapen/vampirism/ModBlocks.java @@ -35,14 +35,14 @@ public static void init() { GameRegistry.registerBlock(bloodAltarTier4Tip, ItemBlock.class,BlockBloodAltarTier4Tip.name); GameRegistry.registerBlock(cursedEarth, BlockCursedEarth.name); GameRegistry.registerBlock(churchAltar, BlockChurchAltar.name); - //GameRegistry.registerBlock(coffin, BlockCoffin.name); + GameRegistry.registerBlock(coffin, BlockCoffin.name); GameRegistry.registerTileEntity(TileEntityBloodAltar.class, "TileEntityBloodAltar"); GameRegistry.registerTileEntity(TileEntityBloodAltarTier2.class, "TileEntityBloodAltarTier2"); //GameRegistry.registerTileEntity(TileEntityBloodAltarTier3.class, "TileEntityBloodAltarTier3"); GameRegistry.registerTileEntity(TileEntityBloodAltarTier4.class, "TileEntityBloodAltarTier4"); GameRegistry.registerTileEntity(TileEntityChurchAltar.class, "TileEntityChurchAltar"); GameRegistry.registerTileEntity(TileEntityBloodAltarTier4Tip.class, "TileEntityBloodAltarTier4Tip"); - //GameRegistry.registerTileEntity(TileEntityCoffin.class, "TileEntityCoffin"); + GameRegistry.registerTileEntity(TileEntityCoffin.class, "TileEntityCoffin"); // Flowers GameRegistry.registerBlock(vampireFlower, VampireFlower.name); diff --git a/src/main/java/de/teamlapen/vampirism/ModItems.java b/src/main/java/de/teamlapen/vampirism/ModItems.java index 12cf3bf4aa..18476fa528 100644 --- a/src/main/java/de/teamlapen/vampirism/ModItems.java +++ b/src/main/java/de/teamlapen/vampirism/ModItems.java @@ -26,7 +26,7 @@ public static void init() { GameRegistry.registerItem(humanHeart, ItemHumanHeart.name); GameRegistry.registerItem(pureBlood,ItemPureBlood.name); GameRegistry.registerItem(sunscreen, ItemSunscreen.name); - //GameRegistry.registerItem(coffin, ItemCoffin.name); + GameRegistry.registerItem(coffin, ItemCoffin.name); } public static void registerRecipes(){ diff --git a/src/main/java/de/teamlapen/vampirism/block/BlockCoffin.java b/src/main/java/de/teamlapen/vampirism/block/BlockCoffin.java index e88b174293..d384164e85 100644 --- a/src/main/java/de/teamlapen/vampirism/block/BlockCoffin.java +++ b/src/main/java/de/teamlapen/vampirism/block/BlockCoffin.java @@ -132,7 +132,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, public void setCoffinOccupied(World world, int x, int y, int z, EntityPlayer player, boolean flag) { int newMeta = world.getBlockMetadata(x, y, z); if(flag) - newMeta = newMeta & 7 + 8; + newMeta = newMeta | 8; else newMeta = newMeta & 7; world.setBlockMetadataWithNotify(x, y, z, newMeta, 3); diff --git a/src/main/java/de/teamlapen/vampirism/entity/player/VampirePlayer.java b/src/main/java/de/teamlapen/vampirism/entity/player/VampirePlayer.java index 081456ccd5..d5c2db5580 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/player/VampirePlayer.java +++ b/src/main/java/de/teamlapen/vampirism/entity/player/VampirePlayer.java @@ -806,13 +806,13 @@ protected void fillBloodIntoInventory(int amt){ */ public EntityPlayer.EnumStatus sleepInCoffinAt(int x, int y, int z) { - //TODO Understand the event stuff + //TODO Workaround for event stuff PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(this.player, x, y, z); MinecraftForge.EVENT_BUS.post(event); - if (event.result != null) { - return event.result; - } +// if (event.result != null) { +// return event.result; +// } if (!this.player.worldObj.isRemote) { @@ -894,13 +894,13 @@ public EntityPlayer.EnumStatus sleepInCoffinAt(int x, (double) ((float) z + 0.5F)); } - //Following method will replace: this.player.sleeping = true; -// Helper.Reflection.setPrivateField(EntityPlayer.class, this.player, -// true, Helper.Obfuscation.getPosNames("EntityPlayer/sleeping")); +// Following method will replace: this.player.sleeping = true; + Helper.Reflection.setPrivateField(EntityPlayer.class, this.player, + true, Helper.Obfuscation.getPosNames("EntityPlayer/sleeping")); this.sleepingCoffin = true; - //Following method will replace: this.player.sleepTimer = 0; -// Helper.Reflection.setPrivateField(EntityPlayer.class, this.player, 0, -// Helper.Obfuscation.getPosNames("EntityPlayer/sleepTimer")); +// Following method will replace: this.player.sleepTimer = 0; + Helper.Reflection.setPrivateField(EntityPlayer.class, this.player, 0, + Helper.Obfuscation.getPosNames("EntityPlayer/sleepTimer")); this.sleeptimerCoffin = 0; this.player.playerLocation = new ChunkCoordinates(x, @@ -908,7 +908,7 @@ public EntityPlayer.EnumStatus sleepInCoffinAt(int x, this.player.motionX = this.player.motionZ = this.player.motionY = 0.0D; if (!this.player.worldObj.isRemote) { - //TODO this.player.worldObj.updateAllPlayersSleepingFlag(); + this.player.worldObj.updateAllPlayersSleepingFlag(); } return EntityPlayer.EnumStatus.OK; diff --git a/src/main/java/de/teamlapen/vampirism/item/ItemVampiresFear.java b/src/main/java/de/teamlapen/vampirism/item/ItemVampiresFear.java index c892676dcb..cb94f5c46f 100644 --- a/src/main/java/de/teamlapen/vampirism/item/ItemVampiresFear.java +++ b/src/main/java/de/teamlapen/vampirism/item/ItemVampiresFear.java @@ -23,6 +23,7 @@ import de.teamlapen.vampirism.util.REFERENCE; public class ItemVampiresFear extends ItemSword { + public static final int MAX_BLOOD = 100; public static int getBlood(ItemStack itemStack) { if (itemStack == null || itemStack.stackTagCompound == null) { @@ -46,7 +47,7 @@ public ItemVampiresFear() { public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) { if (itemStack.stackTagCompound != null) { int blood = itemStack.stackTagCompound.getInteger("blood"); - list.add(EnumChatFormatting.RED + "Blood: " + blood + "/" + 1);//TODO adjust + list.add(EnumChatFormatting.RED + "Blood: " + blood + "/" + MAX_BLOOD); } } @@ -89,8 +90,8 @@ public boolean hitEntity(ItemStack itemStack, EntityLivingBase entityTarget, Ent itemStack.stackTagCompound.setInteger("blood", 0); } itemStack.stackTagCompound.setInteger("blood", itemStack.stackTagCompound.getInteger("blood") + VampireMob.getMaxBloodAmount((EntityCreature) entityTarget)); - if(itemStack.stackTagCompound.getInteger("blood") > 20) - itemStack.stackTagCompound.setInteger("blood", 20); + if(itemStack.stackTagCompound.getInteger("blood") > MAX_BLOOD) + itemStack.stackTagCompound.setInteger("blood", MAX_BLOOD); else if (itemStack.stackTagCompound.getInteger("blood") < 0) itemStack.stackTagCompound.setInteger("blood", 0); } diff --git a/src/main/java/de/teamlapen/vampirism/proxy/ClientProxy.java b/src/main/java/de/teamlapen/vampirism/proxy/ClientProxy.java index bdd7dc275c..e57d89cf77 100644 --- a/src/main/java/de/teamlapen/vampirism/proxy/ClientProxy.java +++ b/src/main/java/de/teamlapen/vampirism/proxy/ClientProxy.java @@ -125,7 +125,7 @@ public void registerRenderer() { ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBloodAltarTier4Tip.class,tier4Tip); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.bloodAltarTier4Tip), new RenderTileEntityItem(tier4Tip,new TileEntityBloodAltarTier4Tip())); - //ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCoffin.class, new RendererCoffin()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCoffin.class, new RendererCoffin()); } @Override @@ -203,21 +203,21 @@ else if(entity instanceof EntityCreature){ return loc; } -// @Override -// public void wakeAllPlayers() { -// // TODO Auto-generated method stub -// -// } -// -// @Override -// public boolean areAllPlayersAsleepCoffin() { -// // TODO Auto-generated method stub -// return false; -// } -// -// @Override -// public void updateAllPlayersSleepingFlagCoffin() { -// // TODO Auto-generated method stub -// -// } + + public void wakeAllPlayers() { + // TODO Auto-generated method stub + + } + + + public boolean areAllPlayersAsleepCoffin() { + // TODO Auto-generated method stub + return false; + } + + + public void updateAllPlayersSleepingFlagCoffin() { + // TODO Auto-generated method stub + + } } diff --git a/src/main/java/de/teamlapen/vampirism/proxy/ServerProxy.java b/src/main/java/de/teamlapen/vampirism/proxy/ServerProxy.java index 834d753d79..8244cefad8 100644 --- a/src/main/java/de/teamlapen/vampirism/proxy/ServerProxy.java +++ b/src/main/java/de/teamlapen/vampirism/proxy/ServerProxy.java @@ -15,7 +15,7 @@ public class ServerProxy extends CommonProxy { private boolean allPlayersSleepingInCoffin; private List playerEntities; - //private WorldServer server = MinecraftServer.getServer().worldServerForDimension(0); + private WorldServer server = MinecraftServer.getServer().worldServerForDimension(0); @Override public void registerKeyBindings() { @@ -51,63 +51,64 @@ public String translateToLocal(String s) { return s; } -// public void updateAllPlayersSleepingFlagCoffin() { -// this.playerEntities = server.playerEntities; -// -// this.allPlayersSleepingInCoffin = !this.playerEntities.isEmpty(); -// Iterator iterator = this.playerEntities.iterator(); -// -// while (iterator.hasNext()) { -// EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -// -// if (!entityplayer.isPlayerSleeping()) { -// this.allPlayersSleepingInCoffin = false; -// break; -// } -// } -// } -// -// public boolean areAllPlayersAsleepCoffin() -// { -// if (this.allPlayersSleepingInCoffin) //&& !this.isRemote() -// { -// Iterator iterator = this.playerEntities.iterator(); -// EntityPlayer entityplayer; -// -// do -// { -// if (!iterator.hasNext()) -// { -// return true; -// } -// -// entityplayer = (EntityPlayer)iterator.next(); -// } -// while (VampirePlayer.get(entityplayer).isPlayerFullyAsleepCoffin()); -// -// return false; -// } -// else -// { -// return false; -// } -// } -// -// public void wakeAllPlayers() { -// this.allPlayersSleepingInCoffin = false; -// Iterator iterator = this.playerEntities.iterator(); -// -// while (iterator.hasNext()) -// { -// EntityPlayer entityplayer = (EntityPlayer)iterator.next(); -// -// if (VampirePlayer.get(entityplayer).sleepingCoffin) -// { -// entityplayer.wakeUpPlayer(false, false, true); -// } -// } -// server.provider.resetRainAndThunder(); -// } + public void updateAllPlayersSleepingFlagCoffin() { + this.playerEntities = server.playerEntities; + + this.allPlayersSleepingInCoffin = !this.playerEntities.isEmpty(); + Iterator iterator = this.playerEntities.iterator(); + + while (iterator.hasNext()) { + EntityPlayer entityplayer = (EntityPlayer) iterator.next(); + + if (!entityplayer.isPlayerSleeping()) { + this.allPlayersSleepingInCoffin = false; + break; + } + } + } + + public boolean areAllPlayersAsleepCoffin() + { + if (this.allPlayersSleepingInCoffin) //&& !this.isRemote() + { + Iterator iterator = this.playerEntities.iterator(); + EntityPlayer entityplayer; + + do + { + if (!iterator.hasNext()) + { + return true; + } + + entityplayer = (EntityPlayer)iterator.next(); + } + while (VampirePlayer.get(entityplayer).isPlayerFullyAsleepCoffin()); + + return false; + } + else + { + return false; + } + } + + public void wakeAllPlayers() { + this.allPlayersSleepingInCoffin = false; + Iterator iterator = this.playerEntities.iterator(); + + while (iterator.hasNext()) + { + EntityPlayer entityplayer = (EntityPlayer)iterator.next(); + + if (VampirePlayer.get(entityplayer).sleepingCoffin) + { + entityplayer.wakeUpPlayer(false, false, true); + } + } + server.provider.resetRainAndThunder(); + } + @Override public ResourceLocation checkVampireTexture(Entity entity, ResourceLocation loc) { return loc; diff --git a/src/main/java/de/teamlapen/vampirism/tileEntity/TileEntityBloodAltar.java b/src/main/java/de/teamlapen/vampirism/tileEntity/TileEntityBloodAltar.java index c120f01e7a..545bd47699 100644 --- a/src/main/java/de/teamlapen/vampirism/tileEntity/TileEntityBloodAltar.java +++ b/src/main/java/de/teamlapen/vampirism/tileEntity/TileEntityBloodAltar.java @@ -49,34 +49,6 @@ public Packet getDescriptionPacket() { this.zCoord, 1, nbtTag); } - /** - * Gets a list of all the villagers in entityList that are near this - * TileEntity - * - * @param entityList - * A list of all the entities to check - * @param distance - * The maximum distance from this TileEntity - * @return List with with all the villagers that are found around this - * TileEntity - */ - private ArrayList getVillagersInRadius(List entityList, - double distance) { - ArrayList list = new ArrayList(); - for (Object entity : entityList) { - if (EntityVillager.class.isInstance(entity)) { - EntityVillager v = (EntityVillager) entity; - if (Math.sqrt(Math.pow(v.posX - xCoord, 2) - + Math.pow(v.posY - yCoord, 2) - + Math.pow(v.posZ - zCoord, 2)) <= distance) - list.add((EntityVillager) entity); - } - } - Logger.i(TAG, list.size() + "villagers found in a " + distance - + " block radius around the altar"); - return list; - } - public boolean isOccupied() { return occupied; } @@ -106,7 +78,7 @@ public void startVampirismRitual(EntityPlayer player, ItemStack itemStack) { Logger.i(TAG, "Starting Vampirism-Ritual"); if (VampirePlayer.get(player).getLevel() == 0) { player.addChatMessage(new ChatComponentTranslation( - "text.vampirism:ritual_level_wrong")); + "text.vampirism:ritual_no_vampire")); return; } // Put sword into altar @@ -116,7 +88,7 @@ public void startVampirismRitual(EntityPlayer player, ItemStack itemStack) { // TODO small animation this.worldObj.spawnEntityInWorld(new EntityLightningBolt(worldObj, player.posX, player.posY, player.posZ)); - if(itemStack.stackTagCompound != null && itemStack.stackTagCompound.getInteger("blood") <= ItemVampiresFear.getBlood(itemStack)) + if(ItemVampiresFear.MAX_BLOOD <= ItemVampiresFear.getBlood(itemStack)) player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 20 * 60, 1)); } diff --git a/src/main/resources/assets/vampirism/lang/de_DE.lang b/src/main/resources/assets/vampirism/lang/de_DE.lang index e4f6274b1e..e7f4bc46ba 100644 --- a/src/main/resources/assets/vampirism/lang/de_DE.lang +++ b/src/main/resources/assets/vampirism/lang/de_DE.lang @@ -57,6 +57,7 @@ text.vampirism:ritual_requirements_not_met=Nicht alle Vorraussetzungen wurden er text.vampirism:purity=Reinheit text.vampirism:auto_fill_enabled=Automatisches Füllen aktiviert text.vampirism:auto_fill_disabled=Automatisches Füllen deaktiviert +text.vampirism:ritual_no_vampire=Für dieses Ritual musst du ein Vampir sein #Config category.vampirism.balance=Balance Einstellungen diff --git a/src/main/resources/assets/vampirism/lang/en_US.lang b/src/main/resources/assets/vampirism/lang/en_US.lang index 889953fcd1..5264ab877b 100644 --- a/src/main/resources/assets/vampirism/lang/en_US.lang +++ b/src/main/resources/assets/vampirism/lang/en_US.lang @@ -59,6 +59,7 @@ text.vampirism:purity=Purity text.vampirism:auto_fill_enabled=Auto Fill Enabled text.vampirism:auto_fill_disabled=Auto Fill Disabled text.vampirism:skill.deactivated_by_serveradmin=This skill is deactivated by your serveradmin +text.vampirism:ritual_no_vampire=You need to be a vampire for this ritual #Config category.vampirism.balance=Balance settings