From 7b7156e87fccfa402b640ea63851a21d797202b0 Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 9 Mar 2016 14:11:56 -0800 Subject: [PATCH] Interaction hooks need to be re-added but compiles {Doesn't run} --- .../client/renderer/ItemRenderer.java.patch | 4 +- .../entity/player/EntityPlayer.java.patch | 2 +- .../client/ForgeHooksClient.java | 12 +- .../client/model/ModelLoader.java | 4 +- .../net/minecraftforge/common/ForgeHooks.java | 8 +- .../entity/player/PlayerDestroyItemEvent.java | 2 +- .../items/wrapper/PlayerArmorInvWrapper.java | 12 +- .../debug/NoPotionEffectRenderTest.java | 8 +- .../debug/PotionRegistryDebug.java | 48 ++++---- .../test/ClientCommandTest.java | 4 +- .../test/NoBedSleepingTest.java | 106 ++++++++++++------ 11 files changed, 136 insertions(+), 74 deletions(-) diff --git a/patches.mcp/minecraft/net/minecraft/client/renderer/ItemRenderer.java.patch b/patches.mcp/minecraft/net/minecraft/client/renderer/ItemRenderer.java.patch index 0b1fdfb9bb..ec372f4e72 100644 --- a/patches.mcp/minecraft/net/minecraft/client/renderer/ItemRenderer.java.patch +++ b/patches.mcp/minecraft/net/minecraft/client/renderer/ItemRenderer.java.patch @@ -51,8 +51,8 @@ float f = entityplayersp.func_184825_o(1.0F); - this.field_187469_f += MathHelper.clamp_float((Objects.equal(this.field_187467_d, itemstack) ? f * f * f : 0.0F) - this.field_187469_f, -0.4F, 0.4F); - this.field_187471_h += MathHelper.clamp_float((float)(Objects.equal(this.field_187468_e, itemstack1) ? 1 : 0) - this.field_187471_h, -0.4F, 0.4F); -+ this.field_187469_f += MathHelper.clamp_float((net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.field_187467_d, itemstack) ? f * f * f : 0.0F) - this.field_187469_f, -0.4F, 0.4F); -+ this.field_187471_h += MathHelper.clamp_float((float)(net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.field_187468_e, itemstack1) ? 1 : 0) - this.field_187471_h, -0.4F, 0.4F); ++ this.field_187469_f += MathHelper.clamp_float((net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.field_187467_d, itemstack, entityplayersp.inventory.currentItem) ? f * f * f : 0.0F) - this.field_187469_f, -0.4F, 0.4F); ++ this.field_187471_h += MathHelper.clamp_float((float)(net.minecraftforge.client.ForgeHooksClient.shouldCauseReequipAnimation(this.field_187468_e, itemstack1, -1) ? 1 : 0) - this.field_187471_h, -0.4F, 0.4F); } if (this.field_187469_f < 0.1F) diff --git a/patches.mcp/minecraft/net/minecraft/entity/player/EntityPlayer.java.patch b/patches.mcp/minecraft/net/minecraft/entity/player/EntityPlayer.java.patch index 4532e82c38..e347436882 100644 --- a/patches.mcp/minecraft/net/minecraft/entity/player/EntityPlayer.java.patch +++ b/patches.mcp/minecraft/net/minecraft/entity/player/EntityPlayer.java.patch @@ -107,7 +107,7 @@ public EntityItem dropItem(ItemStack droppedItem, boolean dropAround, boolean traceItem) @@ -746,15 +773,22 @@ - protected ItemStack func_184816_a(EntityItem p_184816_1_) + public ItemStack func_184816_a(EntityItem p_184816_1_) { + if (captureDrops) capturedDrops.add(p_184816_1_); + else // Forge: Don't indent to keep patch smaller. diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index c98196d543..4ead4cae4f 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -604,13 +604,19 @@ public class ForgeHooksClient return (new SimpleBakedModel.Builder(state, ibakedmodel, texture, pos)).makeBakedModel(); } - public static boolean shouldCauseReequipAnimation(ItemStack from, ItemStack to) + private static int slotMainHand = 0; + public static boolean shouldCauseReequipAnimation(ItemStack from, ItemStack to, int slot) { if(!Objects.equal(from, to) || from == null) { return false; } - // FIXME: 3rd argument? - return from.getItem().shouldCauseReequipAnimation(from, to); + boolean changed = false; + if (slot != -1) + { + changed = slot != slotMainHand; + slotMainHand = slot; + } + return from.getItem().shouldCauseReequipAnimation(from, to, changed); } } diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 77de53614a..0c3ea9f1e3 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -249,7 +249,7 @@ public class ModelLoader extends ModelBakery } registerVariantNames(); - + List itemVariants = Lists.newArrayList(); for(Item item : GameData.getItemRegistry().typeSafeIterable()) { @@ -560,7 +560,7 @@ public class ModelLoader extends ModelBakery return bakeNormal(model, perState, state.apply(Optional.absent()).or(TRSRTransformation.identity()), newTransforms, format, bakedTextureGetter, uvlock); } - private IBakedModel bakeNormal(ModelBlock model, IModelState perState, final TRSRTransformation modelState, List newTransforms, VertexFormat format, final Function bakedTextureGetter, boolean uvLocked) + private IBakedModel bakeNormal(ModelBlock model, IModelState perState, final TRSRTransformation modelState, List newTransforms, final VertexFormat format, final Function bakedTextureGetter, boolean uvLocked) { TextureAtlasSprite particle = bakedTextureGetter.apply(new ResourceLocation(model.resolveTextureName("particle"))); SimpleBakedModel.Builder builder = (new SimpleBakedModel.Builder(model, model.func_187967_g())).setTexture(particle); diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 405e2249c8..cecc177a68 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -656,7 +656,7 @@ public class ForgeHooks { // Logic from tryHarvestBlock for pre-canceling the event boolean preCancelEvent = false; - if (gameType.isCreative() && entityPlayer.getHeldItem() != null && entityPlayer.getHeldItem().getItem() instanceof ItemSword) + if (gameType.isCreative() && entityPlayer.func_184614_ca() != null && entityPlayer.func_184614_ca().getItem() instanceof ItemSword) preCancelEvent = true; if (gameType.isAdventure()) @@ -666,7 +666,7 @@ public class ForgeHooks if (!entityPlayer.isAllowEdit()) { - ItemStack itemstack = entityPlayer.getCurrentEquippedItem(); + ItemStack itemstack = entityPlayer.func_184614_ca(); if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock())) preCancelEvent = true; } @@ -865,7 +865,7 @@ public class ForgeHooks stack = stack.getItem().getContainerItem(stack); if (stack != null && stack.isItemStackDamageable() && stack.getMetadata() > stack.getMaxDamage()) { - MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(craftingPlayer.get(), stack)); + ForgeEventFactory.onPlayerDestroyItem(craftingPlayer.get(), stack, null); return null; } return stack; @@ -904,7 +904,7 @@ public class ForgeHooks public static boolean onPlayerAttackTarget(EntityPlayer player, Entity target) { if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false; - ItemStack stack = player.getCurrentEquippedItem(); + ItemStack stack = player.func_184614_ca(); if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return false; return true; } diff --git a/src/main/java/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java b/src/main/java/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java index 65fe0a1663..69de7e6194 100644 --- a/src/main/java/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/player/PlayerDestroyItemEvent.java @@ -27,7 +27,7 @@ import net.minecraft.util.EnumHand; public class PlayerDestroyItemEvent extends PlayerEvent { private final ItemStack original; - private final EnumHand hand; + private final EnumHand hand; // May be null if this player destroies the item by any use besides holding it. public PlayerDestroyItemEvent(EntityPlayer player, ItemStack original, EnumHand hand) { super(player); diff --git a/src/main/java/net/minecraftforge/items/wrapper/PlayerArmorInvWrapper.java b/src/main/java/net/minecraftforge/items/wrapper/PlayerArmorInvWrapper.java index d440f3892d..c0df1e3055 100644 --- a/src/main/java/net/minecraftforge/items/wrapper/PlayerArmorInvWrapper.java +++ b/src/main/java/net/minecraftforge/items/wrapper/PlayerArmorInvWrapper.java @@ -1,6 +1,7 @@ package net.minecraftforge.items.wrapper; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; public class PlayerArmorInvWrapper extends InvWrapper @@ -31,8 +32,17 @@ public class PlayerArmorInvWrapper extends InvWrapper @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + EntityEquipmentSlot equ = null; + for (EntityEquipmentSlot s : EntityEquipmentSlot.values()) + { + if (s.func_188453_a() == EntityEquipmentSlot.Type.ARMOR && s.func_188454_b() == slot) + { + equ = s; + break; + } + } // check if it's valid for the armor slot - if (slot < 4 && stack != null && stack.getItem().isValidArmor(stack, 3 - slot, inventoryPlayer.player)) + if (slot < 4 && stack != null && stack.getItem().isValidArmor(stack, equ, inventoryPlayer.player)) { return super.insertItem(slot + offset, stack, simulate); } diff --git a/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java b/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java index f8d779140d..2bb868cb76 100644 --- a/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java +++ b/src/test/java/net/minecraftforge/debug/NoPotionEffectRenderTest.java @@ -5,6 +5,7 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.GameData; @Mod( modid = NoPotionEffectRenderTest.modID, name = "No Potion Effect Render Test", version = "0.0.0" ) public class NoPotionEffectRenderTest { @@ -12,13 +13,14 @@ public class NoPotionEffectRenderTest { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - TestPotion INSTANCE = new TestPotion(30, new ResourceLocation(modID, "test_potion"), false, 0xff00ff); + TestPotion INSTANCE = new TestPotion(new ResourceLocation(modID, "test_potion"), false, 0xff00ff); + GameData.getPotionRegistry().register(-1, new ResourceLocation(modID, "test_potion"), INSTANCE); } public static class TestPotion extends Potion { - public TestPotion(int potionID, ResourceLocation location, boolean badEffect, int potionColor) { - super(potionID, location, badEffect, potionColor); + public TestPotion(ResourceLocation location, boolean badEffect, int potionColor) { + super(badEffect, potionColor); } @Override diff --git a/src/test/java/net/minecraftforge/debug/PotionRegistryDebug.java b/src/test/java/net/minecraftforge/debug/PotionRegistryDebug.java index 460567bea5..bcd958d877 100644 --- a/src/test/java/net/minecraftforge/debug/PotionRegistryDebug.java +++ b/src/test/java/net/minecraftforge/debug/PotionRegistryDebug.java @@ -6,13 +6,18 @@ import gnu.trove.set.hash.TIntHashSet; import java.util.Random; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.GameData; @Mod(modid=PotionRegistryDebug.MODID) public class PotionRegistryDebug { @@ -20,8 +25,10 @@ public class PotionRegistryDebug { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - new PotionForge(new ResourceLocation("forge", "forge"), false, 0xff00ff); // test automatic id distribution - new PotionForge(200, new ResourceLocation("forge", "forgy"), true, 0x00ff00); // test that ids above 127 work + Potion forge = new PotionForge(new ResourceLocation("forge", "forge"), false, 0xff00ff); // test automatic id distribution + Potion forgy = new PotionForge(new ResourceLocation("forge", "forgy"), true, 0x00ff00); // test that ids above 127 work + GameData.getPotionRegistry().register(-1, new ResourceLocation("forge", "forge"), forge); //TODo: Generic this out in GameRegistry, 'RegistryEntry' base type? + GameData.getPotionRegistry().register(200, new ResourceLocation("forge", "forgy"), forgy); Random rand = new Random(); TIntSet taken = new TIntHashSet(100); @@ -29,7 +36,7 @@ public class PotionRegistryDebug { taken.add(ra); // a new potion with a random id so that forge has to remap it - new PotionForge(ra, new ResourceLocation("forge", "realRandomPotion"), false, 0x0000ff); + //new PotionForge(ra, new ResourceLocation("forge", "realRandomPotion"), false, 0x0000ff); for(int i = 0; i < 20; i++) { int r = rand.nextInt(200) + 35; @@ -39,25 +46,19 @@ public class PotionRegistryDebug { taken.add(r); // this potions will most likely not have the same IDs between server and client. // The forge handshake on connect should fix this. - new PotionForge(r, new ResourceLocation("forge", "randomPotion" + r), false, 0xff00ff); + //new PotionForge(new ResourceLocation("forge", "randomPotion" + r), false, 0xff00ff); } } protected class PotionForge extends Potion { - - public PotionForge(int potionID, ResourceLocation location, boolean badEffect, int potionColor) { - super(potionID, location, badEffect, potionColor); - setPotionName("potion." + location.getResourcePath()); - } - protected PotionForge(ResourceLocation location, boolean badEffect, int potionColor) { - super(location, badEffect, potionColor); + super(badEffect, potionColor); setPotionName("potion." + location.getResourcePath()); } @Override public void renderInventoryEffect(int x, int y, PotionEffect effect, Minecraft mc) { - Potion potion = Potion.potionTypes[effect.getPotionID()]; + Potion potion = effect.func_188419_a(); mc.getTextureManager().bindTexture(TextureMap.locationBlocksTexture); TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite("minecraft:blocks/fire_layer_0"); @@ -67,16 +68,21 @@ public class PotionRegistryDebug { int width = 18; int height = width; -/* + + float r = (float)(potion.getLiquidColor() >> 24 & 255) / 255.0F; + float g = (float)(potion.getLiquidColor() >> 16 & 255) / 255.0F; + float b = (float)(potion.getLiquidColor() >> 8 & 255) / 255.0F; + float a = (float)(potion.getLiquidColor() & 255) / 255.0F; + Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer VertexBuffer = tessellator.getVertexBuffer(); - VertexBuffer.startDrawingQuads(); - VertexBuffer.setColorOpaque_I(potion.getLiquidColor()); - VertexBuffer.addVertexWithUV((double) x, (double) (y + height), 0.0D, sprite.getMinU(), sprite.getMaxV()); - VertexBuffer.addVertexWithUV((double)(x + width), (double)(y + height), 0.0D, sprite.getMaxU(), sprite.getMaxV()); - VertexBuffer.addVertexWithUV((double)(x + width), (double)y, 0.0D, sprite.getMaxU(), sprite.getMinV()); - VertexBuffer.addVertexWithUV((double)x, (double)y, 0.0D, sprite.getMinU(), sprite.getMinV()); - tessellator.draw();*/ + VertexBuffer buf = tessellator.getWorldRenderer(); + buf.begin(7, DefaultVertexFormats.POSITION_TEX); + GlStateManager.color(r, g, b, a); + buf.pos((double) x, (double)(y + height), 0.0D).func_187315_a(sprite.getMinU(), sprite.getMaxV()).endVertex(); + buf.pos((double)(x + width), (double)(y + height), 0.0D).func_187315_a(sprite.getMaxU(), sprite.getMaxV()).endVertex(); + buf.pos((double)(x + width), (double) y, 0.0D).func_187315_a(sprite.getMaxU(), sprite.getMinV()).endVertex(); + buf.pos((double) x, (double) y, 0.0D).func_187315_a(sprite.getMinU(), sprite.getMinV()).endVertex(); + tessellator.draw(); } } } diff --git a/src/test/java/net/minecraftforge/test/ClientCommandTest.java b/src/test/java/net/minecraftforge/test/ClientCommandTest.java index 3d8157e3f6..6e4a1d2e34 100644 --- a/src/test/java/net/minecraftforge/test/ClientCommandTest.java +++ b/src/test/java/net/minecraftforge/test/ClientCommandTest.java @@ -37,13 +37,13 @@ public class ClientCommandTest { } @Override - public boolean canCommandSenderUseCommand(ICommandSender sender) + public boolean func_184882_a(MinecraftServer server, ICommandSender sender) { return true; } @Override - public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) + public List func_184883_a(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { if (args.length > 0) { diff --git a/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java b/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java index c231fcd2cf..88ea98dc39 100644 --- a/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java +++ b/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java @@ -1,16 +1,26 @@ package net.minecraftforge.test; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer.EnumStatus; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTBase.NBTPrimitive; +import net.minecraft.nbt.NBTTagByte; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; +import net.minecraftforge.common.capabilities.CapabilityManager; +import net.minecraftforge.common.capabilities.ICapabilitySerializable; +import net.minecraftforge.common.capabilities.Capability.IStorage; +import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent; import net.minecraftforge.fml.common.Mod; @@ -24,64 +34,90 @@ public class NoBedSleepingTest { public static final String MODID = "ForgeDebugNoBedSleeping"; public static final String VERSION = "1.0"; + @CapabilityInject(IExtraSleeping.class) + private static final Capability SLEEP_CAP = null; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { GameRegistry.registerItem(ItemSleepingPill.instance, ItemSleepingPill.name); + CapabilityManager.INSTANCE.register(IExtraSleeping.class, new Storage(), DefaultImpl.class); MinecraftForge.EVENT_BUS.register(new EventHandler()); } public static class EventHandler { @SubscribeEvent - public void onEntityConstruct(EntityConstructing evt) + public void onEntityConstruct(AttachCapabilitiesEvent evt) { - evt.entity.registerExtendedProperties(ExtendedPropertySleeping.name, new ExtendedPropertySleeping()); + evt.addCapability(new ResourceLocation(MODID, "IExtraSleeping"), new ICapabilitySerializable() + { + IExtraSleeping inst = SLEEP_CAP.getDefaultInstance(); + @Override + public boolean hasCapability(Capability capability, EnumFacing facing) { + return capability == SLEEP_CAP; + } + + @SuppressWarnings("unchecked") + @Override + public T getCapability(Capability capability, EnumFacing facing) { + return capability == SLEEP_CAP ? (T)inst : null; + } + + @Override + public NBTPrimitive serializeNBT() { + return (NBTPrimitive)SLEEP_CAP.getStorage().writeNBT(SLEEP_CAP, inst, null); + } + + @Override + public void deserializeNBT(NBTPrimitive nbt) { + SLEEP_CAP.getStorage().readNBT(SLEEP_CAP, inst, null, nbt); + } + }); } @SubscribeEvent public void onBedCheck(SleepingLocationCheckEvent evt) { - final IExtendedEntityProperties property = evt.entityPlayer.getExtendedProperties(ExtendedPropertySleeping.name); - if (property instanceof ExtendedPropertySleeping && ((ExtendedPropertySleeping) property).isSleeping) + final IExtraSleeping sleep = evt.entityPlayer.getCapability(SLEEP_CAP, null); + if (sleep != null && sleep.isSleeping()) evt.setResult(Result.ALLOW); } @SubscribeEvent public void onWakeUp(PlayerWakeUpEvent evt) { - final IExtendedEntityProperties property = evt.entityPlayer.getExtendedProperties(ExtendedPropertySleeping.name); - if (property instanceof ExtendedPropertySleeping) - ((ExtendedPropertySleeping) property).isSleeping = false; + final IExtraSleeping sleep = evt.entityPlayer.getCapability(SLEEP_CAP, null); + if (sleep != null) + sleep.setSleeping(false); } } - public static class ExtendedPropertySleeping implements IExtendedEntityProperties + public interface IExtraSleeping { + boolean isSleeping(); + void setSleeping(boolean value); + } + + public static class Storage implements IStorage { - private static final String TAG_NAME = "IsSleepingExt"; - - public static final String name = "is_sleeping"; - - public boolean isSleeping; - @Override - public void saveNBTData(NBTTagCompound compound) + public NBTBase writeNBT(Capability capability, IExtraSleeping instance, EnumFacing side) { - compound.setBoolean(TAG_NAME, isSleeping); + return new NBTTagByte((byte)(instance.isSleeping() ? 1 : 0)); } @Override - public void loadNBTData(NBTTagCompound compound) - { - this.isSleeping = compound.getBoolean(TAG_NAME); - } - - @Override - public void init(Entity entity, World world) + public void readNBT(Capability capability, IExtraSleeping instance, EnumFacing side, NBTBase nbt) { + instance.setSleeping(((NBTPrimitive)nbt).getByte() == 1); } + } + public static class DefaultImpl implements IExtraSleeping + { + private boolean isSleeping = false; + @Override public boolean isSleeping() { return isSleeping; } + @Override public void setSleeping(boolean value) { this.isSleeping = value; } } public static class ItemSleepingPill extends Item @@ -95,19 +131,21 @@ public class NoBedSleepingTest setUnlocalizedName(MODID + ":" + name); } - public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) + @Override + public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { - if (!worldIn.isRemote) + if (!world.isRemote) { - final EnumStatus result = playerIn.trySleep(playerIn.getPosition()); + final EnumStatus result = player.trySleep(player.getPosition()); if (result == EnumStatus.OK) { - final IExtendedEntityProperties property = playerIn.getExtendedProperties(ExtendedPropertySleeping.name); - if (property instanceof ExtendedPropertySleeping) - ((ExtendedPropertySleeping) property).isSleeping = true; + final IExtraSleeping sleep = player.getCapability(SLEEP_CAP, null); + if (sleep != null) + sleep.setSleeping(true); + return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } - return itemStackIn; + return ActionResult.newResult(EnumActionResult.PASS, stack); } } }