Fixed errors when booting in dedicated server environment.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -25,3 +25,7 @@ logs
|
||||
# Files from Forge MDK
|
||||
forge*changelog.txt
|
||||
/src/generated/
|
||||
|
||||
#vscode
|
||||
|
||||
.vscode
|
||||
@@ -6,6 +6,7 @@ import li.cil.oc2.client.model.BusCableModelLoader;
|
||||
import li.cil.oc2.client.renderer.NetworkCableRenderer;
|
||||
import li.cil.oc2.client.renderer.tileentity.ComputerTileEntityRenderer;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.common.container.Containers;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
@@ -15,12 +16,14 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
public final class ClientSetup {
|
||||
@SubscribeEvent
|
||||
public static void handleSetupEvent(final FMLClientSetupEvent event) {
|
||||
NetworkCableRenderer.initialize();
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(DeviceTypes::handleTextureStitchEvent);
|
||||
ScreenManager.registerFactory(Containers.COMPUTER_CONTAINER.get(), ComputerContainerScreen::new);
|
||||
|
||||
ClientRegistry.bindTileEntityRenderer(TileEntities.COMPUTER_TILE_ENTITY.get(), ComputerTileEntityRenderer::new);
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
@@ -162,8 +163,8 @@ public final class ComputerBlock extends HorizontalBlock {
|
||||
final ComputerTileEntity computer = (ComputerTileEntity) tileEntity;
|
||||
final ItemStack heldItem = player.getHeldItem(hand);
|
||||
if (Wrenches.isWrench(heldItem)) {
|
||||
if (player instanceof ServerPlayerEntity) {
|
||||
openContainerScreen(computer, (ServerPlayerEntity) player);
|
||||
if (!world.isRemote() && player instanceof ServerPlayerEntity) {
|
||||
openContainerScreen(computer, player);
|
||||
}
|
||||
} else {
|
||||
if (player.isSneaking()) {
|
||||
@@ -210,15 +211,16 @@ public final class ComputerBlock extends HorizontalBlock {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void openTerminalScreen(final ComputerTileEntity computer) {
|
||||
Minecraft.getInstance().displayGuiScreen(new TerminalScreen(computer, getTranslatedName()));
|
||||
}
|
||||
|
||||
private void openContainerScreen(final ComputerTileEntity tileEntity, final ServerPlayerEntity player) {
|
||||
NetworkHooks.openGui(player, new INamedContainerProvider() {
|
||||
private void openContainerScreen(final ComputerTileEntity tileEntity, final PlayerEntity player) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new INamedContainerProvider() {
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return getTranslatedName();
|
||||
return new TranslationTextComponent(getTranslationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,8 +6,10 @@ import li.cil.oc2.common.bus.device.util.DeviceTypeImpl;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.RegistryBuilder;
|
||||
@@ -31,7 +33,6 @@ public final class DeviceTypes {
|
||||
|
||||
DEVICE_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(DeviceTypes::handleTextureStitchEvent);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -43,7 +44,7 @@ public final class DeviceTypes {
|
||||
));
|
||||
}
|
||||
|
||||
private static void handleTextureStitchEvent(final TextureStitchEvent.Pre event) {
|
||||
public static void handleTextureStitchEvent(final TextureStitchEvent.Pre event) {
|
||||
if (event.getMap().getTextureLocation() != PlayerContainer.LOCATION_BLOCKS_TEXTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import li.cil.oc2.common.util.NBTTagIds;
|
||||
import li.cil.oc2.common.util.TextFormatUtils;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemModelsProperties;
|
||||
@@ -13,6 +12,9 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
|
||||
public abstract class AbstractStorageItem extends Item {
|
||||
public static final ResourceLocation CAPACITY_PROPERTY = new ResourceLocation(API.MOD_ID, "capacity");
|
||||
@@ -49,7 +51,10 @@ public abstract class AbstractStorageItem extends Item {
|
||||
public AbstractStorageItem(final Properties properties, final int defaultCapacity) {
|
||||
super(properties);
|
||||
this.defaultCapacity = defaultCapacity;
|
||||
ItemModelsProperties.registerProperty(this, CAPACITY_PROPERTY, AbstractStorageItem::getCapacityProperty);
|
||||
|
||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
||||
ItemModelsProperties.registerProperty(this, CAPACITY_PROPERTY, AbstractStorageItem::getCapacityProperty);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -71,7 +76,7 @@ public abstract class AbstractStorageItem extends Item {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static float getCapacityProperty(final ItemStack stack, final ClientWorld world, final LivingEntity entity) {
|
||||
private static float getCapacityProperty(final ItemStack stack, final World world, final LivingEntity entity) {
|
||||
return getCapacity(stack);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user