mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-25 00:18:34 +01:00
Compare commits
3 commits
2a6126a1df
...
08112ea11c
Author | SHA1 | Date | |
---|---|---|---|
|
08112ea11c | ||
|
cd37abb4ca | ||
|
3da868fc29 |
10 changed files with 80 additions and 142 deletions
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items.base;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockPlant;
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockPlant;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemSeeds;
|
import net.minecraft.item.ItemSeeds;
|
||||||
|
|
|
@ -13,15 +13,11 @@ package de.ellpeck.actuallyadditions.mod.misc;
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.BannerPattern;
|
|
||||||
import net.minecraftforge.common.util.EnumHelper;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public final class BannerHelper {
|
public final class BannerHelper {
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
addCraftingPattern("drill", new ItemStack(ActuallyItems.DRILL.get(), 1, 3));
|
addCraftingPattern("drill", new ItemStack(ActuallyItems.DRILL.get()));
|
||||||
addCraftingPattern("leaf_blo", new ItemStack(ActuallyItems.LEAF_BLOWER.get()));
|
addCraftingPattern("leaf_blo", new ItemStack(ActuallyItems.LEAF_BLOWER.get()));
|
||||||
addCraftingPattern("phan_con", new ItemStack(ActuallyItems.PHANTOM_CONNECTOR.get()));
|
addCraftingPattern("phan_con", new ItemStack(ActuallyItems.PHANTOM_CONNECTOR.get()));
|
||||||
addCraftingPattern("book", new ItemStack(ActuallyItems.ITEM_BOOKLET.get()));
|
addCraftingPattern("book", new ItemStack(ActuallyItems.ITEM_BOOKLET.get()));
|
||||||
|
@ -47,7 +43,7 @@ public final class BannerHelper {
|
||||||
public static void addCraftingPattern(String name, ItemStack craftingStack) {
|
public static void addCraftingPattern(String name, ItemStack craftingStack) {
|
||||||
Class<?>[] paramTypes = {String.class, String.class, ItemStack.class};
|
Class<?>[] paramTypes = {String.class, String.class, ItemStack.class};
|
||||||
Object[] paramValues = {ActuallyAdditions.MODID + "_" + name, ActuallyAdditions.MODID + "_" + name, craftingStack};
|
Object[] paramValues = {ActuallyAdditions.MODID + "_" + name, ActuallyAdditions.MODID + "_" + name, craftingStack};
|
||||||
EnumHelper.addEnum(BannerPattern.class, (ActuallyAdditions.MODID + "_" + name).toUpperCase(Locale.ROOT), paramTypes, paramValues);
|
// EnumHelper.addEnum(BannerPattern.class, (ActuallyAdditions.MODID + "_" + name).toUpperCase(Locale.ROOT), paramTypes, paramValues); //TODO wth banners
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.item.ItemEntity;
|
import net.minecraft.entity.item.ItemEntity;
|
||||||
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
@ -113,7 +114,7 @@ public class MethodHandler implements IMethodHandler {
|
||||||
|
|
||||||
int prevCounter = tag.putInt("Counter");
|
int prevCounter = tag.putInt("Counter");
|
||||||
CompoundNBT compound = new CompoundNBT();
|
CompoundNBT compound = new CompoundNBT();
|
||||||
compound.putInt("ID", Potion.getIdFromPotion(effect.getEffect()));
|
//compound.putInt("ID", Potion.getIdFromPotion(effect.getEffect())); //TODO ?!
|
||||||
compound.putInt("Duration", effect.getDuration());
|
compound.putInt("Duration", effect.getDuration());
|
||||||
compound.putInt("Amplifier", effect.getAmplifier());
|
compound.putInt("Amplifier", effect.getAmplifier());
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ public class MethodHandler implements IMethodHandler {
|
||||||
if (StackUtil.isValid(output)) {
|
if (StackUtil.isValid(output)) {
|
||||||
tile.getWorldObject().levelEvent(2001, pos, Block.getId(state));
|
tile.getWorldObject().levelEvent(2001, pos, Block.getId(state));
|
||||||
recipe.transformHook(ItemStack.EMPTY, state, pos, tile);
|
recipe.transformHook(ItemStack.EMPTY, state, pos, tile);
|
||||||
if (output.getItem() instanceof ItemBlock) {
|
if (output.getItem() instanceof BlockItem) {
|
||||||
Block toPlace = Block.byItem(output.getItem());
|
Block toPlace = Block.byItem(output.getItem());
|
||||||
BlockState state2Place = toPlace.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND);
|
BlockState state2Place = toPlace.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), Hand.MAIN_HAND);
|
||||||
tile.getWorldObject().setBlock(pos, state2Place, 2);
|
tile.getWorldObject().setBlock(pos, state2Place, 2);
|
||||||
|
|
|
@ -16,6 +16,8 @@ import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraftforge.fml.network.NetworkEvent;
|
import net.minecraftforge.fml.network.NetworkEvent;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class PacketClientToServer {
|
public class PacketClientToServer {
|
||||||
|
|
||||||
private CompoundNBT data;
|
private CompoundNBT data;
|
||||||
|
@ -30,39 +32,31 @@ public class PacketClientToServer {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static PacketClientToServer fromBytes(PacketBuffer buffer) {
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
PacketBuffer buffer = new PacketBuffer(buf);
|
|
||||||
try {
|
try {
|
||||||
this.data = buffer.readNbt();
|
CompoundNBT data = buffer.readNbt();
|
||||||
|
|
||||||
int handlerId = buffer.readInt();
|
int handlerId = buffer.readInt();
|
||||||
if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) {
|
if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) {
|
||||||
this.handler = PacketHandler.DATA_HANDLERS.get(handlerId);
|
return new PacketClientToServer(data, PacketHandler.DATA_HANDLERS.get(handlerId));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a server packet!", e);
|
ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a server packet!", e);
|
||||||
}
|
}
|
||||||
|
return new PacketClientToServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void toBytes(PacketClientToServer message, PacketBuffer buffer) {
|
||||||
public void toBytes(ByteBuf buf) {
|
buffer.writeNbt(message.data);
|
||||||
PacketBuffer buffer = new PacketBuffer(buf);
|
buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(message.handler));
|
||||||
|
|
||||||
buffer.writeNbt(this.data);
|
|
||||||
buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(this.handler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Handler implements IMessageHandler<PacketClientToServer, IMessage> {
|
public static void handle(final PacketClientToServer message, final Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork( () -> {
|
||||||
@Override
|
|
||||||
public IMessage onMessage(PacketClientToServer message, NetworkEvent.Context ctx) {
|
|
||||||
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> {
|
|
||||||
if (message.data != null && message.handler != null) {
|
if (message.data != null && message.handler != null) {
|
||||||
message.handler.handleData(message.data, ctx);
|
message.handler.handleData(message.data, ctx.get());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return null;
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,18 @@ import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.inventory.container.Container;
|
import net.minecraft.inventory.container.Container;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.nbt.NBTUtil;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.RegistryKey;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.fml.network.NetworkDirection;
|
import net.minecraftforge.fml.network.NetworkDirection;
|
||||||
|
import net.minecraftforge.fml.network.NetworkEvent;
|
||||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.network.PacketDistributor;
|
import net.minecraftforge.fml.network.PacketDistributor;
|
||||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||||
|
@ -48,19 +52,19 @@ public final class PacketHandler {
|
||||||
public static final IDataHandler LASER_HANDLER = new IDataHandler() {
|
public static final IDataHandler LASER_HANDLER = new IDataHandler() {
|
||||||
@Override
|
@Override
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void handleData(CompoundNBT compound, MessageContext context) {
|
public void handleData(CompoundNBT compound, NetworkEvent.Context context) {
|
||||||
AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), new float[]{compound.getFloat("Color1"), compound.getFloat("Color2"), compound.getFloat("Color3")}, compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha"));
|
AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), new float[]{compound.getFloat("Color1"), compound.getFloat("Color2"), compound.getFloat("Color3")}, compound.getInt("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() {
|
public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler() {
|
||||||
@Override
|
@Override
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void handleData(CompoundNBT compound, MessageContext context) {
|
public void handleData(CompoundNBT compound, NetworkEvent.Context context) {
|
||||||
World world = Minecraft.getInstance().level;
|
World world = Minecraft.getInstance().level;
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||||
if (tile instanceof TileEntityBase) {
|
if (tile instanceof TileEntityBase) {
|
||||||
((TileEntityBase) tile).readSyncableNBT(compound.getCompoundTag("Data"), TileEntityBase.NBTType.SYNC);
|
((TileEntityBase) tile).readSyncableNBT(compound.getCompound("Data"), TileEntityBase.NBTType.SYNC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,9 +72,9 @@ public final class PacketHandler {
|
||||||
public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() {
|
public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler() {
|
||||||
@Override
|
@Override
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void handleData(CompoundNBT compound, MessageContext context) {
|
public void handleData(CompoundNBT compound, NetworkEvent.Context context) {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
ItemStack stack = new ItemStack(compound);
|
ItemStack stack = ItemStack.of(compound);
|
||||||
|
|
||||||
double inX = compound.getDouble("InX") + 0.5;
|
double inX = compound.getDouble("InX") + 0.5;
|
||||||
double inY = compound.getDouble("InY") + 0.78;
|
double inY = compound.getDouble("InY") + 0.78;
|
||||||
|
@ -81,11 +85,11 @@ public final class PacketHandler {
|
||||||
double outZ = compound.getDouble("OutZ") + 0.5;
|
double outZ = compound.getDouble("OutZ") + 0.5;
|
||||||
|
|
||||||
Particle fx = new ParticleLaserItem(mc.level, outX, outY, outZ, stack, 0.025, inX, inY, inZ);
|
Particle fx = new ParticleLaserItem(mc.level, outX, outY, outZ, stack, 0.025, inX, inY, inZ);
|
||||||
mc.effectRenderer.addEffect(fx);
|
//mc.effectRenderer.addEffect(fx); //TODO
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> {
|
public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = (compound, context) -> {
|
||||||
World world = DimensionManager.getWorld(compound.getInt("WorldID"));
|
World world = context.getSender().getServer().getLevel(RegistryKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(compound.getString("WorldID"))));
|
||||||
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||||
|
|
||||||
if (tile instanceof IButtonReactor) {
|
if (tile instanceof IButtonReactor) {
|
||||||
|
@ -97,7 +101,7 @@ public final class PacketHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = (compound, context) -> {
|
public static final IDataHandler GUI_BUTTON_TO_CONTAINER_HANDLER = (compound, context) -> {
|
||||||
World world = DimensionManager.getWorld(compound.getInt("WorldID"));
|
World world = context.getSender().getServer().getLevel(RegistryKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(compound.getString("WorldID"))));
|
||||||
Entity entity = world.getEntity(compound.getInt("PlayerID"));
|
Entity entity = world.getEntity(compound.getInt("PlayerID"));
|
||||||
if (entity instanceof PlayerEntity) {
|
if (entity instanceof PlayerEntity) {
|
||||||
Container container = ((PlayerEntity) entity).containerMenu;
|
Container container = ((PlayerEntity) entity).containerMenu;
|
||||||
|
@ -107,7 +111,7 @@ public final class PacketHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = (compound, context) -> {
|
public static final IDataHandler GUI_NUMBER_TO_TILE_HANDLER = (compound, context) -> {
|
||||||
World world = DimensionManager.getWorld(compound.getInt("WorldID"));
|
World world = context.getSender().getServer().getLevel(RegistryKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(compound.getString("WorldID"))));
|
||||||
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||||
|
|
||||||
if (tile instanceof INumberReactor) {
|
if (tile instanceof INumberReactor) {
|
||||||
|
@ -116,7 +120,7 @@ public final class PacketHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler GUI_STRING_TO_TILE_HANDLER = (compound, context) -> {
|
public static final IDataHandler GUI_STRING_TO_TILE_HANDLER = (compound, context) -> {
|
||||||
World world = DimensionManager.getWorld(compound.getInt("WorldID"));
|
World world = context.getSender().getServer().getLevel(RegistryKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(compound.getString("WorldID"))));
|
||||||
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
TileEntity tile = world.getBlockEntity(new BlockPos(compound.getInt("X"), compound.getInt("Y"), compound.getInt("Z")));
|
||||||
|
|
||||||
if (tile instanceof IStringReactor) {
|
if (tile instanceof IStringReactor) {
|
||||||
|
@ -127,9 +131,9 @@ public final class PacketHandler {
|
||||||
public static final IDataHandler SYNC_PLAYER_DATA = new IDataHandler() {
|
public static final IDataHandler SYNC_PLAYER_DATA = new IDataHandler() {
|
||||||
@Override
|
@Override
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void handleData(CompoundNBT compound, MessageContext context) {
|
public void handleData(CompoundNBT compound, NetworkEvent.Context context) {
|
||||||
CompoundNBT dataTag = compound.getCompoundTag("Data");
|
CompoundNBT dataTag = compound.getCompound("Data");
|
||||||
PlayerEntity player = ActuallyAdditions.PROXY.getCurrentPlayer();
|
PlayerEntity player = context.getSender(); //ActuallyAdditions.PROXY.getCurrentPlayer();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerData.getDataFromPlayer(player).readFromNBT(dataTag, false);
|
PlayerData.getDataFromPlayer(player).readFromNBT(dataTag, false);
|
||||||
|
@ -143,8 +147,8 @@ public final class PacketHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> {
|
public static final IDataHandler PLAYER_DATA_TO_SERVER = (compound, context) -> {
|
||||||
World world = DimensionManager.getWorld(compound.getInt("World"));
|
World world = context.getSender().getServer().getLevel(RegistryKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(compound.getString("World"))));
|
||||||
PlayerEntity player = world.getPlayerEntityByUUID(compound.getUUID("UUID"));
|
PlayerEntity player = world.getServer().getPlayerList().getPlayer(compound.getUUID("UUID"));
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||||
|
|
||||||
|
@ -179,8 +183,16 @@ public final class PacketHandler {
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
THE_NETWORK.registerMessage(PacketServerToClient.Handler.class, PacketServerToClient.class, 0, Side.CLIENT);
|
THE_NETWORK.messageBuilder(PacketServerToClient.class, 0, NetworkDirection.PLAY_TO_CLIENT)
|
||||||
THE_NETWORK.registerMessage(PacketClientToServer.Handler.class, PacketClientToServer.class, 1, Side.SERVER);
|
.decoder(PacketServerToClient::fromBytes)
|
||||||
|
.encoder(PacketServerToClient::toBytes)
|
||||||
|
.consumer(PacketServerToClient::handle).add();
|
||||||
|
|
||||||
|
THE_NETWORK.messageBuilder(PacketClientToServer.class, 1, NetworkDirection.PLAY_TO_SERVER)
|
||||||
|
.decoder(PacketClientToServer::fromBytes)
|
||||||
|
.encoder(PacketClientToServer::toBytes)
|
||||||
|
.consumer(PacketClientToServer::handle).add();
|
||||||
|
|
||||||
|
|
||||||
DATA_HANDLERS.add(LASER_HANDLER);
|
DATA_HANDLERS.add(LASER_HANDLER);
|
||||||
DATA_HANDLERS.add(TILE_ENTITY_HANDLER);
|
DATA_HANDLERS.add(TILE_ENTITY_HANDLER);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
import net.minecraftforge.fml.network.PacketDistributor;
|
||||||
|
|
||||||
public final class PacketHandlerHelper {
|
public final class PacketHandlerHelper {
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ public final class PacketHandlerHelper {
|
||||||
compound.putInt("X", pos.getX());
|
compound.putInt("X", pos.getX());
|
||||||
compound.putInt("Y", pos.getY());
|
compound.putInt("Y", pos.getY());
|
||||||
compound.putInt("Z", pos.getZ());
|
compound.putInt("Z", pos.getZ());
|
||||||
compound.putInt("WorldID", tile.getLevel().getDimension());
|
compound.putString("WorldID", tile.getLevel().dimension().getRegistryName().toString());
|
||||||
compound.putInt("PlayerID", Minecraft.getInstance().player.getId());
|
compound.putInt("PlayerID", Minecraft.getInstance().player.getId());
|
||||||
compound.putInt("ButtonID", buttonId);
|
compound.putInt("ButtonID", buttonId);
|
||||||
PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER));
|
PacketHandler.THE_NETWORK.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER));
|
||||||
|
@ -48,7 +49,7 @@ public final class PacketHandlerHelper {
|
||||||
compound.put("Data", data);
|
compound.put("Data", data);
|
||||||
|
|
||||||
if (player instanceof ServerPlayerEntity) {
|
if (player instanceof ServerPlayerEntity) {
|
||||||
PacketHandler.THE_NETWORK.sendTo(new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA), (ServerPlayerEntity) player);
|
PacketHandler.THE_NETWORK.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) player), new PacketServerToClient(compound, PacketHandler.SYNC_PLAYER_DATA));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +61,8 @@ public final class PacketHandlerHelper {
|
||||||
|
|
||||||
PlayerEntity player = Minecraft.getInstance().player;
|
PlayerEntity player = Minecraft.getInstance().player;
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
compound.putInt("World", player.level.provider.getDimension());
|
compound.putString("World", player.level.dimension().getRegistryName().toString());
|
||||||
compound.setUniqueId("UUID", player.getUUID());
|
compound.putUUID("UUID", player.getUUID());
|
||||||
|
|
||||||
PlayerSave data = PlayerData.getDataFromPlayer(player);
|
PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ public final class PacketHandlerHelper {
|
||||||
compound.putInt("X", tile.getBlockPos().getX());
|
compound.putInt("X", tile.getBlockPos().getX());
|
||||||
compound.putInt("Y", tile.getBlockPos().getY());
|
compound.putInt("Y", tile.getBlockPos().getY());
|
||||||
compound.putInt("Z", tile.getBlockPos().getZ());
|
compound.putInt("Z", tile.getBlockPos().getZ());
|
||||||
compound.putInt("WorldID", tile.getLevel().provider.getDimension());
|
compound.putString("WorldID", tile.getLevel().dimension().getRegistryName().toString());
|
||||||
compound.putInt("PlayerID", Minecraft.getInstance().player.getId());
|
compound.putInt("PlayerID", Minecraft.getInstance().player.getId());
|
||||||
compound.putInt("NumberID", id);
|
compound.putInt("NumberID", id);
|
||||||
compound.putDouble("Number", number);
|
compound.putDouble("Number", number);
|
||||||
|
|
|
@ -11,18 +11,14 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.network;
|
package de.ellpeck.actuallyadditions.mod.network;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.fml.network.NetworkEvent;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import java.util.function.Supplier;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
|
||||||
|
|
||||||
|
|
||||||
public class PacketServerToClient implements Message {
|
public class PacketServerToClient {
|
||||||
|
|
||||||
private CompoundNBT data;
|
private CompoundNBT data;
|
||||||
private IDataHandler handler;
|
private IDataHandler handler;
|
||||||
|
@ -36,40 +32,33 @@ public class PacketServerToClient implements Message {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static PacketServerToClient fromBytes(final PacketBuffer buffer) {
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
PacketBuffer buffer = new PacketBuffer(buf);
|
|
||||||
try {
|
try {
|
||||||
this.data = buffer.readNbt();
|
CompoundNBT data = buffer.readNbt();
|
||||||
|
|
||||||
int handlerId = buffer.readInt();
|
int handlerId = buffer.readInt();
|
||||||
if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) {
|
if (handlerId >= 0 && handlerId < PacketHandler.DATA_HANDLERS.size()) {
|
||||||
this.handler = PacketHandler.DATA_HANDLERS.get(handlerId);
|
return new PacketServerToClient(data, PacketHandler.DATA_HANDLERS.get(handlerId));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a client packet!", e);
|
ActuallyAdditions.LOGGER.error("Something went wrong trying to receive a client packet!", e);
|
||||||
}
|
}
|
||||||
|
return new PacketServerToClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void toBytes(final PacketServerToClient message, PacketBuffer buffer) {
|
||||||
public void toBytes(ByteBuf buf) {
|
buffer.writeNbt(message.data);
|
||||||
PacketBuffer buffer = new PacketBuffer(buf);
|
buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(message.handler));
|
||||||
|
|
||||||
buffer.writeNbt(this.data);
|
|
||||||
buffer.writeInt(PacketHandler.DATA_HANDLERS.indexOf(this.handler));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Handler implements IMessageHandler<PacketServerToClient, IMessage> {
|
public static void handle(final PacketServerToClient message, final Supplier<NetworkEvent.Context> ctx) {
|
||||||
|
ctx.get().enqueueWork(
|
||||||
@Override
|
() -> {
|
||||||
@OnlyIn(Dist.CLIENT)
|
|
||||||
public IMessage onMessage(PacketServerToClient message, MessageContext ctx) {
|
|
||||||
Minecraft.getInstance().addScheduledTask(() -> {
|
|
||||||
if (message.data != null && message.handler != null) {
|
if (message.data != null && message.handler != null) {
|
||||||
message.handler.handleData(message.data, ctx);
|
message.handler.handleData(message.data, ctx.get());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
public interface IEnergyDisplay {
|
public interface IEnergyDisplay {
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
|
import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes;
|
||||||
import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe;
|
import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe;
|
||||||
|
@ -30,7 +29,6 @@ import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
|
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||||
|
|
||||||
public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
||||||
|
@ -43,23 +41,8 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
||||||
super(ActuallyBlocks.EMPOWERER.getTileEntityType(), 1);
|
super(ActuallyBlocks.EMPOWERER.getTileEntityType(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated //Use findMatchingRecipe
|
|
||||||
public static List<EmpowererRecipe> getRecipesForInput(ItemStack input) {
|
|
||||||
List<EmpowererRecipe> recipesThatWork = new ArrayList<>();
|
|
||||||
if (StackUtil.isValid(input)) {
|
|
||||||
// TODO: [port] VALIDATOR OR REMOVE
|
|
||||||
for (EmpowererRecipe recipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES) {
|
|
||||||
if (recipe.getInput().test(input)) {
|
|
||||||
recipesThatWork.add(recipe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return recipesThatWork;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isPossibleInput(ItemStack stack) {
|
public static boolean isPossibleInput(ItemStack stack) {
|
||||||
for (EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) {
|
for (EmpowererRecipe r : ServerLifecycleHooks.getCurrentServer().getRecipeManager().getAllRecipesFor(ActuallyRecipes.Types.EMPOWERING)) {
|
||||||
// TODO: [port] move to proper recipe system
|
|
||||||
if (r.getInput().test(stack)) {
|
if (r.getInput().test(stack)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +69,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase {
|
||||||
if (stands != null) {
|
if (stands != null) {
|
||||||
EmpowererRecipe recipe = findMatchingRecipe(this.inv.getStackInSlot(0), stands[0].getStack(), stands[1].getStack(), stands[2].getStack(), stands[3].getStack());
|
EmpowererRecipe recipe = findMatchingRecipe(this.inv.getStackInSlot(0), stands[0].getStack(), stands[1].getStack(), stands[2].getStack(), stands[3].getStack());
|
||||||
if (recipe != null) {
|
if (recipe != null) {
|
||||||
this.recipeForRenderIndex = ActuallyAdditionsAPI.EMPOWERER_RECIPES.indexOf(recipe);
|
//this.recipeForRenderIndex = ActuallyAdditionsAPI.EMPOWERER_RECIPES.indexOf(recipe); //TODO whats this?
|
||||||
|
|
||||||
boolean hasPower = true;
|
boolean hasPower = true;
|
||||||
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* This file ("RecipeUtil.java") is part of the Actually Additions mod for Minecraft.
|
|
||||||
* It is created and owned by Ellpeck and distributed
|
|
||||||
* under the Actually Additions License to be found at
|
|
||||||
* http://ellpeck.de/actaddlicense
|
|
||||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
||||||
*
|
|
||||||
* © 2015-2017 Ellpeck
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.util;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
|
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.crafting.RecipeHandler;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
|
|
||||||
public final class RecipeUtil {
|
|
||||||
|
|
||||||
public static LensConversionRecipe lastReconstructorRecipe() {
|
|
||||||
List<LensConversionRecipe> list = ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES;
|
|
||||||
return list.get(list.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CrusherRecipe lastCrusherRecipe() {
|
|
||||||
List<CrusherRecipe> list = ActuallyAdditionsAPI.CRUSHER_RECIPES;
|
|
||||||
return list.get(list.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IRecipe lastIRecipe() {
|
|
||||||
return RecipeHandler.lastRecipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EmpowererRecipe lastEmpowererRecipe() {
|
|
||||||
List<EmpowererRecipe> list = ActuallyAdditionsAPI.EMPOWERER_RECIPES;
|
|
||||||
return list.get(list.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue