Jump to content

Recommended Posts

Posted (edited)

I have a code for a tile entity(modified mob spawner code) and now i have troubles making it a real block that i can place. how do i register something like that correctly?

@Mod("spawntweak")
public class SpawnTweak{ 
    public static SpawnTweak instance;
    public static final String modid = "spawntweak";
    private static final Logger logger = LogManager.getLogger(modid);
    
    public SpawnTweak() {
        instance=this;
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
        MinecraftForge.EVENT_BUS.register(this);
        
        
        }
    
private void setup(final FMLCommonSetupEvent event) {
        
        logger.info("setup registered");
        
    }
    private void clientRegistries(final FMLClientSetupEvent event) {
        
        logger.info("client registered");
        
    }
    
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents{
        
        

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            event.getRegistry().registerAll(
  
            BlockList.spawner = new Block(Block.Properties.setRegistryName("minecraft:spawner"). ...)
  
                    );
            logger.info("Blocks registered");
        }

this is how i load my blocks

Edited by DarkAssassin
Posted

You need an item form of your block. Blocks only exist in the world.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
  On 4/13/2020 at 1:42 AM, Draco18s said:

You need an item form of your block. Blocks only exist in the world.

Expand  

I don't really need to do that in my case because I'm using the same ID as a Standart vanilla spawner (im able to place my block with the vanilla item) I'm now only having troubles getting the tile entity to work correctly. see this on my newer post. 

 

Edited by DarkAssassin
Posted
  On 4/13/2020 at 2:14 AM, DarkAssassin said:

I don't really need to do that in my case because I'm using the same ID as a Standart vanilla spawner

Expand  

Yes you do, because items don't know what their block is by registry name, but by being passed the instance in their constructor.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 4/13/2020 at 6:45 AM, Draco18s said:

Yes you do, because items don't know what their block is by registry name, but by being passed the instance in their constructor.

Expand  

ok i will try that but what i´m wondering then is: why is the tile entity not loading and just a block when i comment out the TE out of my code when i place the vanilla item spawner

Posted
  On 4/13/2020 at 8:33 AM, DarkAssassin said:

ok i will try that but what i´m wondering then is: why is the tile entity not loading and just a block when i comment out the TE out of my code when i place the vanilla item spawner

Expand  

Did you register a TileEntityType for your TileEntity?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
  On 4/13/2020 at 8:47 AM, Animefan8888 said:

Did you register a TileEntityType for your TileEntity?

Expand  

i thought so

but i actually just have a questionmark.

do you know what type a spawner is?

@SubscribeEvent public static void registerTileEntety(RegistryEvent.Register<TileEntityType<?>> event) {                     TileEntityType<?> type = TileEntityType.Builder.create(MobSpawnerTileEntity::new,  BlockList.spawner).build(null);           type.setRegistryName("minecraft:spawner");           event.getRegistry().register(type);         }

 

if  type.setRegistryName("minecraft:spawner")

it is just a block and if

type.setRegistryName("minecraft:mob_spawner")

the game crashes with this error log

 

[02:29:55] [Server thread/ERROR] [minecraft/Chunk]: A TileEntity type fabian.spawntweak.lists.MobSpawnerTileEntity has thrown an exception trying to write state. It will not persist, Report this to the mod author java.lang.RuntimeException: class fabian.spawntweak.lists.MobSpawnerTileEntity is missing a mapping! This is a bug!         at net.minecraft.tileentity.TileEntity.writeInternal(TileEntity.java:72) ~[?:?] {re:classloading}         at net.minecraft.tileentity.TileEntity.write(TileEntity.java:66) ~[?:?] {re:classloading}         at fabian.spawntweak.lists.MobSpawnerTileEntity.write(MobSpawnerTileEntity.java:72) ~[?:?] {re:classloading}         at net.minecraft.world.chunk.Chunk.func_223134_j(Chunk.java:444) ~[?:?] {re:classloading}         at net.minecraft.world.chunk.storage.ChunkSerializer.write(ChunkSerializer.java:303) ~[?:?] {re:classloading}         at net.minecraft.world.server.ChunkManager.func_219229_a(ChunkManager.java:677) ~[?:?] {re:classloading}         at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174) [?:1.8.0_241] {}         at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) [?:1.8.0_241] {}         at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) [?:1.8.0_241] {}         at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) [?:1.8.0_241] {}         at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) [?:1.8.0_241] {}         at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) [?:1.8.0_241] {}         at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) [?:1.8.0_241] {}         at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) [?:1.8.0_241] {}         at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [?:1.8.0_241] {}         at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) [?:1.8.0_241] {}         at net.minecraft.world.server.ChunkManager.save(ChunkManager.java:336) [?:?] {re:classloading}         at net.minecraft.world.server.ServerChunkProvider.save(ServerChunkProvider.java:309) [?:?] {re:classloading,pl:accesstransformer:B}         at net.minecraft.world.server.ServerWorld.save(ServerWorld.java:770) [?:?] {re:classloading}         at net.minecraft.server.MinecraftServer.save(MinecraftServer.java:528) [?:?] {re:classloading,pl:accesstransformer:B}         at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:571) [?:?] {re:classloading,pl:accesstransformer:B}         at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:235) [?:?] {re:classloading,pl:runtimedistcleaner:A}         at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:685) [?:?] {re:classloading,pl:accesstransformer:B}         at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241] {}

 

+the main reson is 

spawntweak.lists.MobSpawnerTileEntity has thrown an exception trying to write state. It will not persist, Report this to the mod author java.lang.RuntimeException: class fabian.spawntweak.lists.MobSpawnerTileEntity is missing a mapping!

 

i

 

 

 

Edited by DarkAssassin
Posted
  On 4/13/2020 at 9:01 AM, DarkAssassin said:

the game crashes with this error log

Expand  

It would help if you showed more code. What does your Block look like what about your TileEntity? You are using a class for your Block and TileEntity right?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 4/13/2020 at 9:21 AM, Animefan8888 said:

It would help if you showed more code. What does your Block look like what about your TileEntity? You are using a class for your Block and TileEntity right?

Expand  

i´ve detailed it in another post but

Tile Entity

import java.util.Random;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.WeightedSpawnerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;


public class MobSpawnerTileEntity extends TileEntity implements ITickableTileEntity {
   private final AbstractSpawner spawnerLogic = new AbstractSpawner() {
      public void broadcastEvent(int id) {
         MobSpawnerTileEntity.this.world.addBlockEvent(MobSpawnerTileEntity.this.pos, Blocks.SPAWNER, id, 0);
      }

      public World getWorld() {
         return MobSpawnerTileEntity.this.world;
      }

      public BlockPos getSpawnerPosition() {
         return MobSpawnerTileEntity.this.pos;
      }

      public void setNextSpawnData(WeightedSpawnerEntity nextSpawnData) {
         super.setNextSpawnData(nextSpawnData);
         if (this.getWorld() != null) {
            BlockState blockstate = this.getWorld().getBlockState(this.getSpawnerPosition());
            this.getWorld().notifyBlockUpdate(MobSpawnerTileEntity.this.pos, blockstate, blockstate, 4);
         }

      }
   };
   
   public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
          if (!worldIn.isRemote) {
             if (worldIn.isBlockPowered(pos)) {
                AbstractSpawner.isActivated  = true;
           }
             else 
        {
            AbstractSpawner.isActivated =false;     
                 
                 
                 
        }  
       }

    
    
     }
   
   public MobSpawnerTileEntity() {
      super(TileEntityType.MOB_SPAWNER);
   }

   public void read(CompoundNBT compound) {
      super.read(compound);
      this.spawnerLogic.read(compound);
   }

   public CompoundNBT write(CompoundNBT compound) {
      super.write(compound);
      this.spawnerLogic.write(compound);
      return compound;
   }

   public void tick() {
      this.spawnerLogic.tick();
   }

   
   @Nullable
   public SUpdateTileEntityPacket getUpdatePacket() {
      return new SUpdateTileEntityPacket(this.pos, 1, this.getUpdateTag());
   }

  
   public CompoundNBT getUpdateTag() {
      CompoundNBT compoundnbt = this.write(new CompoundNBT());
      compoundnbt.remove("SpawnPotentials");
      return compoundnbt;
   }

 
   public boolean receiveClientEvent(int id, int type) {
      return this.spawnerLogic.setDelayToMin(id) ? true : super.receiveClientEvent(id, type);
   }

 
   public boolean onlyOpsCanSetNbt() {
      return true;
   }

   public AbstractSpawner getSpawnerBaseLogic() {
      return this.spawnerLogic;
   }
}

Block

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.world.IBlockReader;


public class MobSpawner extends Block{
    
    
    public MobSpawner(Properties properties) {
        super(Properties.create(Material.IRON).hardnessAndResistance(3.0f, 3.0f).sound(SoundType.METAL));
    
        
            
        
    }

    
    @Override
    public TileEntity createTileEntity(BlockState state, IBlockReader world) {
        return new MobSpawnerTileEntity();
    }
    public BlockRenderLayer getRenderLayer()
    {
        return BlockRenderLayer.TRANSLUCENT;
    }
    
    @Override
    public boolean hasTileEntity(BlockState state) {
        return true;
    }


}

is it right that i have this in my tile entity or do i need to put the function into the block class 

 public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
          if (!worldIn.isRemote) {
             if (worldIn.isBlockPowered(pos)) {
                AbstractSpawner.isActivated  = true;
           }
             else 
        {
            AbstractSpawner.isActivated =false;     
                 
                 
                 
        }  
       }

    
    
     }

 

Posted
  On 4/12/2020 at 8:42 PM, DarkAssassin said:

BlockList.spawner = new Block(...

Expand  

Might help if you actually USED your block class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
  On 4/13/2020 at 1:51 PM, Draco18s said:

Might help if you actually USED your block class.

Expand  

my bad. the code is older and my setup function now looks like this

 

    
private void setup(final FMLCommonSetupEvent event) {
        
        logger.info("setup registered");
        
    }
    private void clientRegistries(final FMLClientSetupEvent event) {
        
        logger.info("client registered");
        
    }
    
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents{
        
        

        @SubscribeEvent
        public static void registerItems(final RegistryEvent.Register<Item> event) {
            event.getRegistry().registerAll(
                    ItemList.spawner= new BlockItem(BlockList.spawner, new Item.Properties().group(ItemGroup.TRANSPORTATION)).setRegistryName(BlockList.spawner.getRegistryName()));}

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            event.getRegistry().registerAll(
            
            BlockList.spawner = new MobSpawner(MobSpawner.Properties.create(Material.IRON).hardnessAndResistance(3.0f, 3.0f).sound(SoundType.METAL)).setRegistryName("minecraft:spawner"));
            logger.info("Blocks registered");
        }

        
        @SubscribeEvent
        public static void registerTileEntety(RegistryEvent.Register<TileEntityType<?>> event) {

            
         TileEntityType<?> type = TileEntityType.Builder.create(MobSpawnerTileEntity::new, BlockList.spawner).build(null);
          type.setRegistryName("minecraft:mob_spawner");
          event.getRegistry().register(type);
        }
        
        
        

        
        
   


    

Edited by DarkAssassin

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You will find the crash-report or log in your minecraft directory (crash-report or logs folder)
    • Use a modpack which is using these 2 mods as working base:   https://www.curseforge.com/minecraft/modpacks/life-in-the-village-3
    • inicie un mundo donde instale Croptopia y Farmer's Delight, entonces instale el addon Croptopia Delight pero no funciona. es la version 1.18.2
    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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