Quick Fix

- Portable Contraptions no longer crash clients in smp
This commit is contained in:
simibubi 2020-02-15 19:40:58 +01:00
parent e7b09dc63f
commit 9308d3ca2b
7 changed files with 58 additions and 55 deletions

View file

@ -0,0 +1,38 @@
package com.simibubi.create.modules.contraptions.components.contraptions;
import java.util.function.Supplier;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.contraptions.components.contraptions.bearing.BearingContraption;
import com.simibubi.create.modules.contraptions.components.contraptions.bearing.ClockworkContraption;
import com.simibubi.create.modules.contraptions.components.contraptions.mounted.MountedContraption;
import com.simibubi.create.modules.contraptions.components.contraptions.piston.PistonContraption;
import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyContraption;
public enum AllContraptionTypes {
PISTON(PistonContraption::new),
BEARING(BearingContraption::new),
PULLEY(PulleyContraption::new),
CLOCKWORK(ClockworkContraption::new),
MOUNTED(MountedContraption::new),
;
Supplier<? extends Contraption> factory;
String id;
private AllContraptionTypes(Supplier<? extends Contraption> factory) {
this.factory = factory;
id = Lang.asId(name());
}
public static Contraption fromType(String type) {
for (AllContraptionTypes allContraptionTypes : values()) {
if (type.equals(allContraptionTypes.id))
return allContraptionTypes.factory.get();
}
return null;
}
}

View file

@ -14,7 +14,6 @@ import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.MutablePair;
@ -53,9 +52,7 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
public class Contraption {
protected static Map<String, Supplier<? extends Contraption>> deserializers = new HashMap<>();
public abstract class Contraption {
public Map<BlockPos, BlockInfo> blocks;
public Map<BlockPos, MountedStorage> storage;
@ -69,10 +66,6 @@ public class Contraption {
protected Direction cachedColliderDirection;
protected BlockPos anchor;
protected static void register(String name, Supplier<? extends Contraption> factory) {
deserializers.put(name, factory);
}
public Contraption() {
blocks = new HashMap<>();
storage = new HashMap<>();
@ -481,9 +474,7 @@ public class Contraption {
public static Contraption fromNBT(World world, CompoundNBT nbt) {
String type = nbt.getString("Type");
Contraption contraption = new Contraption();
if (deserializers.containsKey(type))
contraption = deserializers.get(type).get();
Contraption contraption = AllContraptionTypes.fromType(type);
contraption.readNBT(world, nbt);
return contraption;
}
@ -525,7 +516,7 @@ public class Contraption {
public CompoundNBT writeNBT() {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("Type", getType());
nbt.putString("Type", getType().id);
ListNBT blocksNBT = new ListNBT();
for (BlockInfo block : this.blocks.values()) {
CompoundNBT c = new CompoundNBT();
@ -669,8 +660,6 @@ public class Contraption {
return ((IPortableBlock) block).getMovementBehaviour();
}
protected String getType() {
return "Contraption";
}
protected abstract AllContraptionTypes getType();
}

View file

@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.bearing
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.AllBlockTags;
import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes;
import com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
import net.minecraft.nbt.CompoundNBT;
@ -16,16 +17,10 @@ public class BearingContraption extends Contraption {
protected int sailBlocks;
protected Direction facing;
private static String type = "Bearing";
static {
register(type, BearingContraption::new);
}
@Override
protected String getType() {
return type;
protected AllContraptionTypes getType() {
return AllContraptionTypes.BEARING;
}
public static BearingContraption assembleBearingAt(World world, BlockPos pos, Direction direction) {

View file

@ -8,6 +8,7 @@ import java.util.function.BiPredicate;
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes;
import com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
import net.minecraft.block.BlockState;
@ -23,15 +24,9 @@ public class ClockworkContraption extends Contraption {
public int offset;
private Set<BlockPos> ignoreBlocks = new HashSet<>();
private static String type = "Clockwork";
static {
register(type, ClockworkContraption::new);
}
@Override
protected String getType() {
return type;
protected AllContraptionTypes getType() {
return AllContraptionTypes.CLOCKWORK;
}
private void ignoreBlocks(Set<BlockPos> blocks, BlockPos anchor) {

View file

@ -7,6 +7,7 @@ import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes;
import com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
import net.minecraft.block.BlockState;
@ -25,15 +26,9 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo;
public class MountedContraption extends Contraption {
private static String type = "Mounted";
static {
register(type, MountedContraption::new);
}
@Override
protected String getType() {
return type;
protected AllContraptionTypes getType() {
return AllContraptionTypes.MOUNTED;
}
public static Contraption assembleMinecart(World world, BlockPos pos, AbstractMinecartEntity cart) {

View file

@ -13,6 +13,7 @@ import org.apache.commons.lang3.tuple.Pair;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.config.AllConfigs;
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes;
import com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState;
@ -37,16 +38,11 @@ public class PistonContraption extends Contraption {
protected int initialExtensionProgress;
protected Direction orientation;
private static String type = "Piston";
static {
register(type, PistonContraption::new);
@Override
protected AllContraptionTypes getType() {
return AllContraptionTypes.PISTON;
}
@Override
protected String getType() {
return type;
}
public static PistonContraption movePistonAt(World world, BlockPos pos, Direction direction, boolean retract) {
if (isFrozen())
return null;

View file

@ -1,5 +1,6 @@
package com.simibubi.create.modules.contraptions.components.contraptions.pulley;
import com.simibubi.create.modules.contraptions.components.contraptions.AllContraptionTypes;
import com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
import net.minecraft.nbt.CompoundNBT;
@ -11,15 +12,9 @@ public class PulleyContraption extends Contraption {
int initialOffset;
private static String type = "Pulley";
static {
register(type, PulleyContraption::new);
}
@Override
protected String getType() {
return type;
protected AllContraptionTypes getType() {
return AllContraptionTypes.PULLEY;
}
public static PulleyContraption assemblePulleyAt(World world, BlockPos pos, int initialOffset) {