Fix more tile classes
This commit is contained in:
@@ -30,8 +30,8 @@ public enum RedstoneMode {
|
||||
}
|
||||
|
||||
public static RedstoneMode read(CompoundNBT tag) {
|
||||
if (tag.hasKey(RedstoneMode.NBT)) {
|
||||
return getById(tag.getInteger(NBT));
|
||||
if (tag.contains(RedstoneMode.NBT)) {
|
||||
return getById(tag.getInt(NBT));
|
||||
}
|
||||
|
||||
return IGNORE;
|
||||
|
@@ -5,23 +5,20 @@ import com.raoulvdberge.refinedstorage.tile.ClientNode;
|
||||
import com.raoulvdberge.refinedstorage.util.AccessTypeUtils;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.DataParameter;
|
||||
import net.minecraft.network.datasync.DataSerializer;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraft.network.datasync.IDataSerializer;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class RSSerializers {
|
||||
public static final DataSerializer<List<ClientNode>> CLIENT_NODE_SERIALIZER = new DataSerializer<List<ClientNode>>() {
|
||||
public static final IDataSerializer<List<ClientNode>> CLIENT_NODE_SERIALIZER = new IDataSerializer<List<ClientNode>>() {
|
||||
@Override
|
||||
public void write(PacketBuffer buf, List<ClientNode> nodes) {
|
||||
buf.writeInt(nodes.size());
|
||||
|
||||
for (ClientNode node : nodes) {
|
||||
ByteBufUtils.writeItemStack(buf, node.getStack());
|
||||
buf.writeItemStack(node.getStack());
|
||||
buf.writeInt(node.getAmount());
|
||||
buf.writeInt(node.getEnergyUsage());
|
||||
}
|
||||
@@ -34,7 +31,7 @@ public final class RSSerializers {
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
nodes.add(new ClientNode(ByteBufUtils.readItemStack(buf), buf.readInt(), buf.readInt()));
|
||||
nodes.add(new ClientNode(buf.readItemStack(), buf.readInt(), buf.readInt()));
|
||||
}
|
||||
|
||||
return nodes;
|
||||
@@ -51,30 +48,15 @@ public final class RSSerializers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final DataSerializer<FluidStack> FLUID_STACK_SERIALIZER = new DataSerializer<FluidStack>() {
|
||||
public static final IDataSerializer<FluidStack> FLUID_STACK_SERIALIZER = new IDataSerializer<FluidStack>() {
|
||||
@Override
|
||||
public void write(PacketBuffer buf, FluidStack value) {
|
||||
if (value == null) {
|
||||
buf.writeBoolean(false);
|
||||
} else {
|
||||
buf.writeBoolean(true);
|
||||
ByteBufUtils.writeUTF8String(buf, FluidRegistry.getFluidName(value));
|
||||
buf.writeInt(value.amount);
|
||||
buf.writeCompoundTag(value.tag);
|
||||
}
|
||||
value.writeToPacket(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack read(PacketBuffer buf) {
|
||||
try {
|
||||
if (buf.readBoolean()) {
|
||||
return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), buf.readCompoundTag());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
return null;
|
||||
return FluidStack.readFromPacket(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +70,7 @@ public final class RSSerializers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final DataSerializer<AccessType> ACCESS_TYPE_SERIALIZER = new DataSerializer<AccessType>() {
|
||||
public static final IDataSerializer<AccessType> ACCESS_TYPE_SERIALIZER = new IDataSerializer<AccessType>() {
|
||||
@Override
|
||||
public void write(PacketBuffer buf, AccessType value) {
|
||||
buf.writeInt(value.getId());
|
||||
@@ -110,14 +92,14 @@ public final class RSSerializers {
|
||||
}
|
||||
};
|
||||
|
||||
public static final DataSerializer<Long> LONG_SERIALIZER = new DataSerializer<Long>() {
|
||||
public static final IDataSerializer<Long> LONG_SERIALIZER = new IDataSerializer<Long>() {
|
||||
@Override
|
||||
public void write(PacketBuffer buf, Long value) {
|
||||
buf.writeLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long read(PacketBuffer buf) throws IOException {
|
||||
public Long read(PacketBuffer buf) {
|
||||
return buf.readLong();
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.data;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageTileDataParameterUpdate;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -70,6 +68,6 @@ public class TileDataManager {
|
||||
}
|
||||
|
||||
public static void setParameter(TileDataParameter parameter, Object value) {
|
||||
RS.INSTANCE.network.sendToServer(new MessageTileDataParameterUpdate(parameter, value));
|
||||
// TODO RS.INSTANCE.network.sendToServer(new MessageTileDataParameterUpdate(parameter, value));
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.data;
|
||||
|
||||
import net.minecraft.network.datasync.DataSerializer;
|
||||
import net.minecraft.network.datasync.IDataSerializer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -9,7 +9,7 @@ import java.util.function.Function;
|
||||
|
||||
public class TileDataParameter<T, E extends TileEntity> {
|
||||
private int id;
|
||||
private DataSerializer<T> serializer;
|
||||
private IDataSerializer<T> serializer;
|
||||
private Function<E, T> valueProducer;
|
||||
@Nullable
|
||||
private BiConsumer<E, T> valueConsumer;
|
||||
@@ -17,15 +17,15 @@ public class TileDataParameter<T, E extends TileEntity> {
|
||||
private TileDataParameterClientListener<T> listener;
|
||||
private T value;
|
||||
|
||||
public TileDataParameter(DataSerializer<T> serializer, T defaultValue, Function<E, T> producer) {
|
||||
public TileDataParameter(IDataSerializer<T> serializer, T defaultValue, Function<E, T> producer) {
|
||||
this(serializer, defaultValue, producer, null);
|
||||
}
|
||||
|
||||
public TileDataParameter(DataSerializer<T> serializer, T defaultValue, Function<E, T> producer, @Nullable BiConsumer<E, T> consumer) {
|
||||
public TileDataParameter(IDataSerializer<T> serializer, T defaultValue, Function<E, T> producer, @Nullable BiConsumer<E, T> consumer) {
|
||||
this(serializer, defaultValue, producer, consumer, null);
|
||||
}
|
||||
|
||||
public TileDataParameter(DataSerializer<T> serializer, T defaultValue, Function<E, T> producer, @Nullable BiConsumer<E, T> consumer, @Nullable TileDataParameterClientListener<T> listener) {
|
||||
public TileDataParameter(IDataSerializer<T> serializer, T defaultValue, Function<E, T> producer, @Nullable BiConsumer<E, T> consumer, @Nullable TileDataParameterClientListener<T> listener) {
|
||||
this.value = defaultValue;
|
||||
this.serializer = serializer;
|
||||
this.valueProducer = producer;
|
||||
@@ -41,7 +41,7 @@ public class TileDataParameter<T, E extends TileEntity> {
|
||||
return id;
|
||||
}
|
||||
|
||||
public DataSerializer<T> getSerializer() {
|
||||
public IDataSerializer<T> getSerializer() {
|
||||
return serializer;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package com.raoulvdberge.refinedstorage.tile.data;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.network.MessageTileDataParameter;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
|
||||
public class TileDataWatcher {
|
||||
@@ -54,6 +52,6 @@ public class TileDataWatcher {
|
||||
}
|
||||
|
||||
public void sendParameter(boolean initial, TileDataParameter parameter) {
|
||||
RS.INSTANCE.network.sendTo(new MessageTileDataParameter(manager.getTile(), parameter, initial), player);
|
||||
// TODO RS.INSTANCE.network.sendTo(new MessageTileDataParameter(manager.getTile(), parameter, initial), player);
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
|
||||
public class DirectionHandlerTile implements IDirectionHandler {
|
||||
public static final String NBT_DIRECTION = "Direction";
|
||||
private static final String NBT_DIRECTION = "Direction";
|
||||
|
||||
private Direction direction = Direction.NORTH;
|
||||
|
||||
@@ -25,8 +25,8 @@ public class DirectionHandlerTile implements IDirectionHandler {
|
||||
|
||||
@Override
|
||||
public void readFromTileNbt(CompoundNBT tag) {
|
||||
if (tag.hasKey(NBT_DIRECTION)) {
|
||||
direction = Direction.byIndex(tag.getInteger(NBT_DIRECTION));
|
||||
if (tag.contains(NBT_DIRECTION)) {
|
||||
direction = Direction.byIndex(tag.getInt(NBT_DIRECTION));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user