Fixed some issues with saving the parts, and broke the movement even more

This commit is contained in:
modmuss50 2016-05-12 21:37:24 +01:00
parent b0fbd5aea0
commit 560147e3b5
7 changed files with 99 additions and 42 deletions

View file

@ -6,14 +6,16 @@ import javax.annotation.Nullable;
import mcmultipart.multipart.MultipartRegistry;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import reborncore.common.packets.AddDiscriminatorEvent;
import techreborn.compat.ICompatModule;
import techreborn.parts.fluidPipes.ItemFluidPipe;
import techreborn.parts.fluidPipes.MultipartFluidPipe;
import techreborn.parts.fluidPipes.*;
import techreborn.parts.powerCables.CableMultipart;
import techreborn.parts.powerCables.EnumCableType;
import techreborn.parts.powerCables.ItemCables;
@ -35,7 +37,7 @@ public class TechRebornParts implements ICompatModule
@Override
public void preInit(FMLPreInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(this);
}
@Override
@ -50,7 +52,9 @@ public class TechRebornParts implements ICompatModule
cables.setRegistryName("cables");
GameRegistry.register(cables);
MultipartRegistry.registerPart(MultipartFluidPipe.class, "techreborn:fluidpipe");
MultipartRegistry.registerPart(EmptyFluidPipe.class, "techreborn:fluidpipe.empty");
MultipartRegistry.registerPart(InsertingFluidPipe.class, "techreborn:fluidpipe.inserting");
MultipartRegistry.registerPart(ExtractingFluidPipe.class, "techreborn:fluidpipe.extracting");
fluidPipe = new ItemFluidPipe();
fluidPipe.setRegistryName("fluidPipe");
GameRegistry.register(fluidPipe);

View file

@ -0,0 +1,11 @@
package techreborn.parts.fluidPipes;
/**
* Created by modmuss50 on 12/05/2016.
*/
public class EmptyFluidPipe extends MultipartFluidPipe {
@Override
public EnumFluidPipeTypes getPipeType() {
return EnumFluidPipeTypes.EMPTY;
}
}

View file

@ -0,0 +1,11 @@
package techreborn.parts.fluidPipes;
/**
* Created by modmuss50 on 12/05/2016.
*/
public class ExtractingFluidPipe extends MultipartFluidPipe {
@Override
public EnumFluidPipeTypes getPipeType() {
return EnumFluidPipeTypes.EXTRACT;
}
}

View file

@ -0,0 +1,10 @@
package techreborn.parts.fluidPipes;
/**
* Created by modmuss50 on 12/05/2016.
*/
public interface IPartType {
EnumFluidPipeTypes getPipeType();
}

View file

@ -0,0 +1,11 @@
package techreborn.parts.fluidPipes;
/**
* Created by modmuss50 on 12/05/2016.
*/
public class InsertingFluidPipe extends MultipartFluidPipe {
@Override
public EnumFluidPipeTypes getPipeType() {
return EnumFluidPipeTypes.INSERT;
}
}

View file

@ -24,6 +24,6 @@ public class ItemFluidPipe extends ItemMultiPart {
@Override
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack, EntityPlayer player) {
return new MultipartFluidPipe();
return new EmptyFluidPipe();
}
}

View file

@ -2,6 +2,7 @@ package techreborn.parts.fluidPipes;
import com.mojang.realmsclient.gui.ChatFormatting;
import mcmultipart.MCMultiPartMod;
import mcmultipart.block.TileMultipartContainer;
import mcmultipart.microblock.IMicroblock;
import mcmultipart.multipart.*;
import mcmultipart.raytrace.PartMOP;
@ -16,6 +17,7 @@ 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.AxisAlignedBB;
@ -32,10 +34,8 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import reborncore.common.misc.Functions;
import reborncore.common.misc.vecmath.Vecs3dCube;
import reborncore.common.util.ChatUtils;
import reborncore.common.util.StringUtils;
import reborncore.common.util.Tank;
import reborncore.common.util.WorldUtils;
import reborncore.common.packets.PacketHandler;
import reborncore.common.util.*;
import techreborn.parts.TechRebornParts;
import java.util.*;
@ -43,7 +43,7 @@ import java.util.*;
/**
* Created by modmuss50 on 09/05/2016.
*/
public class MultipartFluidPipe extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable {
public abstract class MultipartFluidPipe extends Multipart implements INormallyOccludingPart, ISlottedPart, ITickable, IPartType {
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down"));
@ -58,7 +58,6 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
public float center = 0.6F;
public float offset = 0.10F;
public Map<EnumFacing, BlockPos> connectedSides;
EnumFluidPipeTypes currentType = EnumFluidPipeTypes.EMPTY;
Tank tank = new Tank("MultipartFluidPipe", 1000, null);
public MultipartFluidPipe() {
@ -202,8 +201,8 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
} else {
TileEntity tile = getNeighbourTile(dir);
if (tile instanceof IFluidHandler && (currentType == EnumFluidPipeTypes.EXTRACT
|| currentType == EnumFluidPipeTypes.INSERT)) {
if (tile instanceof IFluidHandler && (getPipeType() == EnumFluidPipeTypes.EXTRACT
|| getPipeType() == EnumFluidPipeTypes.INSERT)) {
return true;
}
}
@ -260,7 +259,7 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
.withProperty(UP, shouldConnectTo(EnumFacing.UP)).withProperty(NORTH, shouldConnectTo(EnumFacing.NORTH))
.withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH))
.withProperty(WEST, shouldConnectTo(EnumFacing.WEST))
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST)).withProperty(TYPE, currentType);
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST)).withProperty(TYPE, getPipeType());
}
@Override
@ -305,13 +304,13 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
if (!tank.isEmpty()) {
if (fluidPipe.tank.isEmpty() || fluidPipe.tank.getFluid().getFluid() == tank.getFluid()
.getFluid()) {
if(fluidPipe.tank.getFluidAmount() < tank.getFluidAmount()){
if (fluidPipe.tank.getFluidAmount() < tank.getFluidAmount()) {
int freeSpace = fluidPipe.tank.getCapacity();
if (!fluidPipe.tank.isEmpty()) {
freeSpace = fluidPipe.tank.getCapacity() - fluidPipe.tank.getFluidAmount();
}
int difference = tank.getFluidAmount() - freeSpace;
int amountToChange = difference /2;
int amountToChange = difference / 2;
fluidPipe.tank.setFluid(tank.getFluid());
fluidPipe.tank.setFluidAmount(fluidPipe.tank.getFluidAmount() + amountToChange);
tank.setFluidAmount(tank.getFluidAmount() - amountToChange);
@ -325,7 +324,7 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
if (tileEntity != null) {
if (tileEntity instanceof IFluidHandler) {
IFluidHandler handler = (IFluidHandler) tileEntity;
if (currentType == EnumFluidPipeTypes.EXTRACT) {
if (getPipeType() == EnumFluidPipeTypes.EXTRACT) {
if (!tank.isFull()) {
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
if (fluidTankInfos.length != 0) {
@ -346,7 +345,7 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
}
}
}
} else if (currentType == EnumFluidPipeTypes.INSERT) {
} else if (getPipeType() == EnumFluidPipeTypes.INSERT) {
if (!tank.isEmpty()) {
FluidTankInfo[] fluidTankInfos = handler.getTankInfo(dir.getOpposite());
if (fluidTankInfos.length != 0) {
@ -375,45 +374,56 @@ public class MultipartFluidPipe extends Multipart implements INormallyOccludingP
public boolean onActivated(EntityPlayer player, EnumHand hand, ItemStack heldItem, PartMOP hit) {
//TODO make only wrench able to change mode, shift-click with wrench picks up pipe, and click with empty hand displays current mode in chat (doesn't change it)
//TODO sync this to the client, and also when part is loaded
//if (!getWorld().isRemote) {
if (currentType == EnumFluidPipeTypes.EMPTY) {
currentType = EnumFluidPipeTypes.EXTRACT;
} else if (currentType == EnumFluidPipeTypes.EXTRACT) {
currentType = EnumFluidPipeTypes.INSERT;
} else if (currentType == EnumFluidPipeTypes.INSERT) {
currentType = EnumFluidPipeTypes.EMPTY;
}
// }
System.out.println(getWorld().isRemote);
if (getWorld().isRemote) {
ChatUtils.sendNoSpamClient(new TextComponentString(
ChatFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " " +
currentType.colour + StringUtils.toFirstCapital(currentType.getName())));
if(!getWorld().isRemote){
if (getPipeType() == EnumFluidPipeTypes.EMPTY) {
setPartType(EnumFluidPipeTypes.EXTRACT, this);
} else if (getPipeType() == EnumFluidPipeTypes.EXTRACT) {
setPartType(EnumFluidPipeTypes.INSERT, this);
} else if (getPipeType()== EnumFluidPipeTypes.INSERT) {
setPartType(EnumFluidPipeTypes.EMPTY, this);
}
}
markRenderUpdate();
return true;
}
public void setPartType(EnumFluidPipeTypes type, MultipartFluidPipe pipe){
World world = pipe.getWorld();
BlockPos pos = pipe.getPos();
Tank tank = pipe.tank;
pipe.getContainer().removePart(pipe);
MultipartFluidPipe newPipe = null;
switch (type){
case EMPTY:
newPipe = new EmptyFluidPipe();
break;
case INSERT:
newPipe = new InsertingFluidPipe();
break;
case EXTRACT:
newPipe = new ExtractingFluidPipe();
break;
}
newPipe.tank = tank;
MultipartHelper.addPart(world, pos, newPipe);
ChatUtils.sendNoSpamClient(new TextComponentString(
ChatFormatting.GRAY + I18n.translateToLocal("techreborn.message.setTo") + " " +
type.colour + reborncore.common.util.StringUtils.toFirstCapital(type.getName())));
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tank.writeToNBT(tag);
tag.setString("mode", currentType.getName());
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
tank.readFromNBT(tag);
String mode = tag.getString("mode");
if (mode.equals(EnumFluidPipeTypes.EMPTY)) {
currentType = EnumFluidPipeTypes.EMPTY;
} else if (mode.equals(EnumFluidPipeTypes.INSERT)) {
currentType = EnumFluidPipeTypes.INSERT;
} else if (mode.equals(EnumFluidPipeTypes.EXTRACT)) {
currentType = EnumFluidPipeTypes.EXTRACT;
}
}
}