Fixed server crash. Fixes #2614

This commit is contained in:
raoulvdberge
2020-07-14 18:12:59 +02:00
parent 1dd8c2fbd0
commit 93e443b7aa
9 changed files with 83 additions and 24 deletions

View File

@@ -1,5 +1,8 @@
# Refined Storage Changelog
### 1.9.1
- Fixed server crash (raoulvdberge)
### 1.9
- Port to Minecraft 1.16 (raoulvdberge)
- Fixed wrench requiring shift click to rotate blocks (raoulvdberge)

View File

@@ -1,6 +1,7 @@
package com.refinedmods.refinedstorage;
import com.refinedmods.refinedstorage.item.*;
import com.refinedmods.refinedstorage.item.blockitem.ControllerBlockItem;
import com.refinedmods.refinedstorage.item.blockitem.PortableGridBlockItem;
import net.minecraftforge.registries.ObjectHolder;
@@ -24,6 +25,10 @@ public final class RSItems {
public static final NetworkCardItem NETWORK_CARD = null;
@ObjectHolder("security_card")
public static final SecurityCardItem SECURITY_CARD = null;
@ObjectHolder("controller")
public static final ControllerBlockItem CONTROLLER = null;
@ObjectHolder("creative_controller")
public static final ControllerBlockItem CREATIVE_CONTROLLER = null;
@ObjectHolder("construction_core")
public static final CoreItem CONSTRUCTION_CORE = null;
@ObjectHolder("destruction_core")

View File

@@ -7,7 +7,6 @@ import com.refinedmods.refinedstorage.util.NetworkUtils;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT;
@@ -32,8 +31,6 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
public NetworkItem(Item.Properties item, boolean creative, Supplier<Integer> energyCapacity) {
super(item, creative, energyCapacity);
ItemModelsProperties.func_239418_a_(this, new ResourceLocation("connected"), (stack, world, entity) -> (entity != null && isValid(stack)) ? 1.0f : 0.0f);
}
@Override
@@ -141,7 +138,7 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
return false;
}
public boolean isValid(ItemStack stack) {
public static boolean isValid(ItemStack stack) {
return stack.hasTag()
&& stack.getTag().contains(NBT_NODE_X)
&& stack.getTag().contains(NBT_NODE_Y)

View File

@@ -4,15 +4,12 @@ import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.network.security.Permission;
import com.refinedmods.refinedstorage.render.Styles;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.data.ItemModelProvider;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
@@ -31,8 +28,6 @@ public class SecurityCardItem extends Item {
super(new Item.Properties().group(RS.MAIN_GROUP).maxStackSize(1));
this.setRegistryName(RS.ID, "security_card");
ItemModelsProperties.func_239418_a_(this, new ResourceLocation("active"), (stack, world, entity) -> (entity != null && isValid(stack)) ? 1.0f : 0.0f);
}
@Override

View File

@@ -2,28 +2,13 @@ package com.refinedmods.refinedstorage.item.blockitem;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.network.NetworkType;
import com.refinedmods.refinedstorage.apiimpl.network.Network;
import com.refinedmods.refinedstorage.block.ControllerBlock;
import net.minecraft.data.ItemModelProvider;
import net.minecraft.item.Item;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
public class ControllerBlockItem extends EnergyBlockItem {
public ControllerBlockItem(ControllerBlock block) {
super(block, new Item.Properties().group(RS.MAIN_GROUP).maxStackSize(1), block.getType() == NetworkType.CREATIVE, () -> RS.SERVER_CONFIG.getController().getCapacity());
this.setRegistryName(block.getRegistryName());
ItemModelsProperties.func_239418_a_(this, new ResourceLocation("energy_type"), (stack, world, entity) -> {
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null);
if (storage != null) {
return Network.getEnergyType(storage.getEnergyStored(), storage.getMaxEnergyStored()).ordinal();
}
return ControllerBlock.EnergyType.OFF.ordinal();
});
}
}

View File

@@ -0,0 +1,24 @@
package com.refinedmods.refinedstorage.item.property;
import com.refinedmods.refinedstorage.apiimpl.network.Network;
import com.refinedmods.refinedstorage.block.ControllerBlock;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nullable;
public class ControllerItemPropertyGetter implements IItemPropertyGetter {
@Override
public float call(ItemStack stack, @Nullable ClientWorld p_call_2_, @Nullable LivingEntity p_call_3_) {
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY).orElse(null);
if (storage != null) {
return Network.getEnergyType(storage.getEnergyStored(), storage.getMaxEnergyStored()).ordinal();
}
return ControllerBlock.EnergyType.OFF.ordinal();
}
}

View File

@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage.item.property;
import com.refinedmods.refinedstorage.item.NetworkItem;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class NetworkItemPropertyGetter implements IItemPropertyGetter {
@Override
public float call(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity) {
return entity != null && NetworkItem.isValid(stack) ? 1.0f : 0.0f;
}
}

View File

@@ -0,0 +1,16 @@
package com.refinedmods.refinedstorage.item.property;
import com.refinedmods.refinedstorage.item.SecurityCardItem;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
public class SecurityCardItemPropertyGetter implements IItemPropertyGetter {
@Override
public float call(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity) {
return entity != null && SecurityCardItem.isValid(stack) ? 1.0f : 0.0f;
}
}

View File

@@ -5,6 +5,9 @@ import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.container.CrafterContainer;
import com.refinedmods.refinedstorage.container.CrafterManagerContainer;
import com.refinedmods.refinedstorage.container.slot.CrafterManagerSlot;
import com.refinedmods.refinedstorage.item.property.ControllerItemPropertyGetter;
import com.refinedmods.refinedstorage.item.property.NetworkItemPropertyGetter;
import com.refinedmods.refinedstorage.item.property.SecurityCardItemPropertyGetter;
import com.refinedmods.refinedstorage.render.BakedModelOverrideRegistry;
import com.refinedmods.refinedstorage.render.color.PatternItemColor;
import com.refinedmods.refinedstorage.render.model.*;
@@ -20,6 +23,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
@@ -242,6 +246,20 @@ public class ClientSetup {
ClientRegistry.bindTileEntityRenderer(RSTiles.STORAGE_MONITOR, StorageMonitorTileRenderer::new);
e.getMinecraftSupplier().get().getItemColors().register(new PatternItemColor(), RSItems.PATTERN);
ItemModelsProperties.func_239418_a_(RSItems.SECURITY_CARD, new ResourceLocation("active"), new SecurityCardItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.CONTROLLER, new ResourceLocation("energy_type"), new ControllerItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.CREATIVE_CONTROLLER, new ResourceLocation("energy_type"), new ControllerItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.WIRELESS_CRAFTING_MONITOR, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.CREATIVE_WIRELESS_CRAFTING_MONITOR, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.WIRELESS_GRID, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.CREATIVE_WIRELESS_GRID, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.WIRELESS_FLUID_GRID, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
ItemModelsProperties.func_239418_a_(RSItems.CREATIVE_WIRELESS_FLUID_GRID, new ResourceLocation("connected"), new NetworkItemPropertyGetter());
}
@SubscribeEvent