Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

MrMarnic

Members
  • Posts

    39
  • Joined

  • Last visited

Posts posted by MrMarnic

  1. In 1.12.2 the type of the RayTraceResult of the ProjectileImpactEvent was Block if the arrow hit a block.

    But int 1.14.3 it is only Block if the arrow hits a block the player is directly looking at. Everytime else it is miss.

    This is my code:

    @SubscribeEvent
    public static void projectileHit(ProjectileImpactEvent.Arrow e) {
      System.out.println(e.getRayTraceResult().getType());
    }
      
      
      

    Again it is only Block if the hit block is highlighted.

    I 1.12.2 it worked.

  2. Here is my problem.

    I have create a custom bow which is working fine but when I am increasing the velocity of the arrows, the arrows have an offset when flying.

    They are not flying as straight as the arrows from the vanilla bow.

    Here is my code:

    public class BasicBow extends ItemBow{
    
        public BasicBow(String name) {
            setRegistryName(name);
          	setUnlocalizedName(name);
            setMaxDamage(384);
            this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
            {
                @SideOnly(Side.CLIENT)
                public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
                {
                    if (entityIn == null)
                    {
                        return 0.0F;
                    }
                    else
                    {
                        return !(entityIn.getActiveItemStack().getItem() instanceof ItemBow) ? 0.0F : (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20f;
                    }
                }
            });
        }
    
        @Override
        public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
            if (entityLiving instanceof EntityPlayer)
            {
                EntityPlayer entityplayer = (EntityPlayer)entityLiving;
                boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
                ItemStack itemstack = this.findAmmo(entityplayer);
    
                int i = this.getMaxItemUseDuration(stack) - timeLeft;
                i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
                if (i < 0) return;
    
                if (!itemstack.isEmpty() || flag)
                {
                    if (itemstack.isEmpty())
                    {
                        itemstack = new ItemStack(Items.ARROW);
                    }
    
                    float f = getArrowVelocity(i);
    
                    if ((double)f >= 0.1D)
                    {
                        boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
    
                        if (!worldIn.isRemote)
                        {
                            ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                            EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                            entityarrow = this.customizeArrow(entityarrow);
                            entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 4, 1f);
    
                            if (f == 1.0F)
                            {
                                entityarrow.setIsCritical(true);
                            }
    
                            int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
    
                            if (j > 0)
                            {
                                entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D + settings.getDamage());
                            }
    
                            int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
    
                            if (k > 0)
                            {
                                entityarrow.setKnockbackStrength(k);
                            }
    
                            if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
                            {
                                entityarrow.setFire(100);
                            }
    
                            stack.damageItem(1, entityplayer);
    
                            if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
                            {
                                entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                            }
    
                            worldIn.spawnEntity(entityarrow);
                        }
    
                        worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
    
                        if (!flag1 && !entityplayer.capabilities.isCreativeMode)
                        {
                            itemstack.shrink(1);
    
                            if (itemstack.isEmpty())
                            {
                                entityplayer.inventory.deleteStack(itemstack);
                            }
                        }
    
                        entityplayer.addStat(StatList.getObjectUseStats(this));
                    }
                }
            }
        }
    }

    In this line I am applying the velocity:

    entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 4.5f, 1f);

    When I multiply f with an float higher than 4 the bug is occuring.

    It would be nice if you can help me.

  3. MinecraftVersion: 1.13.2

    ForgeVersion: 25.0.26

     

    I am currently updating my mod and I need to get all registered entities in the game.

    So i used this code in the FMLLoadCompleteEvent:

    public void complete(final FMLLoadCompleteEvent e) {
            System.out.println("ITEMS: " + ForgeRegistries.ITEMS.getValues().size());
            System.out.println("ENTITIES: " + ForgeRegistries.ENTITIES.getValues().size());
        }

    But the ouput is:

    ITEMS: 797
    ENTITIES: 0

    So the erros is that the ForgeRegistry for Entities is empty.

    Btw. in 1.12.2 it has worked.

  4. I made a custom gui that looks like the one from the furnace . 

    The inventory should not be saved and shoul be opened by and item.

    It should only be an inventory where you can move items.

    When I'm doing things in the player's inventory part everything goes well.

    But when i put an item in the inventory of the dispenser and try to left click to it

    the game crashes with an java.lang.NullPointerException: Rendering screen .

    But when i left click+shift everything works.

    I have no more ideas what to do . I hope you can help me .

    Error Log:

    Spoiler

     Reported exception thrown!
    net.minecraft.util.ReportedException: Rendering screen
        at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1204) ~[EntityRenderer.class:?]
        at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1207) ~[Minecraft.class:?]
        at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
        at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
        at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
        at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
        at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
        at GradleStart.main(GradleStart.java:26) [start/:?]
    Caused by: java.lang.NullPointerException
        at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:141) ~[GuiContainer.class:?]
        at me.marnic.mod.gui.TestGui.drawScreen(TestGui.java:33) ~[TestGui.class:?]
        at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:353) ~[ForgeHooksClient.class:?]
        at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1177) ~[EntityRenderer.class:?]
        ... 15 more
    [18:52:19] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:630]: ---- Minecraft Crash Report ----
    // Would you like a cupcake?

    Time: 12/16/17 6:52 PM
    Description: Rendering screen

    java.lang.NullPointerException: Rendering screen
        at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:141)
        at me.marnic.mod.gui.TestGui.drawScreen(TestGui.java:33)
        at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:353)
        at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1177)
        at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1207)
        at net.minecraft.client.Minecraft.run(Minecraft.java:441)
        at net.minecraft.client.main.Main.main(Main.java:118)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
        at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
        at GradleStart.main(GradleStart.java:26)

     

    GUI class:

    package me.marnic.mod.gui;
    
    import net.minecraft.client.gui.GuiScreen;
    import net.minecraft.client.gui.inventory.GuiContainer;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.ResourceLocation;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraftforge.event.terraingen.BiomeEvent.GetWaterColor;
    
    public class TestGui extends GuiContainer{
    	
    	public TestGui(Container inventorySlotsIn) {
    		
    		super(inventorySlotsIn);
    		// TODO Auto-generated constructor stub
    	}
    		
    	final ResourceLocation loc = new ResourceLocation("m_mod","textures/gui/test_gui.png");
    	
    	@Override
    	public boolean doesGuiPauseGame() {
    		return false;
    	}
    	
    	@Override
    	public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    		mc.getTextureManager().bindTexture(loc);
    		drawTexturedModalRect(width / 2 - 176 / 2, height / 2 - 166 / 2, 0, 0, 176, 166);
    		super.drawScreen(mouseX, mouseY, partialTicks);
    	}
    
    	@Override
    	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    		// TODO Auto-generated method stub
    		
    	}
    	
    	
    	
    }

    GUI Container:

    package me.marnic.mod.gui;
    
    import me.marnic.mod.item.BasicItem;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.inventory.ClickType;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class TestGuiContainer extends Container
    {
        public TestGuiInventory inv;
    
        public TestGuiContainer(IInventory playerInventory, TestGuiInventory dispenserInventoryIn)
        {
            this.inv = dispenserInventoryIn;
           
            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    this.addSlotToContainer(new Slot(dispenserInventoryIn, j + i * 3, 62 + j * 18, 17 + i * 18));
                    
                }
            }
    
            for (int k = 0; k < 3; ++k)
            {
                for (int i1 = 0; i1 < 9; ++i1)
                {
                    this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
                }
            }
    
            for (int l = 0; l < 9; ++l)
            {
                this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
            }
        }
    
        /**
         * Determines whether supplied player can use this container
         */
        @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {
            return true;
        }
    
        /**
         * Handle when the stack in slot {@code index} is shift-clicked. Normally this moves the stack between the player
         * inventory and the other inventory(s).
         */
        @Override
        public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
        {
        	ItemStack itemstack = ItemStack.EMPTY;
            Slot slot = this.inventorySlots.get(index);
    
            if (slot != null && slot.getHasStack())
            {
                ItemStack itemstack1 = slot.getStack();
                itemstack = itemstack1.copy();
    
                if (index < 9)
                {
                    if (!this.mergeItemStack(itemstack1, 9, 45, true))
                    {
                    
                        return ItemStack.EMPTY;
                    }
                }
                else if (!this.mergeItemStack(itemstack1, 0, 9, false))
                {
                    return ItemStack.EMPTY;
                }
    
                if (itemstack1.isEmpty())
                {
                    slot.putStack(ItemStack.EMPTY);
                }
                else
                {
                    slot.onSlotChanged();
                }
    
                if (itemstack1.getCount() == itemstack.getCount())
                {
                    return ItemStack.EMPTY;
                }
    
                slot.onTake(playerIn, itemstack1);
            }
    
            return itemstack;
        }
        
       
       
        
    }

    GUI Inventory:

    package me.marnic.mod.gui;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.init.Items;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.NonNullList;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraftforge.items.IItemHandler;
    
    public class TestGuiInventory implements IInventory{
    	
    	
    	public int SIZE = 9;
    	public NonNullList<ItemStack> items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
    	InventoryPlayer p;
    	
    	@Override
    	public String getName() {
    		// TODO Auto-generated method stub
    		return "GuiInv";
    	}
    
    	@Override
    	public boolean hasCustomName() {
    		// TODO Auto-generated method stub
    		return false;
    	}
    
    	@Override
    	public ITextComponent getDisplayName() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public int getSizeInventory() {
    		// TODO Auto-generated method stub
    		return items.size();
    	}
    
    	@Override
    	public boolean isEmpty() {
    		
    		for(ItemStack s:items) {
    			if(!s.isEmpty()) {
    				return false;
    			}
    		}
    		return true;
    	}
    
    	@Override
    	public ItemStack getStackInSlot(int index) {
    		// TODO Auto-generated method stub
    		return items.get(index);
    	}
    
    	@Override
    	public ItemStack decrStackSize(int index, int count) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public ItemStack removeStackFromSlot(int index) {
    		// TODO Auto-generated method stub
    		return items.set(index, ItemStack.EMPTY);
    	}
    
    	@Override
    	public void setInventorySlotContents(int index, ItemStack stack) {
    		items.set(index, stack);
    		
    	}
    
    	@Override
    	public int getInventoryStackLimit() {
    		// TODO Auto-generated method stub
    		return 64;
    	}
    
    	@Override
    	public void markDirty() {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public boolean isUsableByPlayer(EntityPlayer player) {
    		// TODO Auto-generated method stub
    		return player.getDistanceSq(player) <= 64.0D;
    	}
    
    	@Override
    	public void openInventory(EntityPlayer player) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public void closeInventory(EntityPlayer player) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public boolean isItemValidForSlot(int index, ItemStack stack) {
    		// TODO Auto-generated method stub
    		return true;
    	}
    
    	@Override
    	public int getField(int id) {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	@Override
    	public void setField(int id, int value) {
    		// TODO Auto-generated method stub
    		
    	}
    	
    	@Override
    	public int getFieldCount() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    
    	@Override
    	public void clear() {
    		
    		for(ItemStack s:items) {
    			s = ItemStack.EMPTY;
    		}
    	}
    	
    }

    GUI Handler:

    package me.marnic.mod.gui;
    
    import me.marnic.mod.main.Main;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.common.network.IGuiHandler;
    
    public class GUIHandler implements IGuiHandler{
    	
    	public static int TEST_GUI = 0;
    	
    	
    	@Override
    	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		if(ID==TEST_GUI) {
    			return new TestGuiContainer(player.inventory,new TestGuiInventory());
    		}
    		return null;
    	}
    
    	@Override
    	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    		if(ID==TEST_GUI) {
    			return new TestGui(new TestGuiContainer(player.inventory,new TestGuiInventory()));
    		}
    		return null;
    	}
    
    }

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.