Jump to content

Recommended Posts

Posted

Hello, I had made a pipe block that worked fine and I just had one thing left to do, convert it to a Forge Multipart. I got the block code to convert just fine, but I have been having issues with the Tile Entity code. My problem is that I can't seem to find a way to access the multi part itself when in the world. What I mean by accessing the multi part, I mean that I have code in other Tile Entities and in non converted Tile Entities of the pipe block that check to see if one of the adjacent blocks around them are instances of the Pipe Tile Entity. I use this information for rendering a transferring data. The issue that I am facing is that I can check if the adjacent blocks are instances of TileMultipart, but I cannot seem to figure out how to check if there is a pipe part in the block space. All help is appreciated, Thank You.

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Posted

What you are trying to do sounds very possible. However we are going to need some code to glance at to fully understand the situation. I'll be honest, I probably won't be a ton of help but the others will need code.

An average guy who mods Minecraft. If you need help and are willing to use your brain, don't be afraid to ask.

 

Also, check out the Unofficial Minecraft Coder Pack (MCP) Prerelease Center for the latest from the MCP Team!

 

Was I helpful? Leave some karma/thanks! :)

Posted

In the TileMultipart, there's a List/Seq (

partList

for Scala,

jPartList()

for Java). You can iterate through it and check if the TMultipart is an instance of your pipe.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Does any one know of any open source mod that has a tile entity implemented with a forge multi part, so I can have a better understanding of how to efficiently do stuff.

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Posted

Does any one know of any open source mod that has a tile entity implemented with a forge multi part, so I can have a better understanding of how to efficiently do stuff.

Project Red makes extensive use of multiparts.

 

Also Forge Multipart itself includes multipart versions of some vanilla items such as torches and levers.

 

Finally, for what it's worth, here's some code of my own (incomplete) implementing a pipe part. The canConnectToTube() method contains an example of looking at a tile entity to see whether it contains another pipe part. It's a bit specialised, because my pipes are always centre parts and therefore can only appear in slot 6 of the part list. In the general case you would have to iterate over partMap.

 

 

//------------------------------------------------------------------------------------------------
//
//   Project Blue - Pneumatic Tube Part
//
//------------------------------------------------------------------------------------------------

package gcewing.projectblue;

import java.util.*;
import net.minecraft.inventory.*;
import net.minecraft.nbt.*;
import net.minecraft.tileentity.*;
import net.minecraft.util.*;
import net.minecraftforge.common.util.*;
import codechicken.microblock.*;
import codechicken.multipart.*;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.lib.data.*;
import codechicken.lib.lighting.*;
import codechicken.lib.raytracer.*;
import codechicken.lib.vec.*;

public class PneumaticTubePart extends JCenterPart implements IHollowConnect {

final static int tubeWidth = 6; // sixteenths
final static double h = 0.5 * (tubeWidth / 16.0);
static Cuboid6 centerBox = new Cuboid6(0.5 - h, 0.5 - h, 0.5 - h, 0.5 + h, 0.5 + h, 0.5 + h);
static Cuboid6[] sideBoxes = new Cuboid6[6];
static {
	for (int i = 0; i < 6; i++) {
		Transformation t = Rotation.sideRotations[i].at(codechicken.lib.vec.Vector3.center);
		sideBoxes[i] = new Cuboid6(0.5 - h, 0, 0.5 - h, 0.5 + h, 0.5 - h, 0.5 + h).apply(t);
	}
}

public int connections = 0;
public Collection<TubePayload> payloads;

public boolean isConnectedOnSide(int i) {
	return (connections & (1 << i)) != 0;
}

@Override
public String getType() {
	return "pb_pneumatictube";
}

@Override
public int getHollowSize() {
	return tubeWidth;
}

@Override
public Iterable<Cuboid6> getCollisionBoxes() {
	List<Cuboid6> result = new ArrayList<Cuboid6>();
	result.add(centerBox);
	for (int i = 0; i < 6; i++)
		if (isConnectedOnSide(i))
			result.add(sideBoxes[i]);
	return result;
}

@Override
public Iterable<IndexedCuboid6> getSubParts() {
	List<IndexedCuboid6> result = new ArrayList<IndexedCuboid6>();
	result.add(new IndexedCuboid6(6, centerBox));
	for (int i = 0; i < 6; i++)
		if (isConnectedOnSide(i))
			result.add(new IndexedCuboid6(i, sideBoxes[i]));
	return result;
}

@Override
public void writeDesc(MCDataOutput data) {
	data.writeByte(connections & 0xff);
}

@Override
public void readDesc(MCDataInput data) {
	connections = data.readByte();
}

@Override
public void save(NBTTagCompound nbt) {
	nbt.setInteger("connections", connections);
}

@Override
public void load(NBTTagCompound nbt) {
	connections = nbt.getInteger("connections");
}

@Override
public void renderStatic(codechicken.lib.vec.Vector3 pos, LazyLightMatrix olm, int pass) {
	if (pass == 0)
		PneumaticTubeRenderer.renderStaticInWorld(this, pos.x, pos.y, pos.z);
}

//	@Override
//	public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) {
//	}

//	@Override
//	public void drawBreaking(RenderBlocks rb) {
//	}

@Override
public void onAdded() {
	if (!world().isRemote)
		updateConnections();
}

@Override
public void onPartChanged(TMultiPart part) {
	if (!world().isRemote)
		updateConnections();
}

@Override
public void onNeighborChanged() {
	if (!world().isRemote)
		updateConnections();
}

void updateConnections() {
	int mask = 0;
	for (int i = 0; i < 6; i++) {
		ForgeDirection d = ForgeDirection.getOrientation(i);
		TileEntity te = world().getTileEntity(x() + d.offsetX, y() + d.offsetY, z() + d.offsetZ);
		if (canConnectToTube(te, i ^ 1)) {
			if (tubeCanConnect(this, i))
				mask |= 1 << i;
		}
	}
	if (connections != mask) {
		connections = mask;
		tile().markDirty();
		sendDescUpdate();
	}
}

static boolean canConnectToTube(TileEntity te, int side) {
	if (te instanceof IInventory)
		return true;
	if (te instanceof TileMultipart) {
		TileMultipart tmp = (TileMultipart)te;
		TMultiPart part = tmp.partMap(6);
		if (part instanceof PneumaticTubePart)
			return tubeCanConnect(part, side);
	}
	return false;
}

static boolean tubeCanConnect(TMultiPart tube, int side) {
	TMultiPart part = tube.tile().partMap(side);
	if (part == null)
		return true;
	if (part instanceof TFacePart) {
		TFacePart f = (TFacePart)part;
		return (f.redstoneConductionMap() & (1 << side)) != 0;
	}
	return false;
}

//------------------------------------------------------------------------------------------------

public static class Factory implements IPartFactory {

	public TMultiPart createPart(String name, boolean client) {
		return new PneumaticTubePart();
	}

}

}

 

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

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • 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" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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