First Container opens (Sky Chest)
This commit is contained in:
@@ -21,9 +21,13 @@ package appeng.block.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.container.implementations.ContainerSkyChest;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.inventory.container.SimpleNamedContainerProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
@@ -40,6 +44,7 @@ import net.minecraft.world.World;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.tile.storage.TileSkyChest;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
|
||||
|
||||
public class BlockSkyChest extends AEBaseTileBlock<TileSkyChest>
|
||||
@@ -77,6 +82,15 @@ public class BlockSkyChest extends AEBaseTileBlock<TileSkyChest>
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
TileSkyChest tile = getTileEntity(w, pos);
|
||||
if (tile == null) {
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
INamedContainerProvider container = new SimpleNamedContainerProvider((wnd, p, pl) -> new ContainerSkyChest(wnd, p, tile), getNameTextComponent());
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, container, buf -> {
|
||||
buf.writeBlockPos(pos);
|
||||
});
|
||||
|
||||
// FIXME Platform.openGUI( player, this.getTileEntity( w, pos ), AEPartLocation.fromFacing(hit.getFace()), GuiBridge.GUI_SKYCHEST );
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
//TODO, pass generic up here for Container
|
||||
public abstract class AEBaseGui extends ContainerScreen<AEBaseContainer>
|
||||
public abstract class AEBaseGui<T extends AEBaseContainer> extends ContainerScreen<T>
|
||||
{
|
||||
private final List<InternalSlotME> meSlots = new ArrayList<>();
|
||||
// drag y
|
||||
@@ -90,7 +90,7 @@ public abstract class AEBaseGui extends ContainerScreen<AEBaseContainer>
|
||||
private Slot bl_clicked;
|
||||
protected final List<GuiCustomSlot> guiSlots = new ArrayList<>();
|
||||
|
||||
public AEBaseGui(AEBaseContainer container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
public AEBaseGui(T container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
}
|
||||
|
||||
@@ -940,6 +940,11 @@ public abstract class AEBaseGui extends ContainerScreen<AEBaseContainer>
|
||||
this.minecraft.getTextureManager().bindTexture( loc );
|
||||
}
|
||||
|
||||
public void bindTexture( final ResourceLocation loc )
|
||||
{
|
||||
this.minecraft.getTextureManager().bindTexture( loc );
|
||||
}
|
||||
|
||||
protected GuiScrollbar getScrollBar()
|
||||
{
|
||||
return this.myScrollBar;
|
||||
|
||||
@@ -19,21 +19,25 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.container.implementations.ContainerSkyChest;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.integration.Integrations;
|
||||
import appeng.tile.storage.TileSkyChest;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||
|
||||
|
||||
public class GuiSkyChest extends AEBaseGui
|
||||
public class GuiSkyChest extends AEBaseGui<ContainerSkyChest>
|
||||
{
|
||||
|
||||
public GuiSkyChest( final PlayerInventory PlayerInventory, final TileSkyChest te )
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(AppEng.MOD_ID, "textures/guis/skychest.png");
|
||||
|
||||
public GuiSkyChest( ContainerSkyChest container, PlayerInventory playerInv, ITextComponent title )
|
||||
{
|
||||
super( new ContainerSkyChest( PlayerInventory, te ) );
|
||||
super( container, playerInv, title );
|
||||
this.ySize = 195;
|
||||
}
|
||||
|
||||
@@ -47,13 +51,14 @@ public class GuiSkyChest extends AEBaseGui
|
||||
@Override
|
||||
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
|
||||
{
|
||||
this.bindTexture( "guis/skychest.png" );
|
||||
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize );
|
||||
bindTexture(TEXTURE);
|
||||
GuiUtils.drawTexturedModalRect( offsetX, offsetY, 0, 0, this.xSize, this.ySize, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean enableSpaceClicking()
|
||||
{
|
||||
return !Integrations.invTweaks().isEnabled();
|
||||
// FIXME return !Integrations.invTweaks().isEnabled();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,29 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotNormal;
|
||||
import appeng.tile.storage.TileSkyChest;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
public class ContainerSkyChest extends AEBaseContainer
|
||||
{
|
||||
public static ContainerType<ContainerSkyChest> TYPE;
|
||||
|
||||
private final TileSkyChest chest;
|
||||
|
||||
public ContainerSkyChest( final PlayerInventory ip, final TileSkyChest chest )
|
||||
public ContainerSkyChest(int id, final PlayerInventory ip, final TileSkyChest chest )
|
||||
{
|
||||
super( ip, chest, null );
|
||||
super( TYPE, id, ip, chest, null );
|
||||
this.chest = chest;
|
||||
|
||||
for( int y = 0; y < 4; y++ )
|
||||
@@ -50,6 +57,15 @@ public class ContainerSkyChest extends AEBaseContainer
|
||||
this.bindPlayerInventory( ip, 0, 195 - /* height of player inventory */82 );
|
||||
}
|
||||
|
||||
public static ContainerSkyChest fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
|
||||
BlockPos pos = buf.readBlockPos();
|
||||
TileEntity te = Minecraft.getInstance().player.world.getTileEntity(pos);
|
||||
if (te instanceof TileSkyChest) {
|
||||
return new ContainerSkyChest(windowId, inv, (TileSkyChest) te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed( final PlayerEntity par1PlayerEntity )
|
||||
{
|
||||
|
||||
@@ -108,6 +108,7 @@ public final class AppEng
|
||||
modEventBus.addGenericListener(EntityType.class, registration::registerEntities);
|
||||
modEventBus.addGenericListener(ParticleType.class, registration::registerParticleTypes);
|
||||
modEventBus.addGenericListener(TileEntityType.class, registration::registerTileEntities);
|
||||
modEventBus.addGenericListener(ContainerType.class, registration::registerContainerTypes);
|
||||
modEventBus.addListener(registration::registerParticleFactories);
|
||||
modEventBus.addListener(registration::registerTextures);
|
||||
|
||||
|
||||
@@ -21,17 +21,21 @@ package appeng.core;
|
||||
|
||||
import appeng.bootstrap.IModelRegistry;
|
||||
import appeng.bootstrap.components.*;
|
||||
import appeng.client.gui.implementations.GuiSkyChest;
|
||||
import appeng.client.render.effects.ChargedOreFX;
|
||||
import appeng.client.render.effects.LightningFX;
|
||||
import appeng.client.render.effects.VibrantFX;
|
||||
import appeng.client.render.model.GlassModelLoader;
|
||||
import appeng.client.render.tesr.SkyChestTESR;
|
||||
import appeng.container.implementations.ContainerSkyChest;
|
||||
import appeng.core.stats.AeStats;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.renderer.ItemModelMesher;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.particles.ParticleType;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -42,9 +46,14 @@ import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.GenericEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
|
||||
final class Registration
|
||||
@@ -226,6 +235,17 @@ final class Registration
|
||||
definitions.getRegistry().getBootstrapComponents( ITileEntityRegistrationComponent.class ).forEachRemaining(b -> b.register( registry ) );
|
||||
}
|
||||
|
||||
public void registerContainerTypes( RegistryEvent.Register<ContainerType<?>> event ) {
|
||||
final IForgeRegistry<ContainerType<?>> registry = event.getRegistry();
|
||||
|
||||
ContainerSkyChest.TYPE = IForgeContainerType.create(ContainerSkyChest::fromNetwork);
|
||||
registry.register(ContainerSkyChest.TYPE.setRegistryName(AppEng.MOD_ID, "sky_chest"));
|
||||
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
||||
ScreenManager.registerFactory(ContainerSkyChest.TYPE, GuiSkyChest::new);
|
||||
});
|
||||
}
|
||||
|
||||
// @SubscribeEvent
|
||||
// public void registerRecipes( RegistryEvent.Register<IRecipe> event )
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user