More moves and compilation fixes

This commit is contained in:
Sebastian Hartte
2020-06-29 02:15:31 +02:00
parent 3df93fc66d
commit 0d63f560d3
240 changed files with 2221 additions and 1926 deletions
@@ -132,7 +132,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
this.pushDirection = AEPartLocation.fromFacing(where);
for (int x = 0; x < table.size(); x++) {
this.gridInv.setStackInSlot(x, table.getStack(x));
this.gridInv.setInvStack(x, table.getStack(x));
}
this.updateSleepiness();
@@ -331,7 +331,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
super.getDrops(w, pos, drops);
for (int h = 0; h < this.upgrades.getSlots(); h++) {
for (int h = 0; h < this.upgrades.getSlotCount(); h++) {
final ItemStack is = this.upgrades.getInvStack(h);
if (!is.isEmpty()) {
drops.add(is);
@@ -412,7 +412,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
this.pushOut(output.copy());
for (int x = 0; x < this.craftingInv.size(); x++) {
this.gridInv.setStackInSlot(x, Platform.getRecipeRemainder(this.craftingInv.getStack(x)));
this.gridInv.setInvStack(x, Platform.getRecipeRemainder(this.craftingInv.getStack(x)));
}
if (ItemHandlerUtil.isEmpty(this.patternInv)) {
@@ -446,8 +446,8 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
final ItemStack is = this.gridInv.getInvStack(x);
if (!is.isEmpty()) {
if (this.myPlan == null || !this.myPlan.isValidItemForSlot(x, is, this.world)) {
this.gridInv.setStackInSlot(9, is);
this.gridInv.setStackInSlot(x, ItemStack.EMPTY);
this.gridInv.setInvStack(9, is);
this.gridInv.setInvStack(x, ItemStack.EMPTY);
this.saveChanges();
return;
}
@@ -479,7 +479,7 @@ public class MolecularAssemblerBlockEntity extends AENetworkInvBlockEntity
this.recalculatePlan();
}
this.gridInv.setStackInSlot(9, output);
this.gridInv.setInvStack(9, output);
}
private ItemStack pushTo(ItemStack output, final Direction d) {
@@ -23,11 +23,12 @@ import java.util.Random;
import net.fabricmc.api.EnvType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.math.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import org.lwjgl.opengl.GL11;
@@ -35,7 +36,6 @@ import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.BlockItem;
@@ -99,9 +99,9 @@ public class MolecularAssemblerRenderer extends BlockEntityRenderer<MolecularAss
// https://bugs.mojang.com/browse/MC-161917
MinecraftClient minecraft = MinecraftClient.getInstance();
BakedModel lightsModel = minecraft.getModelManager().getModel(LIGHTS_MODEL);
IVertexBuilder buffer = bufferIn.getBuffer(MC_161917_RENDERTYPE_FIX);
VertexConsumer buffer = bufferIn.getBuffer(MC_161917_RENDERTYPE_FIX);
minecraft.getBlockRendererDispatcher().getBlockModelRenderer().renderModel(ms.getLast(), buffer, null,
minecraft.getBlockRenderManager().getBlockModelRenderer().renderModel(ms.getLast(), buffer, null,
lightsModel, 1, 1, 1, combinedLightIn, combinedOverlayIn, EmptyModelData.INSTANCE);
}
@@ -150,7 +150,7 @@ public class MolecularAssemblerRenderer extends BlockEntityRenderer<MolecularAss
RenderState.TransparencyState TRANSLUCENT_TRANSPARENCY = ObfuscationReflectionHelper
.getPrivateValue(RenderState.class, null, "field_228515_g_");
RenderState.TextureState mipmapBlockAtlasTexture = new RenderState.TextureState(
AtlasTexture.LOCATION_BLOCKS_TEXTURE, false, true);
SpriteAtlasTexture.BLOCK_ATLAS_TEX, false, true);
RenderState.LightmapState disableLightmap = new RenderState.LightmapState(false);
RenderLayer.State glState = RenderLayer.State.getBuilder().texture(mipmapBlockAtlasTexture)
.transparency(TRANSLUCENT_TRANSPARENCY).alpha(new RenderState.AlphaState(0.05F))
@@ -99,8 +99,8 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
item = ItemStack.EMPTY;
}
this.inv.setStackInSlot(x, item);
this.inv.setStackInSlot(6, ais);
this.inv.setInvStack(x, item);
this.inv.setInvStack(6, ais);
return true;
}
}
@@ -137,7 +137,7 @@ public class GrinderBlockEntity extends AEBaseInvBlockEntity implements ICrankab
}
}
this.inv.setStackInSlot(6, ItemStack.EMPTY);
this.inv.setInvStack(6, ItemStack.EMPTY);
}
}
@@ -1,198 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.tile.inventory;
import java.util.Iterator;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import alexiil.mc.lib.attributes.ListenerRemovalToken;
import alexiil.mc.lib.attributes.ListenerToken;
import alexiil.mc.lib.attributes.Simulation;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import alexiil.mc.lib.attributes.item.InvMarkDirtyListener;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import appeng.api.AEApi;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AELog;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
import appeng.util.iterators.InvIterator;
public class AppEngInternalAEInventory implements FixedItemInv, Iterable<ItemStack> {
private final IAEAppEngInventory te;
private final IAEItemStack[] inv;
private final int size;
private int maxStack;
private boolean dirtyFlag = false;
public AppEngInternalAEInventory(final IAEAppEngInventory te, final int s) {
this.te = te;
this.size = s;
this.maxStack = 64;
this.inv = new IAEItemStack[s];
}
public void setMaxStackSize(final int s) {
this.maxStack = s;
}
public IAEItemStack getAEStackInSlot(final int var1) {
return this.inv[var1];
}
public void writeToNBT(final CompoundTag data, final String name) {
final CompoundTag c = new CompoundTag();
this.writeToNBT(c);
data.put(name, c);
}
private void writeToNBT(final CompoundTag target) {
for (int x = 0; x < this.size; x++) {
try {
final CompoundTag c = new CompoundTag();
if (this.inv[x] != null) {
this.inv[x].writeToNBT(c);
}
target.put("#" + x, c);
} catch (final Exception ignored) {
}
}
}
public void readFromNBT(final CompoundTag data, final String name) {
final CompoundTag c = data.getCompound(name);
if (c != null) {
this.readFromNBT(c);
}
}
private void readFromNBT(final CompoundTag target) {
for (int x = 0; x < this.size; x++) {
try {
final CompoundTag c = target.getCompound("#" + x);
if (c != null) {
this.inv[x] = AEItemStack.fromNBT(c);
}
} catch (final Exception e) {
AELog.debug(e);
}
}
}
protected int getStackLimit(int slot, @Nonnull ItemStack stack) {
return Math.min(this.getMaxAmount(slot, stack), stack.getMaxCount());
}
@Override
public ItemStack getInvStack(int slot) {
if (this.inv[slot] == null) {
return ItemStack.EMPTY;
}
return this.inv[slot].createItemStack();
}
@Override
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
if (this.te == null || !Platform.isServer()) {
return false;
}
// FIXME: We need to implement the actual checks here, stacking /caninsert/canremove
if (true) {
throw new IllegalStateException();
}
if (simulation == Simulation.SIMULATE) {
return true;
}
ItemStack oldStack = this.getInvStack(slot).copy();
this.inv[slot] = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)
.createStack(to);
ItemStack newStack = to.copy();
InvOperation op = InvOperation.SET;
if (ItemStack.areItemsEqual(oldStack, newStack)) {
if (newStack.getCount() > oldStack.getCount()) {
newStack.decrement(oldStack.getCount());
oldStack = ItemStack.EMPTY;
op = InvOperation.INSERT;
} else {
oldStack.decrement(newStack.getCount());
newStack = ItemStack.EMPTY;
op = InvOperation.EXTRACT;
}
}
this.fireOnChangeInventory(slot, op, oldStack, newStack);
return true;
}
@Override
public int getSlotCount() {
return this.size;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return true;
}
@Override
public int getChangeValue() {
return 0;
}
@Nullable
@Override
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
return null;
}
private void fireOnChangeInventory(int slot, InvOperation op, ItemStack removed, ItemStack inserted) {
if (this.te != null && Platform.isServer() && !this.dirtyFlag) {
this.dirtyFlag = true;
this.te.onChangeInventory(this, slot, op, removed, inserted);
this.te.saveChanges();
this.dirtyFlag = false;
}
}
@Override
public int getMaxAmount(int slot, ItemStack is) {
return Math.min(this.maxStack, 64);
}
@Override
public Iterator<ItemStack> iterator() {
return new InvIterator(this);
}
}
@@ -1,171 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.tile.inventory;
import alexiil.mc.lib.attributes.Simulation;
import alexiil.mc.lib.attributes.item.FixedItemInvView;
import alexiil.mc.lib.attributes.item.filter.ConstantItemFilter;
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
import alexiil.mc.lib.attributes.item.impl.FullFixedItemInv;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
// FIXME: the filtering is not correctly implemented and need to be reworked
public class AppEngInternalInventory extends FullFixedItemInv implements Iterable<ItemStack> {
private boolean enableClientEvents = false;
private IAEAppEngInventory te;
private final int[] maxStack;
private IAEItemFilter filter;
private boolean dirtyFlag = false;
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size, final int maxStack,
IAEItemFilter filter) {
super(size);
this.setTileEntity(inventory);
this.setFilter(filter);
this.maxStack = new int[size];
Arrays.fill(this.maxStack, maxStack);
setOwnerListener(this::onContentsChanged);
}
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size, final int maxStack) {
this(inventory, size, maxStack, null);
}
public AppEngInternalInventory(final IAEAppEngInventory inventory, final int size) {
this(inventory, size, 64);
}
public void setFilter(IAEItemFilter filter) {
this.filter = filter;
}
@Override
public int getMaxAmount(int slot, ItemStack stack) {
return Math.min(maxStack[slot], super.getMaxAmount(slot, stack));
}
protected void onContentsChanged(FixedItemInvView inv, int slot, ItemStack previous, ItemStack current) {
if (this.getBlockEntity() != null && this.eventsEnabled() && !this.dirtyFlag) {
this.dirtyFlag = true;
ItemStack newStack = current.copy();
ItemStack oldStack = previous;
InvOperation op = InvOperation.SET;
if (newStack.isEmpty() || oldStack.isEmpty() || ItemStack.areItemsEqual(newStack, oldStack)) {
if (newStack.getCount() > oldStack.getCount()) {
newStack.decrement(oldStack.getCount());
oldStack = ItemStack.EMPTY;
op = InvOperation.INSERT;
} else {
oldStack.decrement(newStack.getCount());
newStack = ItemStack.EMPTY;
op = InvOperation.EXTRACT;
}
}
this.getBlockEntity().onChangeInventory(this, slot, op, oldStack, newStack);
this.getBlockEntity().saveChanges();
this.dirtyFlag = false;
}
}
protected boolean eventsEnabled() {
return Platform.isServer() || this.isEnableClientEvents();
}
public void setMaxStackSize(final int slot, final int size) {
this.maxStack[slot] = size;
}
@Override
public ItemFilter getFilterForSlot(int slot) {
if (this.maxStack[slot] == 0) {
return ConstantItemFilter.NOTHING;
}
if (this.filter != null) {
return stack -> {
// FIXME: This is not correct...
if (stack == ItemStack.EMPTY) {
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
} else {
return filter.allowExtract(this, slot, this.getSlot(slot).get().getCount());
}
};
}
return ConstantItemFilter.ANYTHING;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if (this.maxStack[slot] == 0) {
return false;
}
if (this.filter != null) {
return this.filter.allowInsert(this, slot, stack);
}
return true;
}
public void writeToNBT(final CompoundTag data, final String name) {
data.put(name, this.toTag());
}
public void readFromNBT(final CompoundTag data, final String name) {
final CompoundTag c = data.getCompound(name);
if (c != null) {
this.readFromNBT(c);
}
}
public void readFromNBT(final CompoundTag data) {
this.fromTag(data);
}
@Override
public Iterator<ItemStack> iterator() {
return stackIterable().iterator();
}
private boolean isEnableClientEvents() {
return this.enableClientEvents;
}
public void setEnableClientEvents(final boolean enableClientEvents) {
this.enableClientEvents = enableClientEvents;
}
private IAEAppEngInventory getBlockEntity() {
return this.te;
}
public void setTileEntity(final IAEAppEngInventory te) {
this.te = te;
}
}
@@ -149,15 +149,15 @@ public class CellWorkbenchBlockEntity extends AEBaseBlockEntity
}
if (cellHasConfig) {
for (int x = 0; x < this.config.getSlots(); x++) {
this.config.setStackInSlot(x, configInventory.getInvStack(x));
for (int x = 0; x < this.config.getSlotCount(); x++) {
this.config.setInvStack(x, configInventory.getInvStack(x));
}
} else {
ItemHandlerUtil.copy(this.config, configInventory, false);
}
} else if (this.manager.getSetting(Settings.COPY_MODE) == CopyMode.CLEAR_ON_REMOVE) {
for (int x = 0; x < this.config.getSlots(); x++) {
this.config.setStackInSlot(x, ItemStack.EMPTY);
for (int x = 0; x < this.config.getSlotCount(); x++) {
this.config.setInvStack(x, ItemStack.EMPTY);
}
this.saveChanges();
@@ -81,9 +81,9 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
try {
final IAEItemStack item = AEItemStack.fromPacket(data);
final ItemStack is = item.createItemStack();
this.inv.setStackInSlot(0, is);
this.inv.setInvStack(0, is);
} catch (final Throwable t) {
this.inv.setStackInSlot(0, ItemStack.EMPTY);
this.inv.setInvStack(0, ItemStack.EMPTY);
}
return c; // TESR doesn't need updates!
}
@@ -121,7 +121,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG);
materials.certusQuartzCrystalCharged().maybeStack(myItem.getCount())
.ifPresent(charged -> this.inv.setStackInSlot(0, charged));
.ifPresent(charged -> this.inv.setInvStack(0, charged));
}
}
}
@@ -160,12 +160,12 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
if (AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs(held)
|| Platform.isChargeable(held)) {
held = player.inventory.decrStackSize(player.inventory.currentItem, 1);
this.inv.setStackInSlot(0, held);
this.inv.setInvStack(0, held);
}
} else {
final List<ItemStack> drops = new ArrayList<>();
drops.add(myItem);
this.inv.setStackInSlot(0, ItemStack.EMPTY);
this.inv.setInvStack(0, ItemStack.EMPTY);
Platform.spawnDrops(this.world, this.pos.offset(this.getForward()), drops);
}
}
@@ -222,7 +222,7 @@ public class ChargerBlockEntity extends AENetworkPowerBlockEntity implements ICr
this.extractAEPower(this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG);
materials.certusQuartzCrystalCharged().maybeStack(myItem.getCount())
.ifPresent(charged -> this.inv.setStackInSlot(0, charged));
.ifPresent(charged -> this.inv.setInvStack(0, charged));
changed = true;
}
@@ -261,7 +261,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
@Nonnull
@Override
public FluidVolume getFluid() {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Override
@@ -294,13 +294,13 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
@Nonnull
@Override
public FluidVolume drain(int maxDrain, FluidAction action) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Nonnull
@Override
public FluidVolume drain(FluidVolume resource, FluidAction action) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Override
@@ -311,7 +311,7 @@ public class CondenserBlockEntity extends AEBaseInvBlockEntity implements IConfi
@Nonnull
@Override
public FluidVolume getFluidInTank(int tank) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Override
@@ -198,7 +198,7 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
super.getDrops(w, pos, drops);
for (int h = 0; h < this.upgrades.getSlots(); h++) {
for (int h = 0; h < this.upgrades.getSlotCount(); h++) {
final ItemStack is = this.upgrades.getInvStack(h);
if (!is.isEmpty()) {
drops.add(is);
@@ -278,10 +278,10 @@ public class InscriberBlockEntity extends AENetworkPowerBlockEntity
if (this.sideItemHandler.insertItem(1, outputCopy, false).isEmpty()) {
this.setProcessingTime(0);
if (out.getProcessType() == InscriberProcessType.PRESS) {
this.topItemHandler.setStackInSlot(0, ItemStack.EMPTY);
this.bottomItemHandler.setStackInSlot(0, ItemStack.EMPTY);
this.topItemHandler.setInvStack(0, ItemStack.EMPTY);
this.bottomItemHandler.setInvStack(0, ItemStack.EMPTY);
}
this.sideItemHandler.setStackInSlot(0, ItemStack.EMPTY);
this.sideItemHandler.setInvStack(0, ItemStack.EMPTY);
}
}
this.saveChanges();
@@ -28,7 +28,7 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.block.BlockState;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
@@ -311,7 +311,7 @@ public class InterfaceBlockEntity extends AENetworkInvBlockEntity
}
@Override
public ContainerType<?> getContainerType() {
public ScreenHandlerType<?> getContainerType() {
return InterfaceContainer.TYPE;
}
}
@@ -184,7 +184,7 @@ public class SecurityStationBlockEntity extends AENetworkBlockEntity implements
this.getConfigSlot().readFromNBT(data, "config");
final CompoundTag storedItems = data.getCompound("storedItems");
for (final Object key : storedItems.keySet()) {
for (final Object key : storedItems.getKeys()) {
final INBT obj = storedItems.get((String) key);
if (obj instanceof CompoundTag) {
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(ItemStack.fromTag((CompoundTag) obj)));
@@ -217,9 +217,9 @@ public class VibrationChamberBlockEntity extends AENetworkInvBlockEntity impleme
is.decrement(1);
if (is.isEmpty()) {
this.inv.setStackInSlot(0, fuelItem.getRecipeRemainder(is));
this.inv.setInvStack(0, fuelItem.getRecipeRemainder(is));
} else {
this.inv.setStackInSlot(0, is);
this.inv.setInvStack(0, is);
}
this.saveChanges();
}
@@ -183,7 +183,7 @@ public class ControllerBlockEntity extends AENetworkPowerBlockEntity {
* @return true if there is a loaded controller
*/
private boolean checkController(final BlockPos pos) {
if (this.world.getChunkProvider().isChunkLoaded(new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4))) {
if (this.world.getChunkManager().isChunkLoaded(new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4))) {
return this.world.getBlockEntity(pos) instanceof ControllerBlockEntity;
}
@@ -25,6 +25,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
@@ -115,6 +116,11 @@ public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements
@Override
public Void call(final World world) throws Exception {
if (!(world instanceof ServerWorld)) {
return null;
}
ServerWorld serverWorld = (ServerWorld) world;
final ItemStack cell = this.inv.getInvStack(0);
if (this.isSpatialCell(cell) && this.inv.getInvStack(1).isEmpty()) {
final IGrid gi = this.getProxy().getGrid();
@@ -134,12 +140,12 @@ public class SpatialIOPortBlockEntity extends AENetworkInvBlockEntity implements
playerId = this.getProxy().getSecurity().getOwner();
}
final TransitionResult tr = sc.doSpatialTransition(cell, this.world, spc.getMin(), spc.getMax(),
final TransitionResult tr = sc.doSpatialTransition(cell, serverWorld, spc.getMin(), spc.getMax(),
playerId);
if (tr.success) {
energy.extractAEPower(req, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.inv.setStackInSlot(0, ItemStack.EMPTY);
this.inv.setStackInSlot(1, cell);
this.inv.setInvStack(0, ItemStack.EMPTY);
this.inv.setInvStack(1, cell);
}
}
}
@@ -29,7 +29,7 @@ import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
@@ -474,9 +474,9 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
AEItemStack.fromItemStack(this.inputInventory.getInvStack(0)), this.mySrc);
if (returns == null) {
this.inputInventory.setStackInSlot(0, ItemStack.EMPTY);
this.inputInventory.setInvStack(0, ItemStack.EMPTY);
} else {
this.inputInventory.setStackInSlot(0, returns.createItemStack());
this.inputInventory.setInvStack(0, returns.createItemStack());
}
}
}
@@ -714,7 +714,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
@Nonnull
@Override
public FluidVolume getFluid() {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Override
@@ -740,7 +740,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
@Nonnull
@Override
public FluidVolume getFluidInTank(int tank) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Override
@@ -773,13 +773,13 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
@Nonnull
@Override
public FluidVolume drain(FluidVolume resource, FluidAction action) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
@Nonnull
@Override
public FluidVolume drain(int maxDrain, FluidAction action) {
return FluidVolume.EMPTY;
return FluidVolumeUtil.EMPTY;
}
}
@@ -820,7 +820,7 @@ public class ChestBlockEntity extends AENetworkPowerBlockEntity
}
@Override
public ContainerType<?> getContainerType() {
public ScreenHandlerType<?> getContainerType() {
this.updateHandler();
if (this.cellHandler != null) {
if (this.cellHandler.getChannel() == AEApi.instance().storage()
@@ -26,13 +26,12 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
@@ -335,7 +334,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO
double power = 2.0;
for (int x = 0; x < this.inv.getSlots(); x++) {
for (int x = 0; x < this.inv.getSlotCount(); x++) {
final ItemStack is = this.inv.getInvStack(x);
this.invBySlot[x] = null;
this.handlersBySlot[x] = null;
@@ -444,7 +443,7 @@ public class DriveBlockEntity extends AENetworkInvBlockEntity implements IChestO
}
@Override
public ContainerType<?> getContainerType() {
public ScreenHandlerType<?> getContainerType() {
return DriveContainer.TYPE;
}
@@ -395,7 +395,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
private boolean moveSlot(final int x) {
final InventoryAdaptor ad = new AdaptorFixedInv(this.outputCells);
if (ad.addItems(this.inputCells.getInvStack(x)).isEmpty()) {
this.inputCells.setStackInSlot(x, ItemStack.EMPTY);
this.inputCells.setInvStack(x, ItemStack.EMPTY);
return true;
}
return false;
@@ -437,7 +437,7 @@ public class IOPortBlockEntity extends AENetworkInvBlockEntity
public void getDrops(final World w, final BlockPos pos, final List<ItemStack> drops) {
super.getDrops(w, pos, drops);
for (int upgradeIndex = 0; upgradeIndex < this.upgrades.getSlots(); upgradeIndex++) {
for (int upgradeIndex = 0; upgradeIndex < this.upgrades.getSlotCount(); upgradeIndex++) {
final ItemStack stackInSlot = this.upgrades.getInvStack(upgradeIndex);
if (!stackInSlot.isEmpty()) {
@@ -1,168 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.tile.storage;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tileentity.IChestLid;
import net.minecraft.util.Tickable;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.MathHelper;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import appeng.block.storage.SkyChestBlock;
import appeng.tile.AEBaseInvBlockEntity;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.inv.InvOperation;
public class SkyChestBlockEntity extends AEBaseInvBlockEntity implements Tickable, IChestLid {
private final AppEngInternalInventory inv = new AppEngInternalInventory(this, 9 * 4);
// server
private int numPlayersUsing;
// client..
private long lastEvent;
private float lidAngle;
private float prevLidAngle;
public SkyChestBlockEntity(BlockEntityType<? extends SkyChestBlockEntity> type) {
super(type);
}
@Override
protected void writeToStream(final PacketByteBuf data) throws IOException {
super.writeToStream(data);
data.writeBoolean(this.getPlayerOpen() > 0);
}
@Override
protected boolean readFromStream(final PacketByteBuf data) throws IOException {
final boolean c = super.readFromStream(data);
final int wasOpen = this.getPlayerOpen();
this.setPlayerOpen(data.readBoolean() ? 1 : 0);
if (wasOpen != this.getPlayerOpen()) {
this.setLastEvent(System.currentTimeMillis());
}
return c; // TESR yo!
}
@Override
public boolean canRenderBreaking() {
return true;
}
@Override
public FixedItemInv getInternalInventory() {
return this.inv;
}
public void openInventory(final PlayerEntity player) {
if (!player.isSpectator()) {
this.setPlayerOpen(this.getPlayerOpen() + 1);
onOpenOrClose();
if (this.getPlayerOpen() == 1) {
this.getWorld().playSound(player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F,
this.getWorld().rand.nextFloat() * 0.1F + 0.9F);
this.markForUpdate();
}
}
}
public void closeInventory(final PlayerEntity player) {
if (!player.isSpectator()) {
this.setPlayerOpen(this.getPlayerOpen() - 1);
onOpenOrClose();
if (this.getPlayerOpen() < 0) {
this.setPlayerOpen(0);
}
if (this.getPlayerOpen() == 0) {
this.getWorld().playSound(player, this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
this.pos.getZ() + 0.5D, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F,
this.getWorld().rand.nextFloat() * 0.1F + 0.9F);
this.markForUpdate();
}
}
}
// See ChestTileEntity
private void onOpenOrClose() {
Block block = getCachedState().getBlock();
if (block instanceof SkyChestBlock) {
this.world.addBlockEvent(this.pos, block, 1, this.numPlayersUsing);
this.world.updateNeighborsAlways(this.pos, block);
// FIXME: Uhm, we are we doing this?
this.world.updateNeighborsAlways(this.pos.down(), block);
}
}
@Override
public void tick() {
this.prevLidAngle = this.lidAngle;
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
if (this.numPlayersUsing > 0) {
this.lidAngle += 0.1F;
} else {
this.lidAngle -= 0.1F;
}
this.lidAngle = MathHelper.clamp(this.lidAngle, 0, 1);
}
}
@Override
public void onChangeInventory(final FixedItemInv inv, final int slot, final InvOperation mc,
final ItemStack removed, final ItemStack added) {
}
public int getPlayerOpen() {
return this.numPlayersUsing;
}
private void setPlayerOpen(final int playerOpen) {
this.numPlayersUsing = playerOpen;
}
public long getLastEvent() {
return this.lastEvent;
}
private void setLastEvent(final long lastEvent) {
this.lastEvent = lastEvent;
}
@Override
public float getLidAngle(float partialTicks) {
return MathHelper.lerp(partialTicks, this.prevLidAngle, this.lidAngle);
}
}