Jump to content

[1.7.10] My custom Web Block crashes with getPlayerRelativeBlockHardness


SteveKunG

Recommended Posts

Please help!! I don't know why crash. T_T

 

 

package stevekung.mods.moreplanets.planets.fronos.blocks;

 

import java.util.ArrayList;

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeHooks;

import net.minecraftforge.common.IShearable;

import stevekung.mods.moreplanets.core.MorePlanetCore;

import stevekung.mods.moreplanets.planets.fronos.items.FronosItems;

 

public class BlockCheeseWeb extends Block implements IShearable

{

public BlockCheeseWeb(String name)

{

super(Material.web);

this.setBlockName(name);

this.setLightOpacity(1);

this.setHardness(4.0F);

}

 

@Override

public CreativeTabs getCreativeTabToDisplayOn()

{

return MorePlanetCore.mpBlocksTab;

}

 

@Override

public void registerBlockIcons(IIconRegister par1IconRegister)

{

this.blockIcon = par1IconRegister.registerIcon("fronos:cheeseWeb");

}

 

@Override

public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)

{

entity.setInWeb();

}

 

@Override

public boolean isOpaqueCube()

{

return false;

}

 

@Override

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)

{

return null;

}

 

@Override

public int getRenderType()

{

return 1;

}

 

@Override

public int damageDropped(int meta)

{

return 9;

}

 

@Override

public boolean renderAsNormalBlock()

{

return false;

}

 

@Override

public Item getItemDropped(int meta, Random rand, int fortune)

{

return FronosItems.fronosBasicItem;

}

 

@Override

public boolean canHarvestBlock(EntityPlayer player, int metadata)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack == null)

{

return player.canHarvestBlock(this);

}

return stack.getItem() == Items.shears && stack.getItem() instanceof ItemSword;

}

 

@Override

public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack.getItem() instanceof ItemSword && stack.getItem() == Items.shears)

{

return 0.1F;

}

return ForgeHooks.blockStrength(this, player, world, x, y, z);

}

 

@Override

public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z)

{

return true;

}

 

@Override

public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)

{

final ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

ret.add(new ItemStack(FronosItems.fronosBasicItem, 1, 9));

return ret;

}

}

 

Link to comment
Share on other sites

Is it NPE?

 

My guess is not checking for null itemStack :)

You need to check if itemStack is not null before you cast it to any kind of item.

 

ItemStack current = inv.getCurrentItem();
if (current != null && current.getItem() instanceof SomeItem)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

OK When I changed to this.

 

@Override

public boolean canHarvestBlock(EntityPlayer player, int metadata)

{

ItemStack stack = player.inventory.getCurrentItem();

 

if (stack.getItem() == Items.shears || stack.getItem() instanceof ItemSword)

{

return player.canHarvestBlock(this);

}

return false;

}

 

That crash again T_T

 

 

---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 5/1/2558, 21:41 น.

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at stevekung.mods.moreplanets.planets.fronos.blocks.BlockCheeseWeb.getPlayerRelativeBlockHardness(BlockCheeseWeb.java:105)

at net.minecraft.client.multiplayer.PlayerControllerMP.clickBlock(PlayerControllerMP.java:170)

at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1398)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1937)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:962)

at net.minecraft.client.Minecraft.run(Minecraft.java:887)

at net.minecraft.client.main.Main.main(SourceFile:148)

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 net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at stevekung.mods.moreplanets.planets.fronos.blocks.BlockCheeseWeb.getPlayerRelativeBlockHardness(BlockCheeseWeb.java:105)

at net.minecraft.client.multiplayer.PlayerControllerMP.clickBlock(PlayerControllerMP.java:170)

at net.minecraft.client.Minecraft.func_147116_af(Minecraft.java:1398)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [GCEntityClientPlayerMP['SteveMCCommander'/8, l='MpServer', x=-511.54, y=57.62, z=848.34]]

Chunk stats: MultiplayerChunkCache: 289, 289

Level seed: 0

Level generator: ID 01 - flat, ver 0. Features enabled: false

Level generator options:

Level spawn location: World: (-517,4,842), Chunk: (at 11,0,10 in -33,52; contains blocks -528,0,832 to -513,255,847), Region: (-2,1; contains chunks -64,32 to -33,63, blocks -1024,0,512 to -513,255,1023)

Level time: 792527 game time, 4000 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 1 total; [GCEntityClientPlayerMP['SteveMCCommander'/8, l='MpServer', x=-511.54, y=57.62, z=848.34]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:373)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2433)

at net.minecraft.client.Minecraft.run(Minecraft.java:916)

at net.minecraft.client.main.Main.main(SourceFile:148)

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 net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78)

at GradleStart.main(GradleStart.java:45)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 7 (x86) version 6.1

Java Version: 1.7.0_71, Oracle Corporation

Java VM Version: Java HotSpot Client VM (mixed mode), Oracle Corporation

Memory: 832060272 bytes (793 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP v9.05 FML v7.10.85.1272 Minecraft Forge 10.13.2.1272 15 mods loaded, 15 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.10.85.1272} [Forge Mod Loader] (forgeBin-1.7.10-10.13.2.1272.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.13.2.1272} [Minecraft Forge] (forgeBin-1.7.10-10.13.2.1272.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Micdoodlecore{} [Micdoodle8 Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

GalacticraftCore{3.0.6} [Galacticraft Core] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

BiomesOPlenty{1.0} [biomes O' Plenty] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

NBTEdit{1.7.10} [in-game NBTEdit] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

GalacticraftMars{3.0.6} [Galacticraft Planets] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

BlockUtility{1.0.0} [block Utility] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

EntityGhost{1.0.0} [Entity Ghost Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

SteveIceBucket{1.0.3} [steve's Ice Bucket] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Lays{1.0.0} [Lays Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

MorePlanet{1.1.2} [More Planet's] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

TiberiumCraft{1.0.0} [Tiberium Craft] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

YouTuber{1.0.0} [YouTuber Tutorial Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Launched Version: 1.7.10

LWJGL: 2.9.1

OpenGL: GeForce 9500 GT/PCIe/SSE2 GL version 3.3.0, NVIDIA Corporation

GL Caps: Using GL 1.3 multitexturing.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Anisotropic filtering is supported and maximum anisotropy is 16.

Shaders are available because OpenGL 2.1 is supported.

 

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

 

Link to comment
Share on other sites

In #getPlayerRelativeBlockHardness()

 

ItemStack stack = player.inventory.getCurrentItem();

      if (stack != null && (stack.getItem() instanceof ItemSword || stack.getItem() == Items.shears))
      {
         return 0.1F;
      }
      return ForgeHooks.blockStrength(this, player, world, x, y, z);

 

***stack != null***

 

Also shears are not extending Sword so:

stack.getItem() == Items.shears && stack.getItem() instanceof ItemSword

Which you wrote will always be false.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

You need to check if it's null. Also, instead of checking if the item is equal to Items.shears you should be checking if it is an instance of ItemShears, this way someone can use shears from other mods. You should also be using || (or) not && (and) because something can never be both shears and a sword.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • KILAT77 : Waspada Situs Scam dengan Withdraw Yang Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah KILAT77. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan KILAT77. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • It is a dupe mod issue Remove Rubidium - you are already using Embeddium which is a fork of Rubidium
    • I made a block entity in forge 1.20.1, I want to prevent hopper from taking input slot item, i tried to override the extractItem method, it prevented hopper from taking input slot item, but the player also unable to take/change the item in input slot unless the slot is empty. public class FluidSeparatorBlockEntity extends BlockEntity implements MenuProvider { private static final int INPUT_SLOT = 0; private final CustomItemHandler itemHandler = new CustomItemHandler(3){ @Override protected void onContentsChanged(int slot) { setChanged(); } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { return slot == INPUT_SLOT; } @Override public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { if (slot == INPUT_SLOT) { return ItemStack.EMPTY; } return super.extractItem(slot, amount, simulate); } }; private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty(); protected final ContainerData data; private int progress = 0; private int maxProgress = 78; public FluidSeparatorBlockEntity(BlockPos pPos, BlockState pBlockState) { super(ModBlockEntities.FLUID_SEPARATOR_BE.get(), pPos, pBlockState); this.data = new ContainerData() { @Override public int get(int pIndex) { return switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress; default -> 0; }; } @Override public void set(int pIndex, int pValue) { switch (pIndex) { case 0 -> FluidSeparatorBlockEntity.this.progress = pValue; case 1, 2 -> FluidSeparatorBlockEntity.this.maxProgress = pValue; } } @Override public int getCount() { return 3; } }; } @Override public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if(cap == ForgeCapabilities.ITEM_HANDLER) { return lazyItemHandler.cast(); } return super.getCapability(cap, side); } @Override public void onLoad() { super.onLoad(); lazyItemHandler = LazyOptional.of(() -> itemHandler); } @Override public void invalidateCaps() { super.invalidateCaps(); lazyItemHandler.invalidate(); } public void drops() { SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, itemHandler.getStackInSlot(i)); } Containers.dropContents(this.level, this.worldPosition, inventory); } @Override public Component getDisplayName() { return Component.translatable("block.chemmaster.fluid_separator"); } @Nullable @Override public AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) { return new FluidSeparatorMenu(pContainerId, pPlayerInventory, this, this.data); } @Override protected void saveAdditional(CompoundTag pTag) { pTag.put("inventory", itemHandler.serializeNBT()); pTag.putInt("fluid_separator.progress", progress); super.saveAdditional(pTag); } @Override public void load(CompoundTag pTag) { super.load(pTag); itemHandler.deserializeNBT(pTag.getCompound("inventory")); progress = pTag.getInt("fluid_separator.progress"); } public void tick(Level pLevel, BlockPos pPos, BlockState pState) { ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { resetProgress(); return; } if(hasRecipe()) { increaseCraftingProgress(); setChanged(pLevel, pPos, pState); if(hasProgressFinished()) { craftItem(); resetProgress(); } } else { resetProgress(); } } private void resetProgress() { progress = 0; } private void craftItem() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isPresent()) { List<ItemStack> results = recipe.get().getOutputs(); ItemStack inputStack = this.itemHandler.getStackInSlot(INPUT_SLOT); if (inputStack.getCount() < 2) { // If there are not enough items, do not proceed with crafting return; } // Extract the input item from the input slot this.itemHandler.internalExtractItem(INPUT_SLOT, 2, false); // Loop through each result item and find suitable output slots for (ItemStack result : results) { int outputSlot = findSuitableOutputSlot(result); if (outputSlot != -1) { this.itemHandler.setStackInSlot(outputSlot, new ItemStack(result.getItem(), this.itemHandler.getStackInSlot(outputSlot).getCount() + result.getCount())); } else { // Handle the case where no suitable output slot is found // This can be logging an error, throwing an exception, or any other handling logic System.err.println("No suitable output slot found for item: " + result); } } } } private int findSuitableOutputSlot(ItemStack result) { // Implement logic to find a suitable output slot for the given result // Return the slot index or -1 if no suitable slot is found for (int i = 0; i < this.itemHandler.getSlots(); i++) { // Ensure we do not place the output item in the input slot if (i == INPUT_SLOT) { continue; } ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return i; } } return -1; } private boolean hasRecipe() { Optional<FluidSeparatingRecipe> recipe = getCurrentRecipe(); if (recipe.isEmpty()) { return false; } List<ItemStack> results = recipe.get().getOutputs(); for (ItemStack result : results) { if (!canInsertAmountIntoOutputSlot(result) || !canInsertItemIntoOutputSlot(result.getItem())) { return false; } } return true; } private Optional<FluidSeparatingRecipe> getCurrentRecipe(){ SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for (int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(FluidSeparatingRecipe.Type.INSTANCE, inventory, level); } private boolean canInsertAmountIntoOutputSlot(ItemStack result) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || (stackInSlot.getItem() == result.getItem() && stackInSlot.getCount() + result.getCount() <= stackInSlot.getMaxStackSize())) { return true; } } return false; } private boolean canInsertItemIntoOutputSlot(Item item) { for (int i = 1; i < this.itemHandler.getSlots(); i++) { ItemStack stackInSlot = this.itemHandler.getStackInSlot(i); if (stackInSlot.isEmpty() || stackInSlot.getItem() == item) { return true; } } return false; } private boolean hasProgressFinished() { return progress >= maxProgress; } private void increaseCraftingProgress() { progress++; } }  
    • No dice. Unfortunately this fix didn't work, thank you though.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.