Lots of compound fixes

This commit is contained in:
Michael Hillcox 2020-09-21 18:59:08 +01:00
parent 497b742b87
commit 26b021a5e9
No known key found for this signature in database
GPG key ID: 971C5B254742488F
7 changed files with 136 additions and 143 deletions

View file

@ -18,7 +18,7 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.OnlyIn;
public class BookletPage implements IBookletPage { public class BookletPage implements IBookletPage {
@ -60,7 +60,7 @@ public class BookletPage implements IBookletPage {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public String getInfoText() { public String getInfoText() {
if (this.hasNoText) { return null; } if (this.hasNoText) { return null; }
@ -78,55 +78,55 @@ public class BookletPage implements IBookletPage {
return base; return base;
} }
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
protected String getLocalizationKey() { protected String getLocalizationKey() {
return "booklet." + ActuallyAdditions.MODID + ".chapter." + this.chapter.getIdentifier() + ".text." + this.localizationKey; return "booklet." + ActuallyAdditions.MODID + ".chapter." + this.chapter.getIdentifier() + ".text." + this.localizationKey;
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton) { public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state) { public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void actionPerformed(GuiBookletBase gui, GuiButton button) { public void actionPerformed(GuiBookletBase gui, GuiButton button) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void initGui(GuiBookletBase gui, int startX, int startY) { public void initGui(GuiBookletBase gui, int startX, int startY) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer) { public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks) { public void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks) {
} }
@Override @Override
@SideOnly(Side.CLIENT) @OnlyIn(Side.CLIENT)
public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks) { public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks) {
} }

View file

@ -8,16 +8,16 @@ import java.util.concurrent.ConcurrentHashMap;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.booklet.gui.GuiBooklet; import de.ellpeck.actuallyadditions.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.booklet.misc.BookletUtils; import de.ellpeck.actuallyadditions.booklet.misc.BookletUtils;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTTagString; import net.minecraft.nbt.StringNBT;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.api.distmarker.OnlyIn;
public final class PlayerData { public final class PlayerData {
public static PlayerSave getDataFromPlayer(EntityPlayer player) { public static PlayerSave getDataFromPlayer(PlayerEntity player) {
WorldData worldData = WorldData.get(player.getEntityWorld()); WorldData worldData = WorldData.get(player.getEntityWorld());
ConcurrentHashMap<UUID, PlayerSave> data = worldData.playerSaveData; ConcurrentHashMap<UUID, PlayerSave> data = worldData.playerSaveData;
UUID id = player.getUniqueID(); UUID id = player.getUniqueID();
@ -47,24 +47,24 @@ public final class PlayerData {
public IBookletPage[] bookmarks = new IBookletPage[12]; public IBookletPage[] bookmarks = new IBookletPage[12];
public List<String> completedTrials = new ArrayList<>(); public List<String> completedTrials = new ArrayList<>();
@SideOnly(Side.CLIENT) @OnlyIn(Dist.CLIENT)
public GuiBooklet lastOpenBooklet; public GuiBooklet lastOpenBooklet;
public PlayerSave(UUID id) { public PlayerSave(UUID id) {
this.id = id; this.id = id;
} }
public void readFromNBT(NBTTagCompound compound, boolean savingToFile) { public void readFromNBT(CompoundNBT compound, boolean savingToFile) {
this.bookGottenAlready = compound.getBoolean("BookGotten"); this.bookGottenAlready = compound.getBoolean("BookGotten");
this.didBookTutorial = compound.getBoolean("DidTutorial"); this.didBookTutorial = compound.getBoolean("DidTutorial");
this.hasBatWings = compound.getBoolean("HasBatWings"); this.hasBatWings = compound.getBoolean("HasBatWings");
this.batWingsFlyTime = compound.getInteger("BatWingsFlyTime"); this.batWingsFlyTime = compound.getInt("BatWingsFlyTime");
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8); ListNBT bookmarks = compound.getList("Bookmarks", 8);
this.loadBookmarks(bookmarks); this.loadBookmarks(bookmarks);
NBTTagList trials = compound.getTagList("Trials", 8); ListNBT trials = compound.getList("Trials", 8);
this.loadTrials(trials); this.loadTrials(trials);
if (!savingToFile) { if (!savingToFile) {
@ -72,33 +72,33 @@ public final class PlayerData {
} }
} }
public void writeToNBT(NBTTagCompound compound, boolean savingToFile) { public void writeToNBT(CompoundNBT compound, boolean savingToFile) {
compound.setBoolean("BookGotten", this.bookGottenAlready); compound.putBoolean("BookGotten", this.bookGottenAlready);
compound.setBoolean("DidTutorial", this.didBookTutorial); compound.putBoolean("DidTutorial", this.didBookTutorial);
compound.setBoolean("HasBatWings", this.hasBatWings); compound.putBoolean("HasBatWings", this.hasBatWings);
compound.setInteger("BatWingsFlyTime", this.batWingsFlyTime); compound.putInt("BatWingsFlyTime", this.batWingsFlyTime);
compound.setTag("Bookmarks", this.saveBookmarks()); compound.put("Bookmarks", this.saveBookmarks());
compound.setTag("Trials", this.saveTrials()); compound.put("Trials", this.saveTrials());
if (!savingToFile) { if (!savingToFile) {
compound.setBoolean("ShouldDisableWings", this.shouldDisableBatWings); compound.putBoolean("ShouldDisableWings", this.shouldDisableBatWings);
} }
} }
public NBTTagList saveBookmarks() { public ListNBT saveBookmarks() {
NBTTagList bookmarks = new NBTTagList(); ListNBT bookmarks = new ListNBT();
for (IBookletPage bookmark : this.bookmarks) { for (IBookletPage bookmark : this.bookmarks) {
bookmarks.appendTag(new NBTTagString(bookmark == null ? "" : bookmark.getIdentifier())); bookmarks.add(StringNBT.valueOf(bookmark == null ? "" : bookmark.getIdentifier()));
} }
return bookmarks; return bookmarks;
} }
public void loadBookmarks(NBTTagList bookmarks) { public void loadBookmarks(ListNBT bookmarks) {
for (int i = 0; i < bookmarks.tagCount(); i++) { for (int i = 0; i < bookmarks.size(); i++) {
String strg = bookmarks.getStringTagAt(i); String strg = bookmarks.getString(i);
if (strg != null && !strg.isEmpty()) { if (!strg.isEmpty()) {
IBookletPage page = BookletUtils.getBookletPageById(strg); IBookletPage page = BookletUtils.getBookletPageById(strg);
this.bookmarks[i] = page; this.bookmarks[i] = page;
} else { } else {
@ -107,20 +107,20 @@ public final class PlayerData {
} }
} }
public NBTTagList saveTrials() { public ListNBT saveTrials() {
NBTTagList trials = new NBTTagList(); ListNBT trials = new ListNBT();
for (String trial : this.completedTrials) { for (String trial : this.completedTrials) {
trials.appendTag(new NBTTagString(trial)); trials.add(StringNBT.valueOf(trial));
} }
return trials; return trials;
} }
public void loadTrials(NBTTagList trials) { public void loadTrials(ListNBT trials) {
this.completedTrials.clear(); this.completedTrials.clear();
for (int i = 0; i < trials.tagCount(); i++) { for (int i = 0; i < trials.size(); i++) {
String strg = trials.getStringTagAt(i); String strg = trials.getString(i);
if (strg != null && !strg.isEmpty()) { if (!strg.isEmpty()) {
this.completedTrials.add(strg); this.completedTrials.add(strg);
} }
} }

View file

@ -8,8 +8,8 @@ import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.data.PlayerData.PlayerSave; import de.ellpeck.actuallyadditions.common.data.PlayerData.PlayerSave;
import de.ellpeck.actuallyadditions.common.misc.apiimpl.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.common.misc.apiimpl.LaserRelayConnectionHandler;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListNBT;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.storage.WorldSavedData; import net.minecraft.world.storage.WorldSavedData;
@ -65,21 +65,21 @@ public class WorldData extends WorldSavedData {
} }
@Override @Override
public void readFromNBT(NBTTagCompound compound) { public void read(CompoundNBT compound) {
this.laserRelayNetworks.clear(); this.laserRelayNetworks.clear();
NBTTagList networkList = compound.getTagList("Networks", 10); ListNBT networkList = compound.getList("Networks", 10);
for (int i = 0; i < networkList.tagCount(); i++) { for (int i = 0; i < networkList.size(); i++) {
Network network = LaserRelayConnectionHandler.readNetworkFromNBT(networkList.getCompoundTagAt(i)); Network network = LaserRelayConnectionHandler.readNetworkFromNBT(networkList.getCompound(i));
this.laserRelayNetworks.add(network); this.laserRelayNetworks.add(network);
} }
this.playerSaveData.clear(); this.playerSaveData.clear();
NBTTagList playerList = compound.getTagList("PlayerData", 10); ListNBT playerList = compound.getList("PlayerData", 10);
for (int i = 0; i < playerList.tagCount(); i++) { for (int i = 0; i < playerList.size(); i++) {
NBTTagCompound player = playerList.getCompoundTagAt(i); CompoundNBT player = playerList.getCompound(i);
UUID id = player.getUniqueId("UUID"); UUID id = player.getUniqueId("UUID");
NBTTagCompound data = player.getCompoundTag("Data"); CompoundNBT data = player.getCompound("Data");
PlayerSave save = new PlayerSave(id); PlayerSave save = new PlayerSave(id);
save.readFromNBT(data, true); save.readFromNBT(data, true);
@ -88,27 +88,27 @@ public class WorldData extends WorldSavedData {
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) { public CompoundNBT write(CompoundNBT compound) {
//Laser World Data //Laser World Data
NBTTagList networkList = new NBTTagList(); ListNBT networkList = new ListNBT();
for (Network network : this.laserRelayNetworks) { for (Network network : this.laserRelayNetworks) {
networkList.appendTag(LaserRelayConnectionHandler.writeNetworkToNBT(network)); networkList.add(LaserRelayConnectionHandler.writeNetworkToNBT(network));
} }
compound.setTag("Networks", networkList); compound.put("Networks", networkList);
//Player Data //Player Data
NBTTagList playerList = new NBTTagList(); ListNBT playerList = new ListNBT();
for (PlayerSave save : this.playerSaveData.values()) { for (PlayerSave save : this.playerSaveData.values()) {
NBTTagCompound player = new NBTTagCompound(); CompoundNBT player = new CompoundNBT();
player.setUniqueId("UUID", save.id); player.putUniqueId("UUID", save.id);
NBTTagCompound data = new NBTTagCompound(); CompoundNBT data = new CompoundNBT();
save.writeToNBT(data, true); save.writeToNBT(data, true);
player.setTag("Data", data); player.put("Data", data);
playerList.appendTag(player); playerList.add(player);
} }
compound.setTag("PlayerData", playerList); compound.put("PlayerData", playerList);
return compound; return compound;
} }

View file

@ -7,32 +7,32 @@ import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.common.data.WorldData; import de.ellpeck.actuallyadditions.common.data.WorldData;
import de.ellpeck.actuallyadditions.common.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.common.tile.TileEntityLaserRelay;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListNBT;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public final class LaserRelayConnectionHandler implements ILaserRelayConnectionHandler { public final class LaserRelayConnectionHandler implements ILaserRelayConnectionHandler {
public static NBTTagCompound writeNetworkToNBT(Network network) { public static CompoundNBT writeNetworkToNBT(Network network) {
NBTTagList list = new NBTTagList(); ListNBT list = new ListNBT();
for (IConnectionPair pair : network.connections) { for (IConnectionPair pair : network.connections) {
NBTTagCompound tag = new NBTTagCompound(); CompoundNBT tag = new CompoundNBT();
pair.writeToNBT(tag); pair.writeToNBT(tag);
list.appendTag(tag); list.add(tag);
} }
NBTTagCompound compound = new NBTTagCompound(); CompoundNBT compound = new CompoundNBT();
compound.setTag("Network", list); compound.put("Network", list);
return compound; return compound;
} }
public static Network readNetworkFromNBT(NBTTagCompound tag) { public static Network readNetworkFromNBT(CompoundNBT tag) {
NBTTagList list = tag.getTagList("Network", 10); ListNBT list = tag.getList("Network", 10);
Network network = new Network(); Network network = new Network();
for (int i = 0; i < list.tagCount(); i++) { for (int i = 0; i < list.size(); i++) {
ConnectionPair pair = new ConnectionPair(); ConnectionPair pair = new ConnectionPair();
pair.readFromNBT(list.getCompoundTagAt(i)); pair.readFromNBT(list.getCompound(i));
network.connections.add(pair); network.connections.add(pair);
} }
return network; return network;

View file

@ -25,21 +25,19 @@ import de.ellpeck.actuallyadditions.common.recipe.CrusherRecipeRegistry;
import de.ellpeck.actuallyadditions.common.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.common.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.common.util.StackUtil; import de.ellpeck.actuallyadditions.common.util.StackUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.block.Blocks;
import net.minecraft.item.ItemBlock; import net.minecraft.entity.item.ItemEntity;
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.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect; import net.minecraft.util.Direction;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.FakePlayerFactory;
public class MethodHandler implements IMethodHandler { public class MethodHandler implements IMethodHandler {
@ -48,10 +46,10 @@ public class MethodHandler implements IMethodHandler {
public boolean addEffectToStack(ItemStack stack, CoffeeIngredient ingredient) { public boolean addEffectToStack(ItemStack stack, CoffeeIngredient ingredient) {
boolean worked = false; boolean worked = false;
if (ingredient != null) { if (ingredient != null) {
PotionEffect[] effects = ingredient.getEffects(); EffectInstance[] effects = ingredient.getEffects();
if (effects != null && effects.length > 0) { if (effects != null && effects.length > 0) {
for (PotionEffect effect : effects) { for (EffectInstance effect : effects) {
PotionEffect effectHas = this.getSameEffectFromStack(stack, effect); EffectInstance effectHas = this.getSameEffectFromStack(stack, effect);
if (effectHas != null) { if (effectHas != null) {
if (effectHas.getAmplifier() < ingredient.getMaxAmplifier() - 1) { if (effectHas.getAmplifier() < ingredient.getMaxAmplifier() - 1) {
this.addEffectProperties(stack, effect, false, true); this.addEffectProperties(stack, effect, false, true);
@ -68,10 +66,10 @@ public class MethodHandler implements IMethodHandler {
} }
@Override @Override
public PotionEffect getSameEffectFromStack(ItemStack stack, PotionEffect effect) { public EffectInstance getSameEffectFromStack(ItemStack stack, EffectInstance effect) {
PotionEffect[] effectsStack = this.getEffectsFromStack(stack); EffectInstance[] effectsStack = this.getEffectsFromStack(stack);
if (effectsStack != null && effectsStack.length > 0) { if (effectsStack != null && effectsStack.length > 0) {
for (PotionEffect effectStack : effectsStack) { for (EffectInstance effectStack : effectsStack) {
if (effect.getPotion() == effectStack.getPotion()) { return effectStack; } if (effect.getPotion() == effectStack.getPotion()) { return effectStack; }
} }
} }
@ -79,66 +77,61 @@ public class MethodHandler implements IMethodHandler {
} }
@Override @Override
public void addEffectProperties(ItemStack stack, PotionEffect effect, boolean addDur, boolean addAmp) { public void addEffectProperties(ItemStack stack, EffectInstance effect, boolean addDur, boolean addAmp) {
PotionEffect[] effects = this.getEffectsFromStack(stack); EffectInstance[] effects = this.getEffectsFromStack(stack);
stack.setTagCompound(new NBTTagCompound()); stack.setTag(new CompoundNBT());
for (int i = 0; i < effects.length; i++) { for (int i = 0; i < effects.length; i++) {
if (effects[i].getPotion() == effect.getPotion()) { if (effects[i].getPotion() == effect.getPotion()) {
effects[i] = new PotionEffect(effects[i].getPotion(), effects[i].getDuration() + (addDur ? effect.getDuration() : 0), effects[i].getAmplifier() + (addAmp ? effect.getAmplifier() > 0 ? effect.getAmplifier() : 1 : 0)); effects[i] = new EffectInstance(effects[i].getPotion(), effects[i].getDuration() + (addDur ? effect.getDuration() : 0), effects[i].getAmplifier() + (addAmp ? effect.getAmplifier() > 0 ? effect.getAmplifier() : 1 : 0));
} }
this.addEffectToStack(stack, effects[i]); this.addEffectToStack(stack, effects[i]);
} }
} }
@Override @Override
public void addEffectToStack(ItemStack stack, PotionEffect effect) { public void addEffectToStack(ItemStack stack, EffectInstance effect) {
NBTTagCompound tag = stack.getTagCompound(); CompoundNBT tag = stack.getOrCreateTag();
if (tag == null) {
tag = new NBTTagCompound();
}
int prevCounter = tag.getInteger("Counter"); int prevCounter = tag.getInt("Counter");
NBTTagCompound compound = new NBTTagCompound(); CompoundNBT compound = new CompoundNBT();
compound.setInteger("ID", Potion.getIdFromPotion(effect.getPotion())); compound.putInt("ID", Potion.getIdFromPotion(effect.getPotion()));
compound.setInteger("Duration", effect.getDuration()); compound.putInt("Duration", effect.getDuration());
compound.setInteger("Amplifier", effect.getAmplifier()); compound.putInt("Amplifier", effect.getAmplifier());
int counter = prevCounter + 1; int counter = prevCounter + 1;
tag.setTag(counter + "", compound); tag.put(counter + "", compound);
tag.setInteger("Counter", counter); tag.putInt("Counter", counter);
stack.setTagCompound(tag); stack.setTag(tag);
} }
@Override @Override
public PotionEffect[] getEffectsFromStack(ItemStack stack) { public EffectInstance[] getEffectsFromStack(ItemStack stack) {
ArrayList<PotionEffect> effects = new ArrayList<>(); ArrayList<EffectInstance> effects = new ArrayList<>();
NBTTagCompound tag = stack.getTagCompound(); CompoundNBT tag = stack.getOrCreateTag();
if (tag != null) { int counter = tag.getInt("Counter");
int counter = tag.getInteger("Counter"); while (counter > 0) {
while (counter > 0) { CompoundNBT compound = (CompoundNBT) tag.get(counter + "");
NBTTagCompound compound = (NBTTagCompound) tag.getTag(counter + ""); EffectInstance effect = new EffectInstance(Potion.getPotionById(compound.getInt("ID")), compound.getInt("Duration"), compound.getByte("Amplifier"));
PotionEffect effect = new PotionEffect(Potion.getPotionById(compound.getInteger("ID")), compound.getInteger("Duration"), compound.getByte("Amplifier")); effects.add(effect);
effects.add(effect); counter--;
counter--;
}
} }
return effects.size() > 0 ? effects.toArray(new PotionEffect[effects.size()]) : null; return effects.size() > 0 ? effects.toArray(new EffectInstance[effects.size()]) : null;
} }
@Override @Override
public boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) { public boolean invokeConversionLens(BlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile) {
if (hitBlock != null) { if (hitBlock != null) {
int range = 1; int range = 1;
int rangeX = 0; int rangeX = 0;
int rangeY = 0; int rangeY = 0;
int rangeZ = 0; int rangeZ = 0;
EnumFacing facing = tile.getOrientation(); Direction facing = tile.getOrientation();
if (facing != EnumFacing.UP && facing != EnumFacing.DOWN) { if (facing != Direction.UP && facing != Direction.DOWN) {
rangeY = range; rangeY = range;
if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH) { if (facing == Direction.NORTH || facing == Direction.SOUTH) {
rangeX = range; rangeX = range;
} else { } else {
rangeZ = range; rangeZ = range;
@ -154,7 +147,7 @@ public class MethodHandler implements IMethodHandler {
for (int reachY = -rangeY; reachY <= rangeY; reachY++) { for (int reachY = -rangeY; reachY <= rangeY; reachY++) {
BlockPos pos = new BlockPos(hitBlock.getX() + reachX, hitBlock.getY() + reachY, hitBlock.getZ() + reachZ); BlockPos pos = new BlockPos(hitBlock.getX() + reachX, hitBlock.getY() + reachY, hitBlock.getZ() + reachZ);
if (!tile.getWorldObject().isAirBlock(pos)) { if (!tile.getWorldObject().isAirBlock(pos)) {
IBlockState state = tile.getWorldObject().getBlockState(pos); BlockState state = tile.getWorldObject().getBlockState(pos);
if (state.getBlock() instanceof BlockLaserRelay) continue; if (state.getBlock() instanceof BlockLaserRelay) continue;
LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)), tile.getLens()); LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)), tile.getLens());
if (recipe != null && tile.getEnergy() >= recipe.getEnergyUsed()) { if (recipe != null && tile.getEnergy() >= recipe.getEnergyUsed()) {
@ -164,12 +157,12 @@ public class MethodHandler implements IMethodHandler {
recipe.transformHook(ItemStack.EMPTY, state, pos, tile); recipe.transformHook(ItemStack.EMPTY, state, pos, tile);
if (output.getItem() instanceof ItemBlock) { if (output.getItem() instanceof ItemBlock) {
Block toPlace = Block.getBlockFromItem(output.getItem()); Block toPlace = Block.getBlockFromItem(output.getItem());
IBlockState state2Place = toPlace.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), EnumHand.MAIN_HAND); BlockState state2Place = toPlace.getStateForPlacement(tile.getWorldObject(), pos, facing, 0, 0, 0, output.getMetadata(), FakePlayerFactory.getMinecraft((WorldServer) tile.getWorldObject()), EnumHand.MAIN_HAND);
tile.getWorldObject().setBlockState(pos, state2Place, 2); tile.getWorld().setBlockState(pos, state2Place, 2);
} else { } else {
EntityItem item = new EntityItem(tile.getWorldObject(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output.copy()); ItemEntity item = new ItemEntity(tile.getWorldObject(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output.copy());
tile.getWorldObject().spawnEntity(item); tile.getWorld().addEntity(item);
tile.getWorldObject().setBlockToAir(pos); tile.getWorld().setBlockState(pos, Blocks.AIR.getDefaultState());
} }
tile.extractEnergy(recipe.getEnergyUsed()); tile.extractEnergy(recipe.getEnergyUsed());
@ -185,30 +178,30 @@ public class MethodHandler implements IMethodHandler {
AxisAlignedBB aabb = new AxisAlignedBB(tile.getPosition().getX(), tile.getPosition().getY(), tile.getPosition().getZ(), hitBlock.getX() + 1, hitBlock.getY() + 1, hitBlock.getZ() + 1); AxisAlignedBB aabb = new AxisAlignedBB(tile.getPosition().getX(), tile.getPosition().getY(), tile.getPosition().getZ(), hitBlock.getX() + 1, hitBlock.getY() + 1, hitBlock.getZ() + 1);
Vec3i dir = tile.getOrientation().getDirectionVec(); Vec3i dir = tile.getOrientation().getDirectionVec();
aabb = aabb.grow(0.02, 0.02, 0.02).expand(dir.getX(), dir.getY(), dir.getZ()); aabb = aabb.grow(0.02, 0.02, 0.02).expand(dir.getX(), dir.getY(), dir.getZ());
List<EntityItem> items = tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, aabb); List<ItemEntity> items = tile.getWorldObject().getEntitiesWithinAABB(ItemEntity.class, aabb);
for (EntityItem item : items) { for (ItemEntity item : items) {
ItemStack stack = item.getItem(); ItemStack stack = item.getItem();
if (!item.isDead && StackUtil.isValid(stack) && !item.getEntityData().getBoolean("aa_cnv")) { if (item.isAlive() && StackUtil.isValid(stack) && !item.getEntityData().getBoolean("aa_cnv")) {
LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(stack, tile.getLens()); LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(stack, tile.getLens());
if (recipe != null) { if (recipe != null) {
int itemsPossible = Math.min(tile.getEnergy() / recipe.getEnergyUsed(), stack.getCount()); int itemsPossible = Math.min(tile.getEnergy() / recipe.getEnergyUsed(), stack.getCount());
if (itemsPossible > 0) { if (itemsPossible > 0) {
recipe.transformHook(item.getItem(), null, item.getPosition(), tile); recipe.transformHook(item.getItem(), null, item.getPosition(), tile);
item.setDead(); item.remove();
if (stack.getCount() - itemsPossible > 0) { if (stack.getCount() - itemsPossible > 0) {
ItemStack stackCopy = stack.copy(); ItemStack stackCopy = stack.copy();
stackCopy.shrink(itemsPossible); stackCopy.shrink(itemsPossible);
EntityItem inputLeft = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, stackCopy); ItemEntity inputLeft = new ItemEntity(tile.getWorldObject(), item.posX, item.posY, item.posZ, stackCopy);
tile.getWorldObject().spawnEntity(inputLeft); tile.getWorld().addEntity(inputLeft);
} }
ItemStack outputCopy = recipe.getOutput().copy(); ItemStack outputCopy = recipe.getOutput().copy();
outputCopy.setCount(itemsPossible); outputCopy.setCount(itemsPossible);
EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy); ItemEntity newItem = new ItemEntity(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy);
newItem.getEntityData().setBoolean("aa_cnv", true); newItem.getEntityData().setBoolean("aa_cnv", true);
tile.getWorldObject().spawnEntity(newItem); tile.getWorldObject().spawnEntity(newItem);
@ -226,7 +219,7 @@ public class MethodHandler implements IMethodHandler {
@Override @Override
public boolean invokeReconstructor(IAtomicReconstructor tile) { public boolean invokeReconstructor(IAtomicReconstructor tile) {
if (tile.getEnergy() >= TileEntityAtomicReconstructor.ENERGY_USE) { if (tile.getEnergy() >= TileEntityAtomicReconstructor.ENERGY_USE) {
EnumFacing sideToManipulate = tile.getOrientation(); Direction sideToManipulate = tile.getOrientation();
Lens currentLens = tile.getLens(); Lens currentLens = tile.getLens();
if (currentLens.canInvoke(tile, sideToManipulate, TileEntityAtomicReconstructor.ENERGY_USE)) { if (currentLens.canInvoke(tile, sideToManipulate, TileEntityAtomicReconstructor.ENERGY_USE)) {
tile.extractEnergy(TileEntityAtomicReconstructor.ENERGY_USE); tile.extractEnergy(TileEntityAtomicReconstructor.ENERGY_USE);

View file

@ -1,10 +1,10 @@
package de.ellpeck.actuallyadditions.common.network; package de.ellpeck.actuallyadditions.common.network;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; import net.minecraftforge.fml.network.NetworkEvent;
public interface IDataHandler { public interface IDataHandler {
void handleData(NBTTagCompound compound, MessageContext context); void handleData(CompoundNBT compound, NetworkEvent.Context context);
} }

View file

@ -137,7 +137,7 @@ public final class PacketHandler {
int type = compound.getInteger("Type"); int type = compound.getInteger("Type");
if (type == 0) { if (type == 0) {
data.loadBookmarks(compound.getTagList("Bookmarks", 8)); data.loadBookmarks(compound.getList("Bookmarks", 8));
} else if (type == 1) { } else if (type == 1) {
data.didBookTutorial = compound.getBoolean("DidBookTutorial"); data.didBookTutorial = compound.getBoolean("DidBookTutorial");
} else if (type == 2) { } else if (type == 2) {