Jump to content

[1.10.2] Good place to learn about MCMultipart


KeeganDeathman

Recommended Posts

Do any of you know a good place to learn about using MCMultipart? My github crawls have not been fruitful it would seem.(Missing model)

Probably reading the JavaDoc of MCMultipart.

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.

Link to comment
Share on other sites

Upon mashing my face into the block, I find that the model is rendering, but instead of rendering it's texture, it renders invisible and the full sides are obviously still rendering.

 

 

package keegan.labstuff.multipart;

import java.util.*;

import cofh.api.energy.*;
import keegan.labstuff.common.capabilities.*;
import keegan.labstuff.network.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.Optional.Method;

public class PartPowerCable extends PartTransmitter<EnergyAcceptorWrapper, EnergyNetwork> implements IStrictEnergyAcceptor
{

public double currentPower = 0;
public int lastWrite = 0;

public int buffer = 0;

public PartPowerCable()
{
	super();
}

@Override
public void update()
{
	if(getWorld().isRemote)
	{
		double targetPower = getTransmitter().hasTransmitterNetwork() ? getTransmitter().getTransmitterNetwork().clientEnergyScale : 0;

		if(Math.abs(currentPower - targetPower) > 0.01)
		{
			currentPower = (9 * currentPower + targetPower) / 10;
		}
	} 
	else {
		updateShare();

		List<EnumFacing> sides = getConnections(ConnectionType.PULL);

		if(!sides.isEmpty())
		{
			TileEntity[] connectedOutputters = CableUtils.getConnectedOutputters(getPos(), getWorld());
			double canDraw = 100F;

			for(EnumFacing side : sides)
			{
				if(connectedOutputters[side.ordinal()] != null)
				{
					TileEntity outputter = connectedOutputters[side.ordinal()];

					if(CapabilityUtils.hasCapability(outputter, Capabilities.CABLE_OUTPUTTER_CAPABILITY, side.getOpposite()) && CapabilityUtils.hasCapability(outputter, Capabilities.ENERGY_STORAGE_CAPABILITY, side.getOpposite()))
					{
						IStrictEnergyStorage storage = CapabilityUtils.getCapability(outputter, Capabilities.ENERGY_STORAGE_CAPABILITY, side.getOpposite());
						double received = Math.min(storage.getEnergy(), canDraw);
						double toDraw = received;

						if(received > 0)
						{
							toDraw -= takeEnergy(received, true);
						}

						storage.setEnergy(storage.getEnergy() - toDraw);
					}

				}
			}
		}
	}

	super.update();
}

    @Override
    public void updateShare()
    {
        if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
        {
            int last = getSaveShare();

            if(last != lastWrite)
            {
                lastWrite = last;
                markDirty();
            }
        }
    }

private int getSaveShare()
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		return (int) EnergyNetwork.round(getTransmitter().getTransmitterNetwork().buffer * (1F / getTransmitter().getTransmitterNetwork().transmitters.size()));
	}
	else {
		return buffer;
	}
}

@Override
public TransmitterType getTransmitterType()
{
	return TransmitterType.POWER_CABLE;
}

@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
	super.readFromNBT(nbtTags);

	buffer = nbtTags.getInteger("cacheEnergy");
	if(buffer < 0) buffer = 0;

}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTags)
{
	super.writeToNBT(nbtTags);

	nbtTags.setInteger("cacheEnergy", lastWrite);

	return nbtTags;
}

@Override
public ResourceLocation getType()
{
	return new ResourceLocation("labstuff:blockPowerCable");
}

@Override
public TransmissionType getTransmissionType()
{
	return TransmissionType.ENERGY;
}

@Override
public EnergyNetwork createNetworkByMerging(Collection<EnergyNetwork> networks)
{
	return new EnergyNetwork(networks);
}

@Override
public boolean isValidAcceptor(TileEntity acceptor, EnumFacing side)
{
	return CableUtils.isValidAcceptorOnSide(getWorld().getTileEntity(getPos()), acceptor, side);
}

@Override
public EnergyNetwork createNewNetwork()
{
	return new EnergyNetwork();
}

@Override
public Object getBuffer()
{
	return buffer;
}

@Override
public void takeShare()
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		getTransmitter().getTransmitterNetwork().buffer -= lastWrite;
		buffer = lastWrite;
	}
}

@Override
public int getCapacity()
{
	return Integer.MAX_VALUE;
}

@Override
public double transferEnergyToAcceptor(EnumFacing side, double amount)
{
	if(!canReceiveEnergy(side))
	{
		return 0;
	}

	double toUse = Math.min(getMaxEnergy() - getEnergy(), amount);
	setEnergy(getEnergy() + toUse);

	return toUse;
}

@Override
public boolean canReceiveEnergy(EnumFacing side)
{
	return getConnectionType(side) == ConnectionType.NORMAL;
}

@Override
public double getMaxEnergy()
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		return getTransmitter().getTransmitterNetwork().getCapacity();
	} 
	else {
		return getCapacity();
	}
}

@Override
public double getEnergy()
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		return getTransmitter().getTransmitterNetwork().buffer;
	} 
	else {
		return buffer;
	}
}

@Override
public void setEnergy(double energy)
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		getTransmitter().getTransmitterNetwork().buffer = (int) energy;
	} 
	else {
		buffer = (int) energy;
	}
}
public double takeEnergy(double energy, boolean doEmit)
{
	if(getTransmitter().hasTransmitterNetwork())
	{
		return getTransmitter().getTransmitterNetwork().emit(energy, doEmit);
	}
	else {
		double used = Math.min(getCapacity() - buffer, energy);

		if(doEmit)
		{
			buffer += used;
		}

		return energy - used;
	}
}

@Override
public EnergyAcceptorWrapper getCachedAcceptor(EnumFacing side)
{
	return EnergyAcceptorWrapper.get(getCachedTile(side), side.getOpposite());
}


@Override
public void readUpdatePacket(PacketBuffer packet)
{

	super.readUpdatePacket(packet);
}

@Override
public void writeUpdatePacket(PacketBuffer packet)
{

	super.writeUpdatePacket(packet);
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
	return capability == Capabilities.ENERGY_STORAGE_CAPABILITY
			|| capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY
			|| super.hasCapability(capability, facing);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
	if(capability == Capabilities.ENERGY_STORAGE_CAPABILITY || capability == Capabilities.ENERGY_ACCEPTOR_CAPABILITY)
	{
		return (T)this;
	}

	return super.getCapability(capability, facing);
}
}

 

 

 

package keegan.labstuff.multipart;

import java.util.*;

import keegan.labstuff.common.Coord4D;
import keegan.labstuff.common.capabilities.Capabilities;
import keegan.labstuff.network.*;
import keegan.labstuff.network.DynamicNetwork.NetworkClientRequest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;

public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends PartSidedPipe
{
public MultipartTransmitter<A, N> transmitterDelegate;

public boolean unloaded = true;

public boolean dataRequest = false;

public PartTransmitter()
{
	transmitterDelegate = new MultipartTransmitter<>(this);
}

public MultipartTransmitter<A, N> getTransmitter()
{
	return transmitterDelegate;
}

public abstract N createNewNetwork();

public abstract N createNetworkByMerging(Collection<N> networks);

@Override
public void onWorldJoin()
{
	if(!getWorld().isRemote)
	{
		TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
	}

	unloaded = false;
}

@Override
public void update()
{
	super.update();

	if(getWorld().isRemote)
	{
		if(!dataRequest)
		{
			dataRequest = true;
			MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(getWorld().getTileEntity(getPos())));
		}
	}
}

@Override
public void onUnloaded()
{
	if(!getWorld().isRemote)
	{
		getTransmitter().takeShare();
	}

	super.onUnloaded();
}

@Override
public void onWorldSeparate() 
{
	unloaded = true;

	if(!getWorld().isRemote)
	{
		TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
	}
	else {
		getTransmitter().setTransmitterNetwork(null);
	}
}

@Override
public void markDirtyTransmitters()
{
	super.markDirtyTransmitters();

	if(getTransmitter().hasTransmitterNetwork())
	{
		TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
	}
}

@Override
public void markDirtyAcceptor(EnumFacing side)
{
	super.markDirtyAcceptor(side);

	if(getTransmitter().hasTransmitterNetwork())
	{
		getTransmitter().getTransmitterNetwork().acceptorChanged(getTransmitter(), side);
	}
}

public abstract A getCachedAcceptor(EnumFacing side);

protected TileEntity getCachedTile(EnumFacing side)
{
	ConnectionType type = connectionTypes[side.ordinal()];

	if(type == ConnectionType.PULL || type == ConnectionType.NONE)
	{
		return null;
	}

	return connectionMapContainsSide(currentAcceptorConnections, side) ? cachedAcceptors[side.ordinal()] : null;
}

public abstract int getCapacity();

public abstract Object getBuffer();

public abstract void takeShare();

    public abstract void updateShare();

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing side)
{
	return capability == Capabilities.GRID_TRANSMITTER_CAPABILITY
			|| super.hasCapability(capability, side);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing side)
{
	if(capability == Capabilities.GRID_TRANSMITTER_CAPABILITY)
	{
		return (T)getTransmitter();
	}

	return super.getCapability(capability, side);
}
}

 

 

 

package keegan.labstuff.multipart;

import java.util.*;

import io.netty.buffer.ByteBuf;
import keegan.labstuff.LabStuffMain;
import keegan.labstuff.common.*;
import keegan.labstuff.common.capabilities.*;
import keegan.labstuff.network.*;
import keegan.labstuff.network.TransmitterType.Size;
import mcmultipart.MCMultiPartMod;
import mcmultipart.block.TileMultipartContainer;
import mcmultipart.multipart.*;
import mcmultipart.raytrace.*;
import mcmultipart.raytrace.RayTraceUtils.AdvancedRayTraceResultPart;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.*;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.client.model.obj.OBJModel.*;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.property.*;

public abstract class PartSidedPipe extends Multipart implements INormallyOccludingPart, /*ISlotOccludingPart, ISidedHollowConnect, JIconHitEffects, INeighborTileChange,*/ ITileNetwork, IBlockableConnection, ITransmitter, ITickable
{
public static AxisAlignedBB[] smallSides = new AxisAlignedBB[7];
public static AxisAlignedBB[] largeSides = new AxisAlignedBB[7];

public int delayTicks;

public EnumFacing testingSide = null;

public byte currentAcceptorConnections = 0x00;
public byte currentTransmitterConnections = 0x00;

public boolean sendDesc = false;
public boolean redstonePowered = false;

public boolean redstoneReactive = false;

public boolean forceUpdate = true;

public boolean redstoneSet = false;

public ConnectionType[] connectionTypes = {ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL};
public TileEntity[] cachedAcceptors = new TileEntity[6];

static
{
	smallSides[0] = new AxisAlignedBB(0.3, 0.0, 0.3, 0.7, 0.3, 0.7);
	smallSides[1] = new AxisAlignedBB(0.3, 0.7, 0.3, 0.7, 1.0, 0.7);
	smallSides[2] = new AxisAlignedBB(0.3, 0.3, 0.0, 0.7, 0.7, 0.3);
	smallSides[3] = new AxisAlignedBB(0.3, 0.3, 0.7, 0.7, 0.7, 1.0);
	smallSides[4] = new AxisAlignedBB(0.0, 0.3, 0.3, 0.3, 0.7, 0.7);
	smallSides[5] = new AxisAlignedBB(0.7, 0.3, 0.3, 1.0, 0.7, 0.7);
	smallSides[6] = new AxisAlignedBB(0.3, 0.3, 0.3, 0.7, 0.7, 0.7);

	largeSides[0] = new AxisAlignedBB(0.25, 0.0, 0.25, 0.75, 0.25, 0.75);
	largeSides[1] = new AxisAlignedBB(0.25, 0.75, 0.25, 0.75, 1.0, 0.75);
	largeSides[2] = new AxisAlignedBB(0.25, 0.25, 0.0, 0.75, 0.75, 0.25);
	largeSides[3] = new AxisAlignedBB(0.25, 0.25, 0.75, 0.75, 0.75, 1.0);
	largeSides[4] = new AxisAlignedBB(0.0, 0.25, 0.25, 0.25, 0.75, 0.75);
	largeSides[5] = new AxisAlignedBB(0.75, 0.25, 0.25, 1.0, 0.75, 0.75);
	largeSides[6] = new AxisAlignedBB(0.25, 0.25, 0.25, 0.75, 0.75, 0.75);
}

public static IMultipart getPartType(TransmitterType type)
{
	switch(type)
	{
		case POWER_CABLE:
			return new PartPowerCable();
		default:
			return null;
	}
}

public static boolean connectionMapContainsSide(byte connections, EnumFacing side)
{
	byte tester = (byte)(1 << side.ordinal());
	return (connections & tester) > 0;
}

public static byte setConnectionBit(byte connections, boolean toSet, EnumFacing side)
{
	return (byte)((connections & ~(byte)(1 << side.ordinal())) | (byte)((toSet ? 1 : 0) << side.ordinal()));
}

@Override
public void update()
{
	if(getWorld().isRemote)
	{
		if(delayTicks == 5)
		{
			delayTicks = 6; /* don't refresh again */
			refreshConnections();
		}
		else if(delayTicks < 5)
		{
			delayTicks++;
		}
	}

	if(!getWorld().isRemote)
	{
		if(forceUpdate)
		{
			refreshConnections();
			forceUpdate = false;
		}

		if(sendDesc)
		{
			sendUpdatePacket();
			sendDesc = false;
		}
	}
}

public boolean handlesRedstone()
{
	return true;
}

public boolean renderCenter()
{
	return false;
}

public boolean transparencyRender()
{
	return false;
}

public byte getPossibleTransmitterConnections()
{
	byte connections = 0x00;

	if(handlesRedstone() && redstoneReactive && redstonePowered)
	{
		return connections;
	}

	for(EnumFacing side : EnumFacing.values())
	{
		if(canConnectMutual(side))
		{
			TileEntity tileEntity = getWorld().getTileEntity(getPos().offset(side));

			if(tileEntity != null && CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, side.getOpposite())
					&& TransmissionType.checkTransmissionType(CapabilityUtils.getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, side.getOpposite()), getTransmitterType().getTransmission())
					&& isValidTransmitter(tileEntity))
			{
				connections |= 1 << side.ordinal();
			}
		}
	}

	return connections;
}

public boolean getPossibleAcceptorConnection(EnumFacing side)
{
	if(handlesRedstone() && redstoneReactive && redstonePowered)
	{
		return false;
	}

	if(canConnectMutual(side))
	{
		TileEntity tileEntity = getWorld().getTileEntity(getPos().offset(side));

		if(isValidAcceptor(tileEntity, side))
		{
			if(cachedAcceptors[side.ordinal()] != tileEntity)
			{
				cachedAcceptors[side.ordinal()] = tileEntity;
				markDirtyAcceptor(side);
			}

			return true;
		}
	}

	if(cachedAcceptors[side.ordinal()] != null)
	{
		cachedAcceptors[side.ordinal()] = null;
		markDirtyAcceptor(side);
	}

	return false;
}

public boolean getPossibleTransmitterConnection(EnumFacing side)
{
	if(handlesRedstone() && redstoneReactive && redstonePowered)
	{
		return false;
	}

	if(canConnectMutual(side))
	{
		TileEntity tileEntity = getWorld().getTileEntity(getPos().offset(side));

		if(CapabilityUtils.hasCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, side.getOpposite())
				&& TransmissionType.checkTransmissionType(CapabilityUtils.getCapability(tileEntity, Capabilities.GRID_TRANSMITTER_CAPABILITY, side.getOpposite()), getTransmitterType().getTransmission())
				&& isValidTransmitter(tileEntity))
		{
			return true;
		}
	}

	return false;
}

public byte getPossibleAcceptorConnections()
{
	byte connections = 0x00;

	if(handlesRedstone() && redstoneReactive && redstonePowered)
	{
		return connections;
	}

	for(EnumFacing side : EnumFacing.values())
	{
		if(canConnectMutual(side))
		{
			Coord4D coord = new Coord4D(getPos(), getWorld()).offset(side);

			if(!getWorld().isRemote && !coord.exists(getWorld()))
			{
				forceUpdate = true;
				continue;
			}

			TileEntity tileEntity = coord.getTileEntity(getWorld());

			if(isValidAcceptor(tileEntity, side))
			{
				if(cachedAcceptors[side.ordinal()] != tileEntity)
				{
					cachedAcceptors[side.ordinal()] = tileEntity;
					markDirtyAcceptor(side);
				}

				connections |= 1 << side.ordinal();
				continue;
			}
		}

		if(cachedAcceptors[side.ordinal()] != null)
		{
			cachedAcceptors[side.ordinal()] = null;
			markDirtyAcceptor(side);
		}
	}

	return connections;
}

public byte getAllCurrentConnections()
{
	return (byte)(currentTransmitterConnections | currentAcceptorConnections);
}

protected boolean isValidTransmitter(TileEntity tileEntity)
{
	return true;
}

@Override
public float getHardness(PartMOP partHit)
{
	return 3.5F;
}

/*
@Override
public boolean occlusionTest(IMultipart other)
{
	return NormalOcclusionTest.apply(this, other);
}
*/

@Override
public void addSelectionBoxes(List<AxisAlignedBB> list)
{
	if(getContainer() != null)
	{
		for(EnumFacing side : EnumFacing.values())
		{
			int ord = side.ordinal();
			byte connections = getAllCurrentConnections();

			if(connectionMapContainsSide(connections, side) || side == testingSide)
			{
				list.add(getTransmitterType().getSize() == Size.SMALL ? smallSides[ord] : largeSides[ord]);
			}
		}
	}

	list.add(getTransmitterType().getSize() == Size.SMALL ? smallSides[6] : largeSides[6]);
}

public abstract TransmitterType getTransmitterType();

@Override
public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity)
{
	if(getContainer() != null)
	{
		for(EnumFacing side : EnumFacing.values())
		{
			int ord = side.ordinal();
			byte connections = getAllCurrentConnections();

			if(connectionMapContainsSide(connections, side) || side == testingSide)
			{
				AxisAlignedBB box = getTransmitterType().getSize() == Size.SMALL ? smallSides[ord] : largeSides[ord];
				if(box.intersectsWith(mask)) list.add(box);
			}
		}
	}

	AxisAlignedBB box = getTransmitterType().getSize() == Size.SMALL ? smallSides[6] : largeSides[6];
	if(box.intersectsWith(mask)) list.add(box);
}

@Override
public void addOcclusionBoxes(List<AxisAlignedBB> list)
{
	addSelectionBoxes(list);
}
/*
@Override
public EnumSet<PartSlot> getSlotMask()
{
	return EnumSet.of(PartSlot.CENTER);
}

@Override
public EnumSet<PartSlot> getOccludedSlots()
{
	return EnumSet.of(PartSlot.CENTER); //TODO implement properly
}

@Override
public TextureAtlasSprite getBreakingIcon(Object subPart, EnumFacing side)
{
	return getCenterIcon(true);
}

@Override
public TextureAtlasSprite getBrokenIcon(EnumFacing side)
{
	return getCenterIcon(true);
}

@Override
public Cuboid6 getBounds()
{
	return getTransmitterType().getSize() == Size.SMALL ? smallSides[6] : largeSides[6];
}

@Override
public int getHollowSize(EnumFacing side)
{
	EnumFacing direction = EnumFacing.getOrientation(side);

	if(connectionMapContainsSide(getAllCurrentConnections(), direction) || direction == testingSide)
	{
		return getTransmitterType().getSize().centerSize+1;
	}

	return 0;
}
*/

public abstract boolean isValidAcceptor(TileEntity tile, EnumFacing side);

@Override
public boolean canConnectMutual(EnumFacing side)
{
	if(!canConnect(side)) return false;

	TileEntity tile = getWorld().getTileEntity(getPos().offset(side));

	if(!CapabilityUtils.hasCapability(tile, Capabilities.BLOCKABLE_CONNECTION_CAPABILITY, side.getOpposite()))
	{
		return true;
	}

	return CapabilityUtils.getCapability(tile, Capabilities.BLOCKABLE_CONNECTION_CAPABILITY, side.getOpposite()).canConnect(side.getOpposite());
}

@Override
public boolean canConnect(EnumFacing side)
{

	testingSide = side;
	IMultipart testPart = new OcclusionHelper.NormallyOccludingPart(getTransmitterType().getSize() == Size.SMALL ? smallSides[side.ordinal()] : largeSides[side.ordinal()]);
	boolean unblocked = OcclusionHelper.occlusionTest(testPart, (part) -> part==this, getContainer().getParts());//getContainer().canReplacePart(this, this);
	testingSide = null;

	return unblocked;
}

@Override
public void readUpdatePacket(PacketBuffer packet)
{
	currentTransmitterConnections = packet.readByte();
	currentAcceptorConnections = packet.readByte();

	for(int i = 0; i < 6; i++)
	{
		connectionTypes[i] = ConnectionType.values()[packet.readInt()];
	}

	notifyPartUpdate();
	markRenderUpdate();
}

@Override
public void writeUpdatePacket(PacketBuffer packet)
{
	packet.writeByte(currentTransmitterConnections);
	packet.writeByte(currentAcceptorConnections);

	for(int i = 0; i < 6; i++)
	{
		packet.writeInt(connectionTypes[i].ordinal());
	}
}

@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
	super.readFromNBT(nbtTags);

	redstoneReactive = nbtTags.getBoolean("redstoneReactive");

	for(int i = 0; i < 6; i++)
	{
		connectionTypes[i] = ConnectionType.values()[nbtTags.getInteger("connection" + i)];
	}
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTags)
{
	super.writeToNBT(nbtTags);

	nbtTags.setBoolean("redstoneReactive", redstoneReactive);

	for(int i = 0; i < 6; i++)
	{
		nbtTags.setInteger("connection" + i, connectionTypes[i].ordinal());
	}

	return nbtTags;
}

@Override
public boolean onActivated(EntityPlayer player, EnumHand hand, ItemStack stack, PartMOP hit)
{
	if(stack == null)
	{
		return false;
	}

	return false;
}

@Override
public List<ItemStack> getDrops()
{
	return Collections.singletonList(getPickBlock(null, null));
}

@Override
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit)
{
	return new ItemStack(LabStuffMain.itemPartTransmitter, 1, getTransmitterType().ordinal());
}

protected void onRefresh() {}

public void refreshConnections()
{

	if(!getWorld().isRemote)
	{
		byte possibleTransmitters = getPossibleTransmitterConnections();
		byte possibleAcceptors = getPossibleAcceptorConnections();

		if((possibleTransmitters | possibleAcceptors) != getAllCurrentConnections())
		{
			sendDesc = true;
		}

		currentTransmitterConnections = possibleTransmitters;
		currentAcceptorConnections = possibleAcceptors;
	}
}

public void refreshConnections(EnumFacing side)
{
	if(!getWorld().isRemote)
	{
		boolean possibleTransmitter = getPossibleTransmitterConnection(side);
		boolean possibleAcceptor = getPossibleAcceptorConnection(side);

		if((possibleTransmitter || possibleAcceptor) != connectionMapContainsSide(getAllCurrentConnections(), side))
		{
			sendDesc = true;
		}

		currentTransmitterConnections = setConnectionBit(currentTransmitterConnections, possibleTransmitter, side);
		currentAcceptorConnections = setConnectionBit(currentAcceptorConnections, possibleAcceptor, side);
	}
}

protected void onModeChange(EnumFacing side)
{
	markDirtyAcceptor(side);
}

protected void markDirtyTransmitters()
{
	notifyTileChange();
}

protected void markDirtyAcceptor(EnumFacing side) {}

public abstract void onWorldJoin();

public abstract void onWorldSeparate();

@Override
public void onRemoved()
{
	onWorldSeparate();
	super.onRemoved();
}

@Override
public void onUnloaded()
{
	onWorldSeparate();
	super.onRemoved();
}

@Override
public void onAdded()
{
	onWorldJoin();
	super.onAdded();

	refreshConnections();
}

@Override
public void onLoaded()
{
	onWorldJoin();
	super.onLoaded();
}

@Override
public void onNeighborTileChange(EnumFacing side) 
{
	refreshConnections(side);
}

@Override
public void onNeighborBlockChange(Block block)
{
	if(handlesRedstone())
	{
		boolean prevPowered = redstonePowered;
		refreshConnections();

		if(prevPowered != redstonePowered)
		{
			markDirtyTransmitters();
		}
	}
	else {
		refreshConnections();
	}
}

@Override
public void onPartChanged(IMultipart part)
{
	super.onPartChanged(part);

	byte transmittersBefore = currentTransmitterConnections;
	refreshConnections();

	if(transmittersBefore != currentTransmitterConnections)
	{
		markDirtyTransmitters();
	}
}

@Override
public void handlePacketData(ByteBuf dataStream) throws Exception {}

@Override
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
{
	return data;
}

public ConnectionType getConnectionType(EnumFacing side)
{
	return getConnectionType(side, getAllCurrentConnections(), currentTransmitterConnections, connectionTypes);
}

public static ConnectionType getConnectionType(EnumFacing side, byte allConnections, byte transmitterConnections, ConnectionType[] types)
{
	if(!connectionMapContainsSide(allConnections, side))
	{
		return ConnectionType.NONE;
	}
	else if(connectionMapContainsSide(transmitterConnections, side))
	{
		return ConnectionType.NORMAL;
	}

	return types[side.ordinal()];
}

public List<EnumFacing> getConnections(ConnectionType type)
{
	List<EnumFacing> sides = new ArrayList<EnumFacing>();

	for(EnumFacing side : EnumFacing.values())
	{
		if(getConnectionType(side) == type)
		{
			sides.add(side);
		}
	}

	return sides;
}

private PartMOP reTrace(World world, BlockPos pos, EntityPlayer player) 
{
	Vec3d start = RayTraceUtils.getStart(player);
	Vec3d end = RayTraceUtils.getEnd(player);
	AdvancedRayTraceResultPart result = ((TileMultipartContainer)world.getTileEntity(pos)).getPartContainer().collisionRayTrace(start, end);

	return result == null ? null : result.hit;
}

protected EnumFacing sideHit(int boxIndex)
{
	List<EnumFacing> list = new ArrayList<>();

	if(getContainer() != null)
	{
		for(EnumFacing side : EnumFacing.values())
		{
			int ord = side.ordinal();
			byte connections = getAllCurrentConnections();

			if(connectionMapContainsSide(connections, side))
			{
				list.add(side);
			}
		}
	}

	if(boxIndex < list.size()) return list.get(boxIndex);

	return null;
}

protected EnumActionResult onConfigure(EntityPlayer player, int part, EnumFacing side)
{
	return EnumActionResult.PASS;
}

@Override
public ResourceLocation getModelPath()
{
	return getType();
}

@Override
public BlockStateContainer createBlockState()
{
	return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[0], new IUnlistedProperty[] {OBJProperty.INSTANCE, ConnectionProperty.INSTANCE});
}

public List<String> getVisibleGroups()
{
	List<String> visible = new ArrayList<>();

	for(EnumFacing side : EnumFacing.values())
	{
		visible.add(side.getName() + getConnectionType(side).getName().toUpperCase());
	}

	return visible;
}

@Override
public IBlockState getExtendedState(IBlockState state)
{
	ConnectionProperty connectionProp = new ConnectionProperty(getAllCurrentConnections(), currentTransmitterConnections, connectionTypes, renderCenter());

	return ((IExtendedBlockState)state).withProperty(OBJProperty.INSTANCE, new OBJState(getVisibleGroups(), true)).withProperty(ConnectionProperty.INSTANCE, connectionProp);
}

@Override
public boolean canRenderInLayer(BlockRenderLayer layer) 
{
	return layer == BlockRenderLayer.CUTOUT || (transparencyRender() && layer == BlockRenderLayer.TRANSLUCENT);
}

public void notifyTileChange()
{
	LabStuffUtils.notifyLoadedNeighborsOfTileChange(getWorld(), new Coord4D(getPos(), getWorld()));
}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
	return capability == Capabilities.BLOCKABLE_CONNECTION_CAPABILITY || super.hasCapability(capability, facing);
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
	if(capability == Capabilities.BLOCKABLE_CONNECTION_CAPABILITY)
	{
		return (T)this;
	}

	return super.getCapability(capability, facing);
}

public static enum ConnectionType implements IStringSerializable
{
	NORMAL,
	PUSH,
	PULL,
	NONE;

	public ConnectionType next()
	{
		if(ordinal() == values().length-1)
		{
			return NORMAL;
		}

		return values()[ordinal()+1];
	}

	@Override
	public String getName()
	{
		return name().toLowerCase();
	}
}

@Override
public boolean shouldBreakingUseExtendedState() {
	return true;
}
}

 

 

This was a lot of late night github crawls so it may be stupid simple

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

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.



×
×
  • Create New...

Important Information

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