mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-13 16:54:02 +00:00
Almost done with client data save and data sync and bugfix
This commit is contained in:
1 parent
70139662d3
commit
d29aa0622d
14 files changed
+308
-60
No files matched your search
@@ -15,10 +15,12 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pers.towdium.tudicraft.event.GuiEventHandler;
|
||||
import pers.towdium.tudicraft.event.PlayerEventHandler;
|
||||
import pers.towdium.tudicraft.gui.GuiHandler;
|
||||
import pers.towdium.tudicraft.item.ItemCalculator;
|
||||
import pers.towdium.tudicraft.network.IProxy;
|
||||
import pers.towdium.tudicraft.network.packages.PackageCalculatorUpdate;
|
||||
import pers.towdium.tudicraft.network.packages.PackageRecipeUpdate;
|
||||
import pers.towdium.tudicraft.network.packages.PackageSlotUpdate;
|
||||
|
||||
/**
|
||||
@@ -48,8 +50,8 @@ public class Tudicraft {
|
||||
GameRegistry.registerItem(itemCalculator,itemCalculator.getUnlocalizedName().substring(5));
|
||||
networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID);
|
||||
networkWrapper.registerMessage(PackageSlotUpdate.class, PackageSlotUpdate.class, 0, Side.SERVER);
|
||||
networkWrapper.registerMessage(PackageCalculatorUpdate.class, PackageCalculatorUpdate.class, 0, Side.SERVER);
|
||||
|
||||
networkWrapper.registerMessage(PackageCalculatorUpdate.class, PackageCalculatorUpdate.class, 1, Side.SERVER);
|
||||
networkWrapper.registerMessage(PackageRecipeUpdate.class, PackageRecipeUpdate.class, 2, Side.SERVER);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -58,8 +60,9 @@ public class Tudicraft {
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().
|
||||
register(itemCalculator, 0, new ModelResourceLocation(Reference.MODID + ":" + itemCalculator.getUnlocalizedName().substring(5), "inventory"));
|
||||
}
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(Tudicraft.instance, new GuiHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
|
||||
proxy.init();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Calculator {
|
||||
this.catalystBuffer = catalystBuffer;
|
||||
this.itemRecord = itemRecord;
|
||||
this.operateRecords = operateRecords;
|
||||
for (Recipe recipe : Tudicraft.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item, itemRecord.meta))){
|
||||
for (Recipe recipe : Tudicraft.proxy.getPlayerHandler().getAllRecipeOf(new ItemStack(itemRecord.item, itemRecord.meta), null)){
|
||||
if(checkRecipeValid(recipe)){
|
||||
long count = getOperateCount(recipe, exceedMode);
|
||||
this.currentOperate = new OperateRecord(recipe, count);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package pers.towdium.tudicraft.core;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
@@ -113,4 +116,97 @@ public class Recipe {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class ByteBufUtl{
|
||||
public static Recipe fromByte(ByteBuf buf){
|
||||
short a = buf.readShort();
|
||||
if(a == 0){
|
||||
return null;
|
||||
}
|
||||
short b = buf.readShort();
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=0; i<a; i++){
|
||||
output[i] = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
for(int i=0; i<b; i++){
|
||||
input[i] = ByteBufUtils.readItemStack(buf);
|
||||
}
|
||||
return new Recipe(output, input);
|
||||
}
|
||||
|
||||
public static void toByte(ByteBuf buf, Recipe recipe){
|
||||
if(recipe == null){
|
||||
buf.writeShort(0);
|
||||
return;
|
||||
}
|
||||
short a = 0;
|
||||
short b = 0;
|
||||
for(ItemStack itemStack : recipe.output){
|
||||
if(itemStack != null){
|
||||
a++;
|
||||
}
|
||||
}
|
||||
for(ItemStack itemStack : recipe.input){
|
||||
if(itemStack != null){
|
||||
b++;
|
||||
}
|
||||
}
|
||||
buf.writeShort(a);
|
||||
buf.writeShort(b);
|
||||
ItemStack[] output1 = recipe.output;
|
||||
for (ItemStack itemStack : output1) {
|
||||
if(itemStack != null){
|
||||
ByteBufUtils.writeItemStack(buf, itemStack);
|
||||
}
|
||||
}
|
||||
ItemStack[] input1 = recipe.input;
|
||||
for (ItemStack itemStack : input1) {
|
||||
if(itemStack != null){
|
||||
ByteBufUtils.writeItemStack(buf, itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class NBTUtl{
|
||||
public static NBTTagCompound toNBT(Recipe recipe){
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
for(int i=0; i<4; i++){
|
||||
if(recipe.output[i] != null){
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
recipe.output[i].writeToNBT(buffer);
|
||||
tagCompound.setTag(i+"", buffer);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
if(recipe.input[i] != null){
|
||||
NBTTagCompound buffer = new NBTTagCompound();
|
||||
recipe.input[i].writeToNBT(buffer);
|
||||
tagCompound.setTag((i+4)+"", buffer);
|
||||
}
|
||||
}
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
public static Recipe fromNBT (NBTTagCompound tagCompound){
|
||||
ItemStack[] output = new ItemStack[4];
|
||||
ItemStack[] input = new ItemStack[12];
|
||||
for(int i=0; i<4; i++){
|
||||
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i));
|
||||
if(buffer != null){
|
||||
output[i] = ItemStack.loadItemStackFromNBT(buffer);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<12; i++){
|
||||
NBTTagCompound buffer = tagCompound.getCompoundTag(String.valueOf(i+4));
|
||||
if(buffer != null){
|
||||
input[i] = ItemStack.loadItemStackFromNBT(buffer);
|
||||
}
|
||||
}
|
||||
return new Recipe(output, input);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package pers.towdium.tudicraft.event;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerEventHandler {
|
||||
@SubscribeEvent
|
||||
public void onLogin(net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile event){
|
||||
Tudicraft.proxy.getPlayerHandler().handleLogin(event);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSave(net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile event){
|
||||
Tudicraft.proxy.getPlayerHandler().handleSave(event);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
Calculator.CostRecord record = calculator.getCost();
|
||||
record.unify();
|
||||
costRecord = record;
|
||||
updateScreen();
|
||||
updateLayout();
|
||||
}catch (Exception e){
|
||||
textFieldAmount.setTextColor(16711680);
|
||||
TimerTask r = new TimerTask() {
|
||||
@@ -133,7 +133,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mode = EnumMode.INPUT;
|
||||
break;
|
||||
}
|
||||
updateScreen();
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
mc.thePlayer.openContainer.slotClick(slotId, clickedButton, clickType, mc.thePlayer);
|
||||
}
|
||||
|
||||
public void updateScreen(){
|
||||
public void updateLayout(){
|
||||
switch (mode){
|
||||
case OUTPUT:
|
||||
modeButton.displayString = StatCollector.translateToLocal("gui.calculator.output");
|
||||
@@ -210,10 +210,7 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
modeButton.displayString = StatCollector.translateToLocal("gui.calculator.catalyst");
|
||||
break;
|
||||
}
|
||||
editButton.enabled = Tudicraft.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(0).getStack());
|
||||
|
||||
|
||||
|
||||
editButton.enabled = Tudicraft.proxy.getPlayerHandler().getHasRecipeOf(inventorySlots.getSlot(0).getStack(), null);
|
||||
if(costRecord != null){
|
||||
switch (mode){
|
||||
case OUTPUT:
|
||||
@@ -243,8 +240,12 @@ public class GuiCalculator extends GuiTooltipScreen{
|
||||
|
||||
private void fillSlotsWith(ItemStack[] itemStacks, int start){
|
||||
int pos = 1;
|
||||
for(int i=start ;i<=itemStacks.length-1 && i<=start+36; i++){
|
||||
inventorySlots.getSlot(pos++).putStack(itemStacks[i]);
|
||||
for(int i=start; i<start+36; i++){
|
||||
if(i<=itemStacks.length-1){
|
||||
inventorySlots.getSlot(pos++).putStack(itemStacks[i]);
|
||||
}else {
|
||||
inventorySlots.putStackInSlot(pos++, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
import pers.towdium.tudicraft.network.packages.PackageRecipeUpdate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Time;
|
||||
@@ -68,7 +69,9 @@ public class GuiRecipeEditor extends GuiContainer{
|
||||
Slot slot = inventorySlots.getSlot(buttonId);
|
||||
slot.inventory.setInventorySlotContents(slot.getSlotIndex(), null);
|
||||
}else if(buttonId == 16) {
|
||||
Tudicraft.proxy.getPlayerHandler().addRecipe(((ContainerRecipeEditor)inventorySlots).buildRecipe());
|
||||
Recipe recipe = ((ContainerRecipeEditor)inventorySlots).buildRecipe();
|
||||
Tudicraft.proxy.getPlayerHandler().addRecipe(recipe, null);
|
||||
Tudicraft.networkWrapper.sendToServer(new PackageRecipeUpdate(recipe, -1));
|
||||
mc.displayGuiScreen(parent);
|
||||
}else if(buttonId == 17) {
|
||||
for(Slot slot : inventorySlots.inventorySlots){
|
||||
|
||||
@@ -5,29 +5,34 @@ import net.minecraft.item.ItemStack;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public interface IPlayerHandler {
|
||||
|
||||
boolean getHasRecipeOf(ItemStack itemStack);
|
||||
boolean getHasRecipeOf(ItemStack itemStack, UUID uuid);
|
||||
|
||||
Recipe getRecipeOf(ItemStack itemStack);
|
||||
Recipe getRecipeOf(ItemStack itemStack, UUID uuid);
|
||||
|
||||
ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack);
|
||||
ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid);
|
||||
|
||||
int getRecipeIndexOf(ItemStack itemStack);
|
||||
int getRecipeIndexOf(ItemStack itemStack, UUID uuid);
|
||||
|
||||
ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack);
|
||||
ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid);
|
||||
|
||||
void addRecipe(Recipe recipe);
|
||||
void addRecipe(Recipe recipe, UUID uuid);
|
||||
|
||||
void removeRecipe(int index);
|
||||
void removeRecipe(int index, UUID uuid);
|
||||
|
||||
void setRecipe(Recipe recipe, int index);
|
||||
void setRecipe(Recipe recipe, int index, UUID uuid);
|
||||
|
||||
Recipe getRecipe(int index);
|
||||
Recipe getRecipe(int index, UUID uuid);
|
||||
|
||||
void syncItemCalculator(ItemStack itemIn, String string);
|
||||
|
||||
void handleLogin(net.minecraftforge.event.entity.player.PlayerEvent.LoadFromFile event);
|
||||
|
||||
void handleSave(net.minecraftforge.event.entity.player.PlayerEvent.SaveToFile event);
|
||||
}
|
||||
@@ -11,5 +11,7 @@ import pers.towdium.tudicraft.core.Recipe;
|
||||
public interface IProxy {
|
||||
IPlayerHandler getPlayerHandler();
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
}
|
||||
@@ -4,23 +4,33 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.play.server.S42PacketCombatEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.core.ItemStackWrapper;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
import pers.towdium.tudicraft.gui.calculator.ContainerCalculator;
|
||||
import pers.towdium.tudicraft.network.packages.PackageCalculatorUpdate;
|
||||
import pers.towdium.tudicraft.network.packages.PackageRecipeUpdate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerClient implements IPlayerHandler {
|
||||
List<Recipe> recipes = new ArrayList<>();
|
||||
List<Recipe> recipes;
|
||||
|
||||
@Override
|
||||
public void addRecipe(Recipe recipe) {
|
||||
public void addRecipe(Recipe recipe, UUID uuid) {
|
||||
for (Recipe oneRecipe : recipes){
|
||||
if(oneRecipe.equals(recipe)){
|
||||
return;
|
||||
@@ -32,7 +42,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack) {
|
||||
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
for (Recipe recipe : recipes){
|
||||
if(recipe.getHasOutput(itemStack)){
|
||||
return true;
|
||||
@@ -42,8 +52,8 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipeOf(ItemStack itemStack) {
|
||||
int i = getRecipeIndexOf(itemStack);
|
||||
public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
int i = getRecipeIndexOf(itemStack, null);
|
||||
if(i == -1){
|
||||
return null;
|
||||
}else {
|
||||
@@ -52,16 +62,16 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack) {
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
ImmutableList.Builder<Recipe> recipeBuilder = new ImmutableList.Builder<>();
|
||||
for(Integer index : getAllRecipeIndexOf(itemStack)){
|
||||
for(Integer index : getAllRecipeIndexOf(itemStack, null)){
|
||||
recipeBuilder.add(recipes.get(index));
|
||||
}
|
||||
return recipeBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeIndexOf(ItemStack itemStack) {
|
||||
public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
int[] result = new int[]{-1, -1, -1, -1};
|
||||
for(int[] record : getAllUnsortedRecipeIndexOf(itemStack)){
|
||||
result[record[1]] = record[0];
|
||||
@@ -75,7 +85,7 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack) {
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
ImmutableList.Builder<ImmutableList.Builder<Integer>> builder1 = new ImmutableList.Builder<>();
|
||||
for(int i=0; i<4; i++){
|
||||
builder1.add(new ImmutableList.Builder<Integer>());
|
||||
@@ -92,17 +102,17 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(int index) {
|
||||
public void removeRecipe(int index, UUID uuid) {
|
||||
recipes.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(Recipe recipe, int index) {
|
||||
public void setRecipe(Recipe recipe, int index, UUID uuid) {
|
||||
recipes.set(index, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index) {
|
||||
public Recipe getRecipe(int index, UUID uuid) {
|
||||
return recipes.get(index);
|
||||
}
|
||||
|
||||
@@ -114,6 +124,30 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
Tudicraft.networkWrapper.sendToServer(new PackageCalculatorUpdate(itemStack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLogin(PlayerEvent.LoadFromFile event) {
|
||||
try {
|
||||
FileInputStream stream = new FileInputStream(event.getPlayerFile("jeca"));
|
||||
NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(stream);
|
||||
readFromNBT(tagCompound);
|
||||
} catch (Exception e) {
|
||||
recipes = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSave(PlayerEvent.SaveToFile event) {
|
||||
try{
|
||||
File file = event.getPlayerFile("jeca");
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
writeToNBT(compound);
|
||||
FileOutputStream fileoutputstream = new FileOutputStream(file);
|
||||
CompressedStreamTools.writeCompressed(compound, fileoutputstream);
|
||||
}catch (Exception e){
|
||||
Tudicraft.log.warn("Fail to save records for"+event.entityPlayer.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
ImmutableList<int[]> getAllUnsortedRecipeIndexOf(ItemStack itemStack){
|
||||
ImmutableList.Builder<int[]> builder = new ImmutableList.Builder<>();
|
||||
int size = recipes.size();
|
||||
@@ -127,4 +161,20 @@ public class PlayerHandlerClient implements IPlayerHandler {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
int amount = tagCompound.getInteger("amount");
|
||||
List<Recipe> recipes = new ArrayList<>(amount);
|
||||
for(int i=0; i<amount; i++){
|
||||
recipes.add(Recipe.NBTUtl.fromNBT((NBTTagCompound) tagCompound.getTag(String.valueOf(i))));
|
||||
}
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tagCompound){
|
||||
tagCompound.setInteger("amount", recipes.size());
|
||||
int index = 0;
|
||||
for(Recipe recipe : recipes){
|
||||
tagCompound.setTag(String.valueOf(index++), Recipe.NBTUtl.toNBT(recipe));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,54 +2,66 @@ package pers.towdium.tudicraft.network;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PlayerHandlerServer implements IPlayerHandler {
|
||||
@Override
|
||||
public void addRecipe(Recipe recipe) {
|
||||
HashMap<UUID, PlayerHandlerClient> players = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasRecipeOf(ItemStack itemStack) {
|
||||
public boolean getHasRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipeOf(ItemStack itemStack) {
|
||||
public Recipe getRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack) {
|
||||
public ImmutableList<Recipe> getAllRecipeOf(ItemStack itemStack, UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeIndexOf(ItemStack itemStack) {
|
||||
public int getRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack) {
|
||||
public ImmutableList<Integer> getAllRecipeIndexOf(ItemStack itemStack, UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe(int index) {
|
||||
|
||||
public void addRecipe(Recipe recipe, UUID uuid) {
|
||||
players.get(uuid).addRecipe(recipe, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipe(Recipe recipe, int index) {
|
||||
|
||||
public void removeRecipe(int index, UUID uuid) {
|
||||
players.get(uuid).removeRecipe(index, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index) {
|
||||
public void setRecipe(Recipe recipe, int index, UUID uuid) {
|
||||
players.get(uuid).setRecipe(recipe, index, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(int index, UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -57,4 +69,18 @@ public class PlayerHandlerServer implements IPlayerHandler {
|
||||
public void syncItemCalculator(ItemStack itemIn, String string) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLogin(PlayerEvent.LoadFromFile event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSave(PlayerEvent.SaveToFile event) {
|
||||
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid){
|
||||
players.put(uuid , new PlayerHandlerClient());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.event.GuiEventHandler;
|
||||
import pers.towdium.tudicraft.event.PlayerEventHandler;
|
||||
import pers.towdium.tudicraft.gui.GuiHandler;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
@@ -10,4 +17,12 @@ public class ProxyClient implements IProxy {
|
||||
public IPlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(Tudicraft.instance, new GuiHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
package pers.towdium.tudicraft.network;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import pers.towdium.tudicraft.event.PlayerEventHandler;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class ProxyServer implements IProxy{
|
||||
PlayerHandlerServer playerHandler = new PlayerHandlerServer();
|
||||
public static PlayerHandlerServer playerHandler = new PlayerHandlerServer();
|
||||
|
||||
@Override
|
||||
public IPlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,37 +4,55 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import pers.towdium.tudicraft.Tudicraft;
|
||||
import pers.towdium.tudicraft.core.Recipe;
|
||||
import pers.towdium.tudicraft.network.IPlayerHandler;
|
||||
import pers.towdium.tudicraft.network.PlayerHandlerServer;
|
||||
import pers.towdium.tudicraft.network.ProxyClient;
|
||||
import pers.towdium.tudicraft.network.ProxyServer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Towdium
|
||||
*/
|
||||
public class PackageRecipeUpdate implements IMessage, IMessageHandler<PackageRecipeUpdate, IMessage> {
|
||||
Recipe recipe;
|
||||
int index;
|
||||
|
||||
public PackageRecipeUpdate(){}
|
||||
|
||||
|
||||
public PackageRecipeUpdate(Recipe recipe){
|
||||
public PackageRecipeUpdate(Recipe recipe, int index){
|
||||
this.recipe = recipe;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buffer) {
|
||||
|
||||
buffer.writeInt(index);
|
||||
Recipe.ByteBufUtl.toByte(buffer, recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
|
||||
index = buffer.readInt();
|
||||
recipe = Recipe.ByteBufUtl.fromByte(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PackageRecipeUpdate message, MessageContext context) {
|
||||
|
||||
IPlayerHandler playerHandler = Tudicraft.proxy.getPlayerHandler();
|
||||
if(playerHandler instanceof PlayerHandlerServer){
|
||||
UUID uuid = context.getServerHandler().playerEntity.getUniqueID();
|
||||
if(message.index == -1){
|
||||
playerHandler.addRecipe(message.recipe, uuid);
|
||||
}else if (message.recipe != null){
|
||||
playerHandler.setRecipe(message.recipe, message.index, uuid);
|
||||
}else {
|
||||
playerHandler.removeRecipe(index, uuid);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import javax.swing.plaf.TableUI;
|
||||
public class JEIPlugin implements IModPlugin{
|
||||
public static IJeiRuntime runtime;
|
||||
|
||||
|
||||
@Override
|
||||
public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user