mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 15:36:24 +01:00
Quick Fix
- Portable Contraptions no longer crash clients in smp
This commit is contained in:
parent
e7b09dc63f
commit
9308d3ca2b
7 changed files with 58 additions and 55 deletions
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,7 +14,6 @@ import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.MutablePair;
|
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.IItemHandlerModifiable;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||||
|
|
||||||
public class Contraption {
|
public abstract class Contraption {
|
||||||
|
|
||||||
protected static Map<String, Supplier<? extends Contraption>> deserializers = new HashMap<>();
|
|
||||||
|
|
||||||
public Map<BlockPos, BlockInfo> blocks;
|
public Map<BlockPos, BlockInfo> blocks;
|
||||||
public Map<BlockPos, MountedStorage> storage;
|
public Map<BlockPos, MountedStorage> storage;
|
||||||
|
@ -69,10 +66,6 @@ public class Contraption {
|
||||||
protected Direction cachedColliderDirection;
|
protected Direction cachedColliderDirection;
|
||||||
protected BlockPos anchor;
|
protected BlockPos anchor;
|
||||||
|
|
||||||
protected static void register(String name, Supplier<? extends Contraption> factory) {
|
|
||||||
deserializers.put(name, factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contraption() {
|
public Contraption() {
|
||||||
blocks = new HashMap<>();
|
blocks = new HashMap<>();
|
||||||
storage = new HashMap<>();
|
storage = new HashMap<>();
|
||||||
|
@ -481,9 +474,7 @@ public class Contraption {
|
||||||
|
|
||||||
public static Contraption fromNBT(World world, CompoundNBT nbt) {
|
public static Contraption fromNBT(World world, CompoundNBT nbt) {
|
||||||
String type = nbt.getString("Type");
|
String type = nbt.getString("Type");
|
||||||
Contraption contraption = new Contraption();
|
Contraption contraption = AllContraptionTypes.fromType(type);
|
||||||
if (deserializers.containsKey(type))
|
|
||||||
contraption = deserializers.get(type).get();
|
|
||||||
contraption.readNBT(world, nbt);
|
contraption.readNBT(world, nbt);
|
||||||
return contraption;
|
return contraption;
|
||||||
}
|
}
|
||||||
|
@ -525,7 +516,7 @@ public class Contraption {
|
||||||
|
|
||||||
public CompoundNBT writeNBT() {
|
public CompoundNBT writeNBT() {
|
||||||
CompoundNBT nbt = new CompoundNBT();
|
CompoundNBT nbt = new CompoundNBT();
|
||||||
nbt.putString("Type", getType());
|
nbt.putString("Type", getType().id);
|
||||||
ListNBT blocksNBT = new ListNBT();
|
ListNBT blocksNBT = new ListNBT();
|
||||||
for (BlockInfo block : this.blocks.values()) {
|
for (BlockInfo block : this.blocks.values()) {
|
||||||
CompoundNBT c = new CompoundNBT();
|
CompoundNBT c = new CompoundNBT();
|
||||||
|
@ -669,8 +660,6 @@ public class Contraption {
|
||||||
return ((IPortableBlock) block).getMovementBehaviour();
|
return ((IPortableBlock) block).getMovementBehaviour();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getType() {
|
protected abstract AllContraptionTypes getType();
|
||||||
return "Contraption";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.bearing
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlockTags;
|
import com.simibubi.create.AllBlockTags;
|
||||||
|
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.Contraption;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
@ -17,15 +18,9 @@ public class BearingContraption extends Contraption {
|
||||||
protected int sailBlocks;
|
protected int sailBlocks;
|
||||||
protected Direction facing;
|
protected Direction facing;
|
||||||
|
|
||||||
private static String type = "Bearing";
|
|
||||||
|
|
||||||
static {
|
|
||||||
register(type, BearingContraption::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected AllContraptionTypes getType() {
|
||||||
return type;
|
return AllContraptionTypes.BEARING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BearingContraption assembleBearingAt(World world, BlockPos pos, Direction direction) {
|
public static BearingContraption assembleBearingAt(World world, BlockPos pos, Direction direction) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.function.BiPredicate;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
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.Contraption;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
@ -23,15 +24,9 @@ public class ClockworkContraption extends Contraption {
|
||||||
public int offset;
|
public int offset;
|
||||||
private Set<BlockPos> ignoreBlocks = new HashSet<>();
|
private Set<BlockPos> ignoreBlocks = new HashSet<>();
|
||||||
|
|
||||||
private static String type = "Clockwork";
|
|
||||||
|
|
||||||
static {
|
|
||||||
register(type, ClockworkContraption::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected AllContraptionTypes getType() {
|
||||||
return type;
|
return AllContraptionTypes.CLOCKWORK;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ignoreBlocks(Set<BlockPos> blocks, BlockPos anchor) {
|
private void ignoreBlocks(Set<BlockPos> blocks, BlockPos anchor) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
|
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.Contraption;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
@ -25,15 +26,9 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo;
|
||||||
|
|
||||||
public class MountedContraption extends Contraption {
|
public class MountedContraption extends Contraption {
|
||||||
|
|
||||||
private static String type = "Mounted";
|
|
||||||
|
|
||||||
static {
|
|
||||||
register(type, MountedContraption::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected AllContraptionTypes getType() {
|
||||||
return type;
|
return AllContraptionTypes.MOUNTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Contraption assembleMinecart(World world, BlockPos pos, AbstractMinecartEntity cart) {
|
public static Contraption assembleMinecart(World world, BlockPos pos, AbstractMinecartEntity cart) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.config.AllConfigs;
|
import com.simibubi.create.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
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.Contraption;
|
||||||
import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState;
|
import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState;
|
||||||
|
|
||||||
|
@ -37,16 +38,11 @@ public class PistonContraption extends Contraption {
|
||||||
protected int initialExtensionProgress;
|
protected int initialExtensionProgress;
|
||||||
protected Direction orientation;
|
protected Direction orientation;
|
||||||
|
|
||||||
private static String type = "Piston";
|
|
||||||
|
|
||||||
static {
|
|
||||||
register(type, PistonContraption::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected AllContraptionTypes getType() {
|
||||||
return type;
|
return AllContraptionTypes.PISTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PistonContraption movePistonAt(World world, BlockPos pos, Direction direction, boolean retract) {
|
public static PistonContraption movePistonAt(World world, BlockPos pos, Direction direction, boolean retract) {
|
||||||
if (isFrozen())
|
if (isFrozen())
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simibubi.create.modules.contraptions.components.contraptions.pulley;
|
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 com.simibubi.create.modules.contraptions.components.contraptions.Contraption;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
@ -11,15 +12,9 @@ public class PulleyContraption extends Contraption {
|
||||||
|
|
||||||
int initialOffset;
|
int initialOffset;
|
||||||
|
|
||||||
private static String type = "Pulley";
|
|
||||||
|
|
||||||
static {
|
|
||||||
register(type, PulleyContraption::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getType() {
|
protected AllContraptionTypes getType() {
|
||||||
return type;
|
return AllContraptionTypes.PULLEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PulleyContraption assemblePulleyAt(World world, BlockPos pos, int initialOffset) {
|
public static PulleyContraption assemblePulleyAt(World world, BlockPos pos, int initialOffset) {
|
||||||
|
|
Loading…
Reference in a new issue