Interaction hooks need to be re-added but compiles {Doesn't run}

This commit is contained in:
LexManos committed 2016-03-09 14:11:56 -08:00
1 parent 846910b8c8
commit 7b7156e87f
11 files changed
+136 -74

No files matched your search

@@ -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
@@ -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();
}
}
}
@@ -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<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
public List<String> func_184883_a(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos)
{
if (args.length > 0)
{
@@ -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<IExtraSleeping> 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<NBTPrimitive>()
{
IExtraSleeping inst = SLEEP_CAP.getDefaultInstance();
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == SLEEP_CAP;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> 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<IExtraSleeping>
{
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<IExtraSleeping> 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<IExtraSleeping> 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<ItemStack> 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);
}
}
}