Jump to content

Recommended Posts

Posted

You're probably using a static variable somewhere. The TileEntities for each block should be all be different instances of your TileEntity class. I can't think of any reason why that might be so. But if one of the variables inside your TileEntity was declared as `static` then every TileEntity would share that same state. From the way you describe it, I'd guess that more than one of your variables is declared static.

  • Like 1
Posted

Post your code.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
1 hour ago, jaminv said:

You're probably using a static variable somewhere. The TileEntities for each block should be all be different instances of your TileEntity class. I can't think of any reason why that might be so. But if one of the variables inside your TileEntity was declared as `static` then every TileEntity would share that same state. From the way you describe it, I'd guess that more than one of your variables is declared static.

Is it only apply on tileentity class or include block class as well?

Posted

One thing I noticed is that you shouldn't be calling BlockWorkbench.setState() from your TileEntity. Instead, you should add a method called getActualState() from your Block. In that method you can call world.getTileEntity(pos), get data from the TE, and return it in an IBlockState. Here's how I've done it in the past.

 

	@Override
	public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
        TileEntity tileentity = BlockHelper.getTileEntity(worldIn, pos);

        EnumFacing facing = EnumFacing.NORTH;
       	boolean active = false;

        if (tileentity instanceof TileEntityMachineBase) {
        	TileEntityMachineBase te = (TileEntityMachineBase)tileentity;
        	facing = te.getFacing();
        	active = te.isProcessing();
        }
        
        return state.withProperty(FACING, facing).withProperty(ACTIVE, active);
	}

 

I don't think this is causing your current problem, it's just the correct way to do things. I don't think you should really be calling World.setBlockState() the way that you are. It could cause you problems down the line.

 

Quote

Is it only apply on tileentity class or include block class as well?

The Block class uses a singleton pattern. Minecraft only creates one Block instance no matter how many blocks of that type there are in the world. So Block classes are basically already de facto static. You should never store anything in a Block class, but instead use block states and tile entities, which you are doing correctly. TileEntities are not singleton. Minecraft creates a separate TileEntity for every instance of a block in the [loaded] world. I don't see you doing anything wrong here. It's just important as a modder to understand what Minecraft is doing here.

 

private WorkstationEnergyStorage storage = new WorkstationEnergyStorage(6000);
...
private int cookTime, energy = storage.getEnergyStored();

 

You've got some weirdness with your energy handling. You probably shouldn't be storing the energy value in your TileEntity, but instead relying on WorkstationEnergyStorage storage to handle it for you. I'm not even sure how your machine actually works, because it doesn't look like `energy` should ever be more than 0. The above code is only called once, and it storage.getEnergyStored() will always be 0 when it's called. I don't see anything else syncing your `energy` value to the energy storage. Even if there is some code I'm not seeing somewhere, it's going to cause you problems down the line. There's no reason to store the energy value as an integer in your TileEntity. It's stored in your energy storage. Use that.

 

					ItemStack output = WorkbenchRecipes.getInstance().getWorkbenchResult(inputs[0], inputs[1]);
					
					if(!output.isEmpty())
					{
						output = WorkbenchRecipes.getInstance().getWorkbenchResult(inputs[0], inputs[1]);
						smelting = output;
						cookTime++;
						energy--;
						BlockWorkbench.setState(true, world, pos);
						if(cookTime == 200)
						{
							cookTime = 0;
							output = WorkbenchRecipes.getInstance().getWorkbenchResult(inputs[0], inputs[1]);
							smelting = output;
							inputs[0].shrink(1);
							inputs[1].shrink(1);
							handler.setStackInSlot(0, inputs[0]);
							handler.setStackInSlot(1, inputs[1]);
							if(handler.getStackInSlot(2).getCount() > 0)
							{
								handler.getStackInSlot(2).grow(1);
							}
							else
							{
								handler.insertItem(2, smelting, false);
							}
							smelting = null;
							output = null;
							cookTime = 0;
							System.out.println("finish");
							this.markDirty();
							return;
						}
					}

 

You've got some weird duplicate code in your update() method. You're initializing `output` 3 times to the exact same value. You're just wasting processor cycles. `smelting` is initialized twice but never used. `output` is set to null at the end of your code, but it's a local variable and this isn't necessary. Perhaps you were just trying different things out, but I would clean this up. It makes it easier to see what going on.

Although I've spotted a few potential issues that might cause you problems down the road, nothing really stands out as the actual problem. Are you sure you've pushed your most recent code to Github? With the energy issue, I'm not sure how you get to the point where this is actually outputing items. Perhaps I'm looking at an older version of the code?

Posted

In WorkbenchRecipes:

	private final Table<ItemStack, ItemStack, ItemStack> workingList = HashBasedTable.<ItemStack, ItemStack, ItemStack>create();

 

ItemStack doesn't have a hashcode() method, so it's just using the default. There's no real way to guarantee that it will arrive at the same hash value for similar stacks, especially when you factor in item counts, NBT, etc. I'm not really sure how this is working for you at all (unless you're only putting 1 of each item in at a time), but it will almost certainly cause you problems down the line.

 

What I've had to do is create a wrapper class that implements hashcode() in a consistent manner:

	@Override
	public int hashCode() {
		// Although it might cause hash collision, we don't hash meta or NBT data. Hash collision should be fairly minimal.
		// We don't hash meta because wildcard meta data wouldn't work.
		// We don't hash NBT because then items with simple NBT data (like renaming in an anvil) would be rejected by the recipe.
		return item.getRegistryName().hashCode();
	}

 

Posted (edited)

i know all the codes are messy because Ive been working on these for quite a long time, how I wrote these code is basically read other mod's source code, but different mod had different setups, which makes me really confused. In the update() function, I tried multiple times to get it to work, so it's really messy but works. For me, the primary target is to make everything to work and then the efficient of the code runs. Thank you for you patients and all replies. I will record a video and what the problems looks like.

 

And no, the code on the github is the latest

 

Edit:

Here is the video

 

As you can see, 2 aluminium bars can produce a aluminium plate. To test the bug, I put 4 aluminium bars into the left workbench, which produces 2 plates, and I put 2 bars into the right one, which should produce only 1 plate, but in the vd, they share the results.

 

Edited by poopoodice
Posted

That is strange. It's even more strange that it the count is 1 at first and then changes it to 2. Since the update() routine is never performed on the client, it's likely not a client/server desync at the tile entity. It seems like it's happening somewhere in the container, but I don't see it.


Unfortunately, I don't have time to debug through all of your code and I can't really run it yourself. You should trace through it and watch it happening step by step. I suggest subclassing ItemStackHandler and override the onContentsChanged. You can even narrow it down by creating an if (slot == 2) {} statement with a dummy operation in it, and add a breakpoint there. When you hit the breakpoint, you can look at the stack trace and see everything that it causing an update to the slot.

 

	@Override
	protected void onContentsChanged(int slot) {
		if (slot == 2) {
			int a = 0; // Breakpoint here
		}
	}

 

  • Thanks 1
Posted
10 hours ago, jaminv said:

output = WorkbenchRecipes.getInstance().getWorkbenchResult(inputs[0], inputs[1]);

Whenever you are interacting with ItemStacks in recipes you need to do ItemStack#copy to create a new instance otherwise you are using the same one for all of them.

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
1 hour ago, jaminv said:

That is strange. It's even more strange that it the count is 1 at first and then changes it to 2. Since the update() routine is never performed on the client, it's likely not a client/server desync at the tile entity. It seems like it's happening somewhere in the container, but I don't see it.


Unfortunately, I don't have time to debug through all of your code and I can't really run it yourself. You should trace through it and watch it happening step by step. I suggest subclassing ItemStackHandler and override the onContentsChanged. You can even narrow it down by creating an if (slot == 2) {} statement with a dummy operation in it, and add a breakpoint there. When you hit the breakpoint, you can look at the stack trace and see everything that it causing an update to the slot.

 


	@Override
	protected void onContentsChanged(int slot) {
		if (slot == 2) {
			int a = 0; // Breakpoint here
		}
	}

 

Thank you, I will try it out

Posted
3 minutes ago, poopoodice said:

Is copyItemStack(ItemStack stack)  What Im looking for? 

Looks like that method is from 1.9.4 so no. Use ItemStack#copy

  • Thanks 1

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

AnimeFan8888 is right about returning ItemStacks. That would definitely cause an issue like this. You should have getWorkbenchResult() return like this:

return ((ItemStack)ent.getValue()).copy();

There's a pretty good chance that will solve your problem. It certainly can't hurt.

 

---

 

I don't know if it helps because it might be total information overload, but the recipe management system for my mod is here: https://github.com/jaminvanderberg/AdvancedMachines/tree/master/src/main/java/jaminv/advancedmachines/util/recipe. It includes a three-ingredient recipe manager that handles ingredients in any order, ore dictionary, etc. There's a lot there because recipe management can get quite complicated. But if it helps, great.

  • Thanks 1
Posted
9 minutes ago, Animefan8888 said:

ItemStack stack = ...;
newStack = stack.copy();

 

9 minutes ago, jaminv said:

AnimeFan8888 is right about returning ItemStacks. That would definitely cause an issue like this. You should have getWorkbenchResult() return like this:


return ((ItemStack)ent.getValue()).copy();

There's a pretty good chance that will solve your problem. It certainly can't hurt.

 

---

 

I don't know if it helps because it might be total information overload, but the recipe management system for my mod is here: https://github.com/jaminvanderberg/AdvancedMachines/tree/master/src/main/java/jaminv/advancedmachines/util/recipe. It includes a three-ingredient recipe manager that handles ingredients in any order, ore dictionary, etc. There's a lot there because recipe management can get quite complicated. But if it helps, great.

Wow, they works! Thank you guys so much, Animefan8888 Ive subscribe to ur channel hope you can upload some nice tutorials, and jaminv thanks for all ur suggestions! :))

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

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • Todas as versões do Minecraft Forge são repentinamente tela preta, mesmo sem mods (tentei reinstalar o Minecraft original, Java, atualizar os drivers não funciona)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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