Begin work on Iron Chests for 1.15!
This commit is contained in:
parent
b09f7f3f09
commit
94c6f7c08b
|
@ -34,7 +34,7 @@ minecraft {
|
|||
workingDirectory project.file('run')
|
||||
|
||||
// Recommended logging data for a userdev environment
|
||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP,CORE'
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP,CORE'
|
||||
|
||||
// Recommended logging level for the console
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
|
@ -50,7 +50,7 @@ minecraft {
|
|||
workingDirectory project.file('run')
|
||||
|
||||
// Recommended logging data for a userdev environment
|
||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP,CORE'
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP,CORE'
|
||||
|
||||
// Recommended logging level for the console
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
|
|
|
@ -4,15 +4,15 @@ org.gradle.jvmargs=-Xmx3G
|
|||
org.gradle.daemon=false
|
||||
|
||||
# Mod Version Information
|
||||
mod_version=9.1
|
||||
mod_version=10.0
|
||||
|
||||
# Minecraft Version Information
|
||||
minecraft_version=1.14.4
|
||||
minecraft_version_toml=14
|
||||
minecraft_version=1.15.1
|
||||
minecraft_version_toml=15
|
||||
|
||||
# Forge Version Information
|
||||
forge_version=28.1.1
|
||||
forge_version_toml=28
|
||||
forge_version=30.0.18
|
||||
forge_version_toml=30
|
||||
|
||||
# Mappings Information
|
||||
mappings_version=20190912-1.14.3
|
||||
mappings_version=20191217-1.14.3
|
|
@ -1,49 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest;
|
||||
|
||||
import com.progwml6.ironchest.client.ClientProxy;
|
||||
import com.progwml6.ironchest.common.ServerProxy;
|
||||
import com.progwml6.ironchest.common.ai.CatsSitOnChestsHandler;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainerType;
|
||||
import com.progwml6.ironchest.common.network.PacketHandler;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(value = IronChest.MOD_ID)
|
||||
public class IronChest
|
||||
{
|
||||
public static final String MOD_ID = "ironchest";
|
||||
|
||||
public static IronChest instance;
|
||||
|
||||
public static ServerProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
|
||||
|
||||
public IronChest()
|
||||
{
|
||||
instance = this;
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::preInit);
|
||||
MinecraftForge.EVENT_BUS.register(new CatsSitOnChestsHandler());
|
||||
}
|
||||
|
||||
private void preInit(final FMLCommonSetupEvent event)
|
||||
{
|
||||
proxy.preInit();
|
||||
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> ChestContainerType::registerScreenFactories);
|
||||
|
||||
PacketHandler.register();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.progwml6.ironchest;
|
||||
|
||||
import com.progwml6.ironchest.client.data.IronChestsLangProvider;
|
||||
import com.progwml6.ironchest.client.screen.IronChestScreen;
|
||||
import com.progwml6.ironchest.client.tileentity.IronChestTileEntityRenderer;
|
||||
import com.progwml6.ironchest.client.tileentity.IronChestsModels;
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestsContainerTypes;
|
||||
import com.progwml6.ironchest.common.item.IronChestsItems;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(IronChests.MODID)
|
||||
public class IronChests {
|
||||
|
||||
public static final String MODID = "ironchest";
|
||||
|
||||
public static final ItemGroup IRONCHESTS_ITEM_GROUP = (new ItemGroup("ironchest") {
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public ItemStack createIcon() {
|
||||
return new ItemStack(IronChestsBlocks.IRON_CHEST.get());
|
||||
}
|
||||
});
|
||||
|
||||
public IronChests() {
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
// General mod setup
|
||||
modBus.addListener(this::setup);
|
||||
modBus.addListener(this::gatherData);
|
||||
|
||||
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
||||
// Client setup
|
||||
modBus.addListener(this::setupClient);
|
||||
new IronChestsModels();
|
||||
});
|
||||
|
||||
// Registry objects
|
||||
IronChestsBlocks.BLOCKS.register(modBus);
|
||||
IronChestsItems.ITEMS.register(modBus);
|
||||
IronChestsTileEntityTypes.TILE_ENTITIES.register(modBus);
|
||||
IronChestsContainerTypes.CONTAINERS.register(modBus);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void setupClient(final FMLClientSetupEvent event) {
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.IRON_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.GOLD_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.DIAMOND_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.CRYSTAL_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.COPPER_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.SILVER_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new);
|
||||
ScreenManager.registerFactory(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new);
|
||||
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.DIAMOND_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.COPPER_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.SILVER_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.CRYSTAL_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.OBSIDIAN_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.DIRT_CHEST.get(), IronChestTileEntityRenderer::new);
|
||||
}
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event) {
|
||||
|
||||
}
|
||||
|
||||
private void gatherData(GatherDataEvent event) {
|
||||
DataGenerator gen = event.getGenerator();
|
||||
|
||||
if (event.includeClient()) {
|
||||
gen.addProvider(new IronChestsLangProvider(gen));
|
||||
}
|
||||
if (event.includeServer()) {
|
||||
//gen.addProvider(new TropicraftLootTableProvider(gen));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.client;
|
||||
|
||||
import com.progwml6.ironchest.client.renderer.IronChestTileEntityRenderer;
|
||||
import com.progwml6.ironchest.common.ServerProxy;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
|
||||
public class ClientProxy extends ServerProxy
|
||||
{
|
||||
public ClientProxy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void preInit()
|
||||
{
|
||||
super.preInit();
|
||||
|
||||
for (ChestType type : ChestType.values())
|
||||
{
|
||||
if (type.clazz != null)
|
||||
{
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(type.clazz, new IronChestTileEntityRenderer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getClientWorld()
|
||||
{
|
||||
return Minecraft.getInstance().world;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.progwml6.ironchest.client.data;
|
||||
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.client.model.generators.ExistingFileHelper;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
|
||||
public class IronChestsItemModelProvider extends ItemModelProvider {
|
||||
|
||||
public IronChestsItemModelProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) {
|
||||
super(generator, IronChests.MODID, existingFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerModels() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Iron Chests Item Models";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.progwml6.ironchest.client.data;
|
||||
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraftforge.common.data.LanguageProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IronChestsLangProvider extends LanguageProvider {
|
||||
|
||||
private static class AccessibleLanguageProvider extends LanguageProvider {
|
||||
|
||||
public AccessibleLanguageProvider(DataGenerator gen, String modid, String locale) {
|
||||
super(gen, modid, locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(String key, String value) {
|
||||
super.add(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTranslations() {
|
||||
}
|
||||
}
|
||||
|
||||
private final AccessibleLanguageProvider upsideDown;
|
||||
|
||||
public IronChestsLangProvider(DataGenerator gen) {
|
||||
super(gen, IronChests.MODID, "en_us");
|
||||
this.upsideDown = new AccessibleLanguageProvider(gen, IronChests.MODID, "en_ud");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTranslations() {
|
||||
|
||||
}
|
||||
|
||||
// Automatic en_ud generation
|
||||
|
||||
private static final String NORMAL_CHARS =
|
||||
/* lowercase */ "abcdefghijklmn\u00F1opqrstuvwxyz" +
|
||||
/* uppercase */ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
/* numbers */ "0123456789" +
|
||||
/* special */ "_,;.?!/\\'";
|
||||
private static final String UPSIDE_DOWN_CHARS =
|
||||
/* lowercase */ "\u0250q\u0254p\u01DD\u025Fb\u0265\u0131\u0638\u029E\u05DF\u026Fuuodb\u0279s\u0287n\u028C\u028Dx\u028Ez" +
|
||||
/* uppercase */ "\u2C6F\u15FA\u0186\u15E1\u018E\u2132\u2141HI\u017F\u029E\uA780WNO\u0500\u1F49\u1D1AS\u27D8\u2229\u039BMX\u028EZ" +
|
||||
/* numbers */ "0\u0196\u1105\u0190\u3123\u03DB9\u312586" +
|
||||
/* special */ "\u203E'\u061B\u02D9\u00BF\u00A1/\\,";
|
||||
|
||||
static {
|
||||
if (NORMAL_CHARS.length() != UPSIDE_DOWN_CHARS.length()) {
|
||||
throw new AssertionError("Char maps do not match in length!");
|
||||
}
|
||||
}
|
||||
|
||||
private String toUpsideDown(String normal) {
|
||||
char[] ud = new char[normal.length()];
|
||||
for (int i = 0; i < normal.length(); i++) {
|
||||
char c = normal.charAt(i);
|
||||
if (c == '%') {
|
||||
String fmtArg = "";
|
||||
while (Character.isDigit(c) || c == '%' || c == '$' || c == 's' || c == 'd') { // TODO this is a bit lazy
|
||||
fmtArg += c;
|
||||
i++;
|
||||
c = i == normal.length() ? 0 : normal.charAt(i);
|
||||
}
|
||||
i--;
|
||||
for (int j = 0; j < fmtArg.length(); j++) {
|
||||
ud[normal.length() - 1 - i + j] = fmtArg.charAt(j);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int lookup = NORMAL_CHARS.indexOf(c);
|
||||
if (lookup >= 0) {
|
||||
c = UPSIDE_DOWN_CHARS.charAt(lookup);
|
||||
}
|
||||
ud[normal.length() - 1 - i] = c;
|
||||
}
|
||||
return new String(ud);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void add(String key, String value) {
|
||||
super.add(key, value);
|
||||
this.upsideDown.add(key, this.toUpsideDown(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(DirectoryCache cache) throws IOException {
|
||||
super.act(cache);
|
||||
this.upsideDown.act(cache);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.client.inventory;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.client.gui.IHasContainer;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ChestScreen extends ContainerScreen<ChestContainer> implements IHasContainer<ChestContainer>
|
||||
{
|
||||
private ChestType chestType;
|
||||
|
||||
private int textureXSize;
|
||||
|
||||
private int textureYSize;
|
||||
|
||||
public ChestScreen(ChestContainer container, PlayerInventory playerInventory, ITextComponent title)
|
||||
{
|
||||
super(container, playerInventory, title);
|
||||
|
||||
this.chestType = container.getChestType();
|
||||
this.xSize = container.getChestType().xSize;
|
||||
this.ySize = container.getChestType().ySize;
|
||||
this.textureXSize = container.getChestType().textureXSize;
|
||||
this.textureYSize = container.getChestType().textureYSize;
|
||||
|
||||
this.passEvents = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.renderBackground();
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
this.renderHoveredToolTip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
||||
{
|
||||
this.font.drawString(this.title.getFormattedText(), 8.0F, 6.0F, 4210752);
|
||||
this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 2), 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
|
||||
{
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.minecraft.getTextureManager().bindTexture(this.chestType.guiTexture);
|
||||
|
||||
int x = (this.width - this.xSize) / 2;
|
||||
int y = (this.height - this.ySize) / 2;
|
||||
|
||||
this.blit(x, y, 0, 0, this.xSize, this.ySize, textureXSize, textureYSize);
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.client.renderer;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.DiamondChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.DirtChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.GoldChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.ObsidianChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.SilverChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class IronChestItemStackTileEntityRenderer extends ItemStackTileEntityRenderer
|
||||
{
|
||||
private static final IronChestTileEntity IRON_CHEST = new IronChestTileEntity();
|
||||
|
||||
private static final GoldChestTileEntity GOLD_CHEST = new GoldChestTileEntity();
|
||||
|
||||
private static final DiamondChestTileEntity DIAMOND_CHEST = new DiamondChestTileEntity();
|
||||
|
||||
private static final CopperChestTileEntity COPPER_CHEST = new CopperChestTileEntity();
|
||||
|
||||
private static final SilverChestTileEntity SILVER_CHEST = new SilverChestTileEntity();
|
||||
|
||||
private static final CrystalChestTileEntity CRYSTAL_CHEST = new CrystalChestTileEntity();
|
||||
|
||||
private static final ObsidianChestTileEntity OBSIDIAN_CHEST = new ObsidianChestTileEntity();
|
||||
|
||||
private static final DirtChestTileEntity DIRT_CHEST = new DirtChestTileEntity();
|
||||
|
||||
private static final IronChestTileEntity[] CHESTS = { IRON_CHEST, GOLD_CHEST, DIAMOND_CHEST, COPPER_CHEST, SILVER_CHEST, CRYSTAL_CHEST, OBSIDIAN_CHEST, DIRT_CHEST };
|
||||
|
||||
public static IronChestItemStackTileEntityRenderer instance = new IronChestItemStackTileEntityRenderer();
|
||||
|
||||
@Override
|
||||
public void renderByItem(ItemStack itemStackIn)
|
||||
{
|
||||
Item item = itemStackIn.getItem();
|
||||
|
||||
if (Block.getBlockFromItem(item) instanceof ChestBlock)
|
||||
{
|
||||
ChestType typeOut = ChestBlock.getTypeFromItem(item);
|
||||
if (typeOut == null)
|
||||
{
|
||||
TileEntityRendererDispatcher.instance.renderAsItem(IRON_CHEST);
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntityRendererDispatcher.instance.renderAsItem(CHESTS[typeOut.ordinal()]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.renderByItem(itemStackIn);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.client.renderer;
|
||||
|
||||
import com.google.common.primitives.SignedBytes;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.model.ChestModel;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> extends TileEntityRenderer<T>
|
||||
{
|
||||
private final ChestModel chestModel = new ChestModel();
|
||||
|
||||
private static ItemEntity customItem;
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
private ItemRenderer itemRenderer;
|
||||
|
||||
private static float[][] shifts = { { 0.3F, 0.45F, 0.3F }, { 0.7F, 0.45F, 0.3F }, { 0.3F, 0.45F, 0.7F }, { 0.7F, 0.45F, 0.7F }, { 0.3F, 0.1F, 0.3F }, { 0.7F, 0.1F, 0.3F }, { 0.3F, 0.1F, 0.7F }, { 0.7F, 0.1F, 0.7F }, { 0.5F, 0.32F, 0.5F } };
|
||||
|
||||
@Override
|
||||
public void render(T tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage)
|
||||
{
|
||||
GlStateManager.enableDepthTest();
|
||||
GlStateManager.depthFunc(515);
|
||||
GlStateManager.depthMask(true);
|
||||
|
||||
IronChestTileEntity tileEntity = (IronChestTileEntity) tileEntityIn;
|
||||
|
||||
BlockState blockstate = tileEntity.hasWorld() ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().getDefaultState().with(ChestBlock.FACING, Direction.SOUTH);
|
||||
ChestType chestType = ChestType.IRON;
|
||||
ChestType actualType = ChestBlock.getTypeFromBlock(blockstate.getBlock());
|
||||
|
||||
if (actualType != null)
|
||||
{
|
||||
chestType = actualType;
|
||||
}
|
||||
|
||||
if (destroyStage >= 0)
|
||||
{
|
||||
this.bindTexture(DESTROY_STAGES[destroyStage]);
|
||||
GlStateManager.matrixMode(5890);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scalef(4.0F, 4.0F, 1.0F);
|
||||
GlStateManager.translatef(0.0625F, 0.0625F, 0.0625F);
|
||||
GlStateManager.matrixMode(5888);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bindTexture(new ResourceLocation("ironchest", "textures/model/" + chestType.modelTexture));
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
if (chestType == ChestType.CRYSTAL)
|
||||
{
|
||||
GlStateManager.disableCull();
|
||||
}
|
||||
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.translatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
|
||||
GlStateManager.scalef(1.0F, -1.0F, -1.0F);
|
||||
|
||||
float f = blockstate.get(ChestBlock.FACING).getHorizontalAngle();
|
||||
if ((double) Math.abs(f) > 1.0E-5D)
|
||||
{
|
||||
GlStateManager.translatef(0.5F, 0.5F, 0.5F);
|
||||
GlStateManager.rotatef(f, 0.0F, 1.0F, 0.0F);
|
||||
GlStateManager.translatef(-0.5F, -0.5F, -0.5F);
|
||||
}
|
||||
|
||||
if (chestType.isTransparent())
|
||||
{
|
||||
GlStateManager.scalef(1F, 0.99F, 1F);
|
||||
}
|
||||
|
||||
this.rotateChestLid(tileEntityIn, partialTicks, this.chestModel);
|
||||
this.chestModel.renderAll();
|
||||
GlStateManager.disableRescaleNormal();
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
if (chestType == ChestType.CRYSTAL)
|
||||
{
|
||||
GlStateManager.enableCull();
|
||||
}
|
||||
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if (destroyStage >= 0)
|
||||
{
|
||||
GlStateManager.matrixMode(5890);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.matrixMode(5888);
|
||||
}
|
||||
|
||||
if (this.rendererDispatcher.renderInfo != null)
|
||||
{
|
||||
if (chestType.isTransparent() && tileEntity.getDistanceSq(this.rendererDispatcher.renderInfo.getProjectedView().x, this.rendererDispatcher.renderInfo.getProjectedView().y, this.rendererDispatcher.renderInfo.getProjectedView().z) < 128d)
|
||||
{
|
||||
this.random.setSeed(254L);
|
||||
float shiftX;
|
||||
float shiftY;
|
||||
float shiftZ;
|
||||
int shift = 0;
|
||||
float blockScale = 0.70F;
|
||||
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
|
||||
|
||||
if (((CrystalChestTileEntity) tileEntity).getTopItems().get(1).isEmpty())
|
||||
{
|
||||
shift = 8;
|
||||
blockScale = 0.85F;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translatef((float) x, (float) y, (float) z);
|
||||
|
||||
if (customItem == null)
|
||||
{
|
||||
customItem = new ItemEntity(EntityType.ITEM, this.getWorld());
|
||||
}
|
||||
|
||||
for (ItemStack item : ((CrystalChestTileEntity) tileEntity).getTopItems())
|
||||
{
|
||||
if (shift > shifts.length || shift > 8)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.isEmpty())
|
||||
{
|
||||
shift++;
|
||||
continue;
|
||||
}
|
||||
|
||||
shiftX = shifts[shift][0];
|
||||
shiftY = shifts[shift][1];
|
||||
shiftZ = shifts[shift][2];
|
||||
shift++;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translatef(shiftX, shiftY, shiftZ);
|
||||
GlStateManager.rotatef(timeD, 0F, 1F, 0F);
|
||||
GlStateManager.scalef(blockScale, blockScale, blockScale);
|
||||
|
||||
customItem.setItem(item);
|
||||
|
||||
if (this.itemRenderer == null)
|
||||
{
|
||||
this.itemRenderer = new ItemRenderer(Minecraft.getInstance().getRenderManager(), Minecraft.getInstance().getItemRenderer())
|
||||
{
|
||||
@Override
|
||||
public int getModelCount(ItemStack stack)
|
||||
{
|
||||
return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBob()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSpreadItems()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.itemRenderer.doRender(customItem, 0D, 0D, 0D, 0F, partialTicks);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void rotateChestLid(T tileEntity, float partialTicks, ChestModel chestModel)
|
||||
{
|
||||
float f = ((IChestLid) tileEntity).getLidAngle(partialTicks);
|
||||
f = 1.0F - f;
|
||||
f = 1.0F - f * f * f;
|
||||
chestModel.getLid().rotateAngleX = -(f * ((float) Math.PI / 2F));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.progwml6.ironchest.client.screen;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.client.gui.IHasContainer;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class IronChestScreen extends ContainerScreen<IronChestContainer> implements IHasContainer<IronChestContainer> {
|
||||
|
||||
private IronChestsTypes chestType;
|
||||
|
||||
private int textureXSize;
|
||||
|
||||
private int textureYSize;
|
||||
|
||||
public IronChestScreen(IronChestContainer container, PlayerInventory playerInventory, ITextComponent title) {
|
||||
super(container, playerInventory, title);
|
||||
|
||||
this.chestType = container.getChestType();
|
||||
this.xSize = container.getChestType().xSize;
|
||||
this.ySize = container.getChestType().ySize;
|
||||
this.textureXSize = container.getChestType().textureXSize;
|
||||
this.textureYSize = container.getChestType().textureYSize;
|
||||
|
||||
this.passEvents = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground();
|
||||
super.render(mouseX, mouseY, partialTicks);
|
||||
this.renderHoveredToolTip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
this.font.drawString(this.title.getFormattedText(), 8.0F, 6.0F, 4210752);
|
||||
this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0F, (float) (this.ySize - 96 + 2), 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
this.minecraft.getTextureManager().bindTexture(this.chestType.guiTexture);
|
||||
|
||||
int x = (this.width - this.xSize) / 2;
|
||||
int y = (this.height - this.ySize) / 2;
|
||||
|
||||
blit(x, y, 0, 0, this.xSize, this.ySize, this.textureXSize, this.textureYSize);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.progwml6.ironchest.client.tileentity;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class IronChestItemStackRenderer<T extends TileEntity> extends ItemStackTileEntityRenderer {
|
||||
|
||||
private final Supplier<T> te;
|
||||
|
||||
public IronChestItemStackRenderer(Supplier<T> te) {
|
||||
this.te = te;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_228364_a_(ItemStack itemStackIn, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_228364_4_, int p_228364_5_) {
|
||||
TileEntityRendererDispatcher.instance.func_228852_a_(this.te.get(), matrixStack, iRenderTypeBuffer, p_228364_4_, p_228364_5_);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.progwml6.ironchest.client.tileentity;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.DualBrightnessCallback;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.state.properties.ChestType;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMerger;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> extends TileEntityRenderer<T> {
|
||||
|
||||
private final ModelRenderer chestLid;
|
||||
private final ModelRenderer chestBottom;
|
||||
private final ModelRenderer chestLock;
|
||||
|
||||
public IronChestTileEntityRenderer(TileEntityRendererDispatcher tileEntityRendererDispatcher) {
|
||||
super(tileEntityRendererDispatcher);
|
||||
|
||||
this.chestBottom = new ModelRenderer(64, 64, 0, 19);
|
||||
this.chestBottom.func_228301_a_(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
|
||||
this.chestLid = new ModelRenderer(64, 64, 0, 0);
|
||||
this.chestLid.func_228301_a_(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.chestLid.rotationPointY = 9.0F;
|
||||
this.chestLid.rotationPointZ = 1.0F;
|
||||
this.chestLock = new ModelRenderer(64, 64, 0, 0);
|
||||
this.chestLock.func_228301_a_(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.chestLock.rotationPointY = 8.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_225616_a_(T tileEntityIn, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_225616_5_, int p_225616_6_) {
|
||||
GenericIronChestTileEntity tileEntity = (GenericIronChestTileEntity) tileEntityIn;
|
||||
|
||||
World world = tileEntity.getWorld();
|
||||
boolean flag = world != null;
|
||||
|
||||
BlockState blockstate = flag ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().getDefaultState().with(GenericIronChestBlock.FACING, Direction.SOUTH);
|
||||
Block block = blockstate.getBlock();
|
||||
IronChestsTypes chestType = IronChestsTypes.IRON;
|
||||
IronChestsTypes actualType = GenericIronChestBlock.getTypeFromBlock(block);
|
||||
|
||||
if (actualType != null) {
|
||||
chestType = actualType;
|
||||
}
|
||||
|
||||
if (block instanceof GenericIronChestBlock) {
|
||||
GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block;
|
||||
|
||||
matrixStack.func_227860_a_();
|
||||
float f = blockstate.get(GenericIronChestBlock.FACING).getHorizontalAngle();
|
||||
matrixStack.func_227861_a_(0.5D, 0.5D, 0.5D);
|
||||
matrixStack.func_227863_a_(Vector3f.field_229181_d_.func_229187_a_(-f));
|
||||
matrixStack.func_227861_a_(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
TileEntityMerger.ICallbackWrapper<? extends GenericIronChestTileEntity> iCallbackWrapper;
|
||||
if (flag) {
|
||||
iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getPos(), true);
|
||||
}
|
||||
else {
|
||||
iCallbackWrapper = TileEntityMerger.ICallback::func_225537_b_;
|
||||
}
|
||||
|
||||
float f1 = iCallbackWrapper.apply(GenericIronChestBlock.getLid((IChestLid) tileEntity)).get(partialTicks);
|
||||
f1 = 1.0F - f1;
|
||||
f1 = 1.0F - f1 * f1 * f1;
|
||||
int i = iCallbackWrapper.apply(new DualBrightnessCallback<>()).applyAsInt(p_225616_5_);
|
||||
|
||||
Material material = IronChestsModels.chooseChestModel(tileEntity, chestType);
|
||||
IVertexBuilder ivertexbuilder = material.func_229311_a_(iRenderTypeBuffer, RenderType::func_228638_b_);
|
||||
|
||||
this.handleModelRender(matrixStack, ivertexbuilder, this.chestLid, this.chestLock, this.chestBottom, f1, i, p_225616_6_);
|
||||
|
||||
matrixStack.func_227865_b_();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleModelRender(MatrixStack matrixStack, IVertexBuilder iVertexBuilder, ModelRenderer firstModel, ModelRenderer secondModel, ModelRenderer thirdModel, float f1, int p_228871_7_, int p_228871_8_) {
|
||||
firstModel.rotateAngleX = -(f1 * ((float) Math.PI / 2F));
|
||||
secondModel.rotateAngleX = firstModel.rotateAngleX;
|
||||
firstModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
|
||||
secondModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
|
||||
thirdModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.progwml6.ironchest.client.tileentity;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.model.Material;
|
||||
import net.minecraft.client.renderer.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.profiler.EmptyProfiler;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IronChestsModels {
|
||||
|
||||
public static final ResourceLocation chestAtlas = new ResourceLocation("textures/atlas/chest.png");
|
||||
|
||||
protected static final Set<Material> LOCATIONS_BUILTIN_TEXTURES = Util.make(Sets.newHashSet(), (p_229337_0_) -> {
|
||||
addTextures(p_229337_0_::add);
|
||||
});
|
||||
|
||||
public IronChestsModels() {
|
||||
System.out.println("IronChestsModels");
|
||||
//ModelBakery.LOCATIONS_BUILTIN_TEXTURES.addAll(LOCATIONS_BUILTIN_TEXTURES);
|
||||
}
|
||||
|
||||
public static final Material IRON_CHEST_LOCATION = getChestMaterial("iron");
|
||||
public static final Material GOLD_CHEST_LOCATION = getChestMaterial("gold");
|
||||
public static final Material DIAMOND_CHEST_LOCATION = getChestMaterial("diamond");
|
||||
public static final Material COPPER_CHEST_LOCATION = getChestMaterial("copper");
|
||||
public static final Material SILVER_CHEST_LOCATION = getChestMaterial("silver");
|
||||
public static final Material CRYSTAL_CHEST_LOCATION = getChestMaterial("crystal");
|
||||
public static final Material OBSIDIAN_CHEST_LOCATION = getChestMaterial("obsidian");
|
||||
public static final Material DIRT_CHEST_LOCATION = getChestMaterial("dirt");
|
||||
|
||||
public static void addTextures(Consumer<Material> p_228775_0_) {
|
||||
p_228775_0_.accept(IRON_CHEST_LOCATION);
|
||||
p_228775_0_.accept(GOLD_CHEST_LOCATION);
|
||||
p_228775_0_.accept(DIAMOND_CHEST_LOCATION);
|
||||
p_228775_0_.accept(COPPER_CHEST_LOCATION);
|
||||
p_228775_0_.accept(SILVER_CHEST_LOCATION);
|
||||
p_228775_0_.accept(CRYSTAL_CHEST_LOCATION);
|
||||
p_228775_0_.accept(OBSIDIAN_CHEST_LOCATION);
|
||||
p_228775_0_.accept(DIRT_CHEST_LOCATION);
|
||||
}
|
||||
|
||||
private static Material getChestMaterial(String name) {
|
||||
return new Material(Atlases.field_228747_f_, new ResourceLocation(IronChests.MODID, "model/" + name + "_chest"));
|
||||
}
|
||||
|
||||
public static Material chooseChestModel(TileEntity tileEntity, IronChestsTypes type) {
|
||||
switch (type) {
|
||||
case IRON:
|
||||
return IRON_CHEST_LOCATION;
|
||||
case GOLD:
|
||||
return GOLD_CHEST_LOCATION;
|
||||
case DIAMOND:
|
||||
return DIAMOND_CHEST_LOCATION;
|
||||
case COPPER:
|
||||
return COPPER_CHEST_LOCATION;
|
||||
case SILVER:
|
||||
return SILVER_CHEST_LOCATION;
|
||||
case CRYSTAL:
|
||||
return CRYSTAL_CHEST_LOCATION;
|
||||
case OBSIDIAN:
|
||||
return OBSIDIAN_CHEST_LOCATION;
|
||||
case DIRTCHEST9000:
|
||||
return DIRT_CHEST_LOCATION;
|
||||
case WOOD:
|
||||
default:
|
||||
return Atlases.field_228758_q_;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.progwml6.ironchest.common;
|
||||
|
||||
public class IronChestsTags {
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ServerProxy
|
||||
{
|
||||
public void preInit()
|
||||
{
|
||||
}
|
||||
|
||||
public World getClientWorld()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.ai;
|
||||
|
||||
import net.minecraft.entity.ai.goal.CatSitOnBlockGoal;
|
||||
import net.minecraft.entity.ai.goal.PrioritizedGoal;
|
||||
import net.minecraft.entity.passive.CatEntity;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class CatsSitOnChestsHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt)
|
||||
{
|
||||
/*
|
||||
if (evt.getEntityLiving().ticksExisted < 5 && evt.getEntityLiving() instanceof CatEntity)
|
||||
{
|
||||
HashSet<PrioritizedGoal> goals = new HashSet<>();
|
||||
|
||||
CatEntity catEntity = (CatEntity) evt.getEntityLiving();
|
||||
|
||||
for (PrioritizedGoal goal : catEntity.goalSelector.goals)
|
||||
{
|
||||
if (goal.func_220772_j().getClass() == CatSitOnBlockGoal.class)
|
||||
{
|
||||
goals.add(goal);
|
||||
}
|
||||
}
|
||||
|
||||
for (PrioritizedGoal goal : goals)
|
||||
{
|
||||
catEntity.goalSelector.removeGoal(goal.func_220772_j());
|
||||
catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal1(catEntity, 0.4F));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.ai;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.ai.goal.CatSitOnBlockGoal;
|
||||
import net.minecraft.entity.passive.CatEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
|
||||
public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal
|
||||
{
|
||||
public IronChestCatSitOnBlockGoal(CatEntity catEntity, float speedIn)
|
||||
{
|
||||
super(catEntity, speedIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true to set given position as destination
|
||||
*/
|
||||
@Override
|
||||
protected boolean shouldMoveTo(IWorldReader worldIn, BlockPos pos)
|
||||
{
|
||||
if (!worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockState iBlockState = worldIn.getBlockState(pos);
|
||||
Block block = iBlockState.getBlock();
|
||||
|
||||
if (block instanceof ChestBlock)
|
||||
{
|
||||
return IronChestTileEntity.getPlayersUsing(worldIn, pos) < 1;
|
||||
}
|
||||
|
||||
return super.shouldMoveTo(worldIn, pos);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class CopperChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public CopperChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.COPPER, IronChestsTileEntityTypes.COPPER_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new CopperChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class CrystalChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public CrystalChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.CRYSTAL, IronChestsTileEntityTypes.CRYSTAL_CHEST::get, properties);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new CrystalChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class DiamondChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public DiamondChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.DIAMOND, IronChestsTileEntityTypes.DIAMOND_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new DiamondChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class DirtChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public DirtChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.DIRTCHEST9000, IronChestsTileEntityTypes.DIRT_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new DirtChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.HorizontalBlock;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.passive.CatEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.pathfinding.PathType;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityMerger;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GenericIronChestBlock extends Block implements IWaterLoggable {
|
||||
|
||||
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
|
||||
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
|
||||
protected static final VoxelShape IRON_CHEST_SHAPE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
|
||||
|
||||
private final IronChestsTypes type;
|
||||
private final Supplier<TileEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplier;
|
||||
|
||||
public GenericIronChestBlock(IronChestsTypes typeIn, Supplier<TileEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplierIn, Properties propertiesIn) {
|
||||
super(propertiesIn);
|
||||
|
||||
this.type = typeIn;
|
||||
this.tileEntityTypeSupplier = tileEntityTypeSupplierIn;
|
||||
|
||||
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(WATERLOGGED, Boolean.valueOf(false)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
|
||||
if (stateIn.get(WATERLOGGED)) {
|
||||
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
|
||||
}
|
||||
|
||||
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||
return IRON_CHEST_SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
||||
Direction direction = context.getPlacementHorizontalFacing().getOpposite();
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
|
||||
return this.getDefaultState().with(FACING, direction).with(WATERLOGGED, ifluidstate.getFluid() == Fluids.WATER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state) {
|
||||
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof GenericIronChestTileEntity) {
|
||||
((GenericIronChestTileEntity) tileentity).wasPlaced(placer, stack);
|
||||
|
||||
if (stack.hasDisplayName()) {
|
||||
((GenericIronChestTileEntity) tileentity).setCustomName(stack.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||
if (state.getBlock() != newState.getBlock()) {
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof GenericIronChestTileEntity) {
|
||||
((GenericIronChestTileEntity) tileentity).removeAdornments();
|
||||
InventoryHelper.dropInventoryItems(worldIn, pos, (GenericIronChestTileEntity) tileentity);
|
||||
worldIn.updateComparatorOutputLevel(pos, this);
|
||||
}
|
||||
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType func_225533_a_(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
|
||||
if (!worldIn.isRemote) {
|
||||
INamedContainerProvider inamedcontainerprovider = this.getContainer(state, worldIn, pos);
|
||||
if (inamedcontainerprovider != null) {
|
||||
player.openContainer(inamedcontainerprovider);
|
||||
player.addStat(this.getOpenStat());
|
||||
}
|
||||
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
protected Stat<ResourceLocation> getOpenStat() {
|
||||
return Stats.CUSTOM.get(Stats.OPEN_CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) {
|
||||
TileEntity tileentity = world.getTileEntity(pos);
|
||||
return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider) tileentity : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eventReceived(BlockState state, World worldIn, BlockPos pos, int id, int param) {
|
||||
super.eventReceived(state, worldIn, pos, id, param);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
|
||||
}
|
||||
|
||||
private static boolean isBlocked(IWorld iWorld, BlockPos blockPos) {
|
||||
return isBelowSolidBlock(iWorld, blockPos) || isCatSittingOn(iWorld, blockPos);
|
||||
}
|
||||
|
||||
private static boolean isBelowSolidBlock(IBlockReader iBlockReader, BlockPos worldIn) {
|
||||
BlockPos blockpos = worldIn.up();
|
||||
return iBlockReader.getBlockState(blockpos).isNormalCube(iBlockReader, blockpos);
|
||||
}
|
||||
|
||||
private static boolean isCatSittingOn(IWorld iWorld, BlockPos blockPos) {
|
||||
List<CatEntity> list = iWorld.getEntitiesWithinAABB(CatEntity.class, new AxisAlignedBB((double) blockPos.getX(), (double) (blockPos.getY() + 1), (double) blockPos.getZ(), (double) (blockPos.getX() + 1), (double) (blockPos.getY() + 2), (double) (blockPos.getZ() + 1)));
|
||||
if (!list.isEmpty()) {
|
||||
for (CatEntity catentity : list) {
|
||||
if (catentity.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
|
||||
return Container.calcRedstoneFromInventory((IInventory) worldIn.getTileEntity(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rot) {
|
||||
return state.with(FACING, rot.rotate(state.get(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirrorIn) {
|
||||
return state.rotate(mirrorIn.toRotation(state.get(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IronChestsTypes getTypeFromItem(Item itemIn) {
|
||||
return getTypeFromBlock(Block.getBlockFromItem(itemIn));
|
||||
}
|
||||
|
||||
public static IronChestsTypes getTypeFromBlock(Block blockIn) {
|
||||
return blockIn instanceof GenericIronChestBlock ? ((GenericIronChestBlock) blockIn).getType() : null;
|
||||
}
|
||||
|
||||
public IronChestsTypes getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static TileEntityMerger.ICallback<GenericIronChestTileEntity, Float2FloatFunction> getLid(final IChestLid p_226917_0_) {
|
||||
return new TileEntityMerger.ICallback<GenericIronChestTileEntity, Float2FloatFunction>() {
|
||||
@Override
|
||||
public Float2FloatFunction func_225539_a_(GenericIronChestTileEntity p_225539_1_, GenericIronChestTileEntity p_225539_2_) {
|
||||
return (p_226921_2_) -> {
|
||||
return Math.max(p_225539_1_.getLidAngle(p_226921_2_), p_225539_2_.getLidAngle(p_226921_2_));
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float2FloatFunction func_225538_a_(GenericIronChestTileEntity p_225538_1_) {
|
||||
return p_225538_1_::getLidAngle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float2FloatFunction func_225537_b_() {
|
||||
return p_226917_0_::getLidAngle;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TileEntityMerger.ICallbackWrapper<? extends GenericIronChestTileEntity> getWrapper(BlockState blockState, World world, BlockPos blockPos, boolean p_225536_4_) {
|
||||
BiPredicate<IWorld, BlockPos> biPredicate;
|
||||
if (p_225536_4_) {
|
||||
biPredicate = (p_226918_0_, p_226918_1_) -> false;
|
||||
}
|
||||
else {
|
||||
biPredicate = GenericIronChestBlock::isBlocked;
|
||||
}
|
||||
|
||||
return TileEntityMerger.func_226924_a_(this.tileEntityTypeSupplier.get(), GenericIronChestBlock::getMergerType, GenericIronChestBlock::getDirectionToAttached, FACING, blockState, world, blockPos, biPredicate);
|
||||
}
|
||||
|
||||
public static TileEntityMerger.Type getMergerType(BlockState blockState) {
|
||||
return TileEntityMerger.Type.SINGLE;
|
||||
}
|
||||
|
||||
public static Direction getDirectionToAttached(BlockState state) {
|
||||
Direction direction = state.get(FACING);
|
||||
return direction.rotateYCCW();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class GoldChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public GoldChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.GOLD, IronChestsTileEntityTypes.GOLD_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new GoldChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class IronChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public IronChestBlock(Block.Properties properties) {
|
||||
super(IronChestsTypes.IRON, IronChestsTileEntityTypes.IRON_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new IronChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import com.progwml6.ironchest.client.tileentity.IronChestItemStackRenderer;
|
||||
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
|
||||
import com.progwml6.ironchest.common.item.IronChestsItems;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class IronChestsBlocks {
|
||||
|
||||
public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, IronChests.MODID);
|
||||
public static final DeferredRegister<Item> ITEMS = IronChestsItems.ITEMS;
|
||||
|
||||
public static final RegistryObject<IronChestBlock> IRON_CHEST = register(
|
||||
"iron_chest", () -> new IronChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> ironChestRenderer());
|
||||
|
||||
public static final RegistryObject<GoldChestBlock> GOLD_CHEST = register(
|
||||
"gold_chest", () -> new GoldChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> goldChestRenderer());
|
||||
|
||||
public static final RegistryObject<DiamondChestBlock> DIAMOND_CHEST = register(
|
||||
"diamond_chest", () -> new DiamondChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> diamondChestRenderer());
|
||||
|
||||
public static final RegistryObject<CopperChestBlock> COPPER_CHEST = register(
|
||||
"copper_chest", () -> new CopperChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> copperChestRenderer());
|
||||
|
||||
public static final RegistryObject<SilverChestBlock> SILVER_CHEST = register(
|
||||
"silver_chest", () -> new SilverChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> silverChestRenderer());
|
||||
|
||||
public static final RegistryObject<CrystalChestBlock> CRYSTAL_CHEST = register(
|
||||
"crystal_chest", () -> new CrystalChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> crystalChestRenderer());
|
||||
|
||||
public static final RegistryObject<ObsidianChestBlock> OBSIDIAN_CHEST = register(
|
||||
"obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 10000.0F)),
|
||||
() -> obsidianChestRenderer());
|
||||
|
||||
public static final RegistryObject<DirtChestBlock> DIRT_CHEST = register(
|
||||
"dirt_chest", () -> new DirtChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)),
|
||||
() -> dirtChestRenderer());
|
||||
|
||||
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) {
|
||||
return register(name, sup, block -> item(block, renderMethod));
|
||||
}
|
||||
|
||||
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Function<RegistryObject<T>, Supplier<? extends Item>> itemCreator) {
|
||||
RegistryObject<T> ret = registerNoItem(name, sup);
|
||||
ITEMS.register(name, itemCreator.apply(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static <T extends Block> RegistryObject<T> registerNoItem(String name, Supplier<? extends T> sup) {
|
||||
return BLOCKS.register(name, sup);
|
||||
}
|
||||
|
||||
private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, final Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) {
|
||||
return () -> new BlockItem(block.get(), new Item.Properties().group(IronChests.IRONCHESTS_ITEM_GROUP).setTEISR(renderMethod));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> ironChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new IronChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> goldChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new GoldChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> diamondChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new DiamondChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> copperChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new CopperChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> silverChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new SilverChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> crystalChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new CrystalChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> obsidianChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new ObsidianChestTileEntity());
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static Callable<ItemStackTileEntityRenderer> dirtChestRenderer() {
|
||||
return () -> new IronChestItemStackRenderer(() -> new DirtChestTileEntity());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum IronChestsTypes implements IStringSerializable {
|
||||
|
||||
IRON(54, 9, IronChestTileEntity.class, 184, 222, new ResourceLocation("ironchest", "textures/gui/iron_container.png"), 256, 256),
|
||||
GOLD(81, 9, GoldChestTileEntity.class, 184, 276, new ResourceLocation("ironchest", "textures/gui/gold_container.png"), 256, 276),
|
||||
DIAMOND(108, 12, DiamondChestTileEntity.class, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
COPPER(45, 9, CopperChestTileEntity.class, 184, 204, new ResourceLocation("ironchest", "textures/gui/copper_container.png"), 256, 256),
|
||||
SILVER(72, 9, SilverChestTileEntity.class, 184, 258, new ResourceLocation("ironchest", "textures/gui/silver_container.png"), 256, 276),
|
||||
CRYSTAL(108, 12, CrystalChestTileEntity.class, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
OBSIDIAN(108, 12, ObsidianChestTileEntity.class, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
DIRTCHEST9000(1, 1, DirtChestTileEntity.class, 184, 184, new ResourceLocation("ironchest", "textures/gui/dirt_container.png"), 256, 256),
|
||||
WOOD(0, 0, null, 0, 0, null, 0, 0);
|
||||
|
||||
private final String name;
|
||||
public final int size;
|
||||
public final int rowLength;
|
||||
public final Class<? extends TileEntity> clazz;
|
||||
public final int xSize;
|
||||
public final int ySize;
|
||||
public final ResourceLocation guiTexture;
|
||||
public final int textureXSize;
|
||||
public final int textureYSize;
|
||||
|
||||
IronChestsTypes(int size, int rowLength, Class<? extends GenericIronChestTileEntity> clazz, int xSize, int ySize, ResourceLocation guiTexture, int textureXSize, int textureYSize) {
|
||||
this(null, size, rowLength, clazz, xSize, ySize, guiTexture, textureXSize, textureYSize);
|
||||
}
|
||||
|
||||
IronChestsTypes(@Nullable String name, int size, int rowLength, Class<? extends GenericIronChestTileEntity> clazz, int xSize, int ySize, ResourceLocation guiTexture, int textureXSize, int textureYSize) {
|
||||
this.name = name == null ? toEnglishName(this.name()) : name;
|
||||
this.size = size;
|
||||
this.rowLength = rowLength;
|
||||
this.clazz = clazz;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.guiTexture = guiTexture;
|
||||
this.textureXSize = textureXSize;
|
||||
this.textureYSize = textureYSize;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public String getEnglishName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public static final String toEnglishName(String internalName) {
|
||||
return Arrays.stream(internalName.toLowerCase(Locale.ROOT).split("_"))
|
||||
.map(StringUtils::capitalize)
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getEnglishName();
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.size / this.rowLength;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this == CRYSTAL;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class ObsidianChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public ObsidianChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.OBSIDIAN, IronChestsTileEntityTypes.OBSIDIAN_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new ObsidianChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.progwml6.ironchest.common.block;
|
||||
|
||||
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
|
||||
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class SilverChestBlock extends GenericIronChestBlock {
|
||||
|
||||
public SilverChestBlock(Properties properties) {
|
||||
super(IronChestsTypes.SILVER, IronChestsTileEntityTypes.SILVER_CHEST::get, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
||||
return new SilverChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class CopperChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public CopperChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.COPPER_CHEST.get(), IronChestsTypes.COPPER, IronChestsBlocks.COPPER_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createCopperContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,186 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class CrystalChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
private NonNullList<ItemStack> topStacks;
|
||||
|
||||
private boolean inventoryTouched;
|
||||
|
||||
private boolean hadStuff;
|
||||
|
||||
public CrystalChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.CRYSTAL_CHEST.get(), IronChestsTypes.CRYSTAL, IronChestsBlocks.CRYSTAL_CHEST::get);
|
||||
this.topStacks = NonNullList.<ItemStack>withSize(8, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createCrystalContainer(id, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (!this.world.isRemote && this.inventoryTouched) {
|
||||
this.inventoryTouched = false;
|
||||
|
||||
this.sortTopStacks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(NonNullList<ItemStack> contents) {
|
||||
super.setItems(contents);
|
||||
|
||||
this.inventoryTouched = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
this.inventoryTouched = true;
|
||||
|
||||
return super.getStackInSlot(index);
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getTopItems() {
|
||||
return this.topStacks;
|
||||
}
|
||||
|
||||
private void sortTopStacks() {
|
||||
if (!this.getChestType().isTransparent() || (this.world != null && this.world.isRemote)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
boolean hasStuff = false;
|
||||
|
||||
int compressedIdx = 0;
|
||||
|
||||
mainLoop:
|
||||
for (int i = 0; i < this.getSizeInventory(); i++) {
|
||||
ItemStack itemStack = this.getItems().get(i);
|
||||
|
||||
if (!itemStack.isEmpty()) {
|
||||
for (int j = 0; j < compressedIdx; j++) {
|
||||
ItemStack tempCopyStack = tempCopy.get(j);
|
||||
|
||||
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack)) {
|
||||
if (itemStack.getCount() != tempCopyStack.getCount()) {
|
||||
tempCopyStack.grow(itemStack.getCount());
|
||||
}
|
||||
|
||||
continue mainLoop;
|
||||
}
|
||||
}
|
||||
|
||||
tempCopy.set(compressedIdx, itemStack.copy());
|
||||
|
||||
compressedIdx++;
|
||||
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStuff && this.hadStuff) {
|
||||
this.hadStuff = false;
|
||||
|
||||
for (int i = 0; i < this.getTopItems().size(); i++) {
|
||||
this.getTopItems().set(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (this.world != null) {
|
||||
BlockState iblockstate = this.world.getBlockState(this.pos);
|
||||
|
||||
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.hadStuff = true;
|
||||
|
||||
Collections.sort(tempCopy, (stack1, stack2) -> {
|
||||
if (stack1.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
else if (stack2.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return stack2.getCount() - stack1.getCount();
|
||||
}
|
||||
});
|
||||
|
||||
int p = 0;
|
||||
|
||||
for (ItemStack element : tempCopy) {
|
||||
if (!element.isEmpty() && element.getCount() > 0) {
|
||||
if (p == this.getTopItems().size()) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.getTopItems().set(p, element);
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = p; i < this.getTopItems().size(); i++) {
|
||||
this.getTopItems().set(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (this.world != null) {
|
||||
BlockState iblockstate = this.world.getBlockState(this.pos);
|
||||
|
||||
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
|
||||
}
|
||||
|
||||
sendTopStacksPacket();
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> buildItemStackDataList() {
|
||||
if (this.getChestType().isTransparent()) {
|
||||
NonNullList<ItemStack> sortList = NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
|
||||
|
||||
int pos = 0;
|
||||
|
||||
for (ItemStack is : this.topStacks) {
|
||||
if (!is.isEmpty()) {
|
||||
sortList.set(pos, is);
|
||||
}
|
||||
else {
|
||||
sortList.set(pos, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
return sortList;
|
||||
}
|
||||
|
||||
return NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
protected void sendTopStacksPacket() {
|
||||
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
|
||||
|
||||
//PacketHandler.send(PacketDistributor.TRACKING_CHUNK.with(() -> (Chunk) this.getWorld().getChunk(this.getPos())), new PacketTopStackSyncChest(this.getWorld().getDimension().getType().getId(), this.getPos(), stacks));
|
||||
}
|
||||
|
||||
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks) {
|
||||
this.topStacks = topStacks;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class DiamondChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public DiamondChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.DIAMOND_CHEST.get(), IronChestsTypes.DIAMOND, IronChestsBlocks.DIAMOND_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createDiamondContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.StringNBT;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public class DirtChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.WRITTEN_BOOK);
|
||||
|
||||
private static boolean bookDataCreated = false;
|
||||
|
||||
public DirtChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.DIRT_CHEST.get(), IronChestsTypes.DIRTCHEST9000, IronChestsBlocks.DIRT_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createDirtContainer(id, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wasPlaced(LivingEntity entityLivingBase, ItemStack itemStack) {
|
||||
if (!(itemStack.hasTag() && itemStack.getTag().getBoolean("been_placed"))) {
|
||||
this.setInventorySlotContents(0, dirtChest9000GuideBook.copy());
|
||||
}
|
||||
|
||||
if (!bookDataCreated) {
|
||||
createBookData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAdornments() {
|
||||
if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).isItemEqual(dirtChest9000GuideBook)) {
|
||||
this.getItems().set(0, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createBookData() {
|
||||
dirtChest9000GuideBook.setTagInfo("author", StringNBT.func_229705_a_("cpw"));
|
||||
|
||||
dirtChest9000GuideBook.setTagInfo("title", StringNBT.func_229705_a_(I18n.format("book.ironchest.dirtchest9000.title")));
|
||||
|
||||
ListNBT pages = new ListNBT();
|
||||
pages.add(StringNBT.func_229705_a_(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page1"))));
|
||||
pages.add(StringNBT.func_229705_a_(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page2"))));
|
||||
pages.add(StringNBT.func_229705_a_(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page3"))));
|
||||
pages.add(StringNBT.func_229705_a_(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page4"))));
|
||||
pages.add(StringNBT.func_229705_a_(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page5"))));
|
||||
|
||||
dirtChest9000GuideBook.setTagInfo("pages", pages);
|
||||
|
||||
bookDataCreated = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.LockableLootTileEntity;
|
||||
import net.minecraft.tileentity.LockableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@OnlyIn(value = Dist.CLIENT, _interface = IChestLid.class)
|
||||
public class GenericIronChestTileEntity extends LockableLootTileEntity implements IChestLid, ITickableTileEntity {
|
||||
|
||||
private NonNullList<ItemStack> chestContents;
|
||||
protected float lidAngle;
|
||||
protected float prevLidAngle;
|
||||
protected int numPlayersUsing;
|
||||
private int ticksSinceSync;
|
||||
private IronChestsTypes chestType;
|
||||
private Supplier<Block> blockToUse;
|
||||
|
||||
protected GenericIronChestTileEntity(TileEntityType<?> typeIn, IronChestsTypes chestTypeIn, Supplier<Block> blockToUseIn) {
|
||||
super(typeIn);
|
||||
|
||||
this.chestContents = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY);
|
||||
this.chestType = chestTypeIn;
|
||||
this.blockToUse = blockToUseIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return this.getItems().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
for (ItemStack itemstack : this.chestContents) {
|
||||
if (!itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ITextComponent getDefaultName() {
|
||||
return new TranslationTextComponent("container.chest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(CompoundNBT compound) {
|
||||
super.read(compound);
|
||||
|
||||
this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
if (!this.checkLootAndRead(compound)) {
|
||||
ItemStackHelper.loadAllItems(compound, this.chestContents);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT write(CompoundNBT compound) {
|
||||
super.write(compound);
|
||||
|
||||
if (!this.checkLootAndWrite(compound)) {
|
||||
ItemStackHelper.saveAllItems(compound, this.chestContents);
|
||||
}
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
int i = this.pos.getX();
|
||||
int j = this.pos.getY();
|
||||
int k = this.pos.getZ();
|
||||
++this.ticksSinceSync;
|
||||
this.numPlayersUsing = getNumberOfPlayersUsing(this.world, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing);
|
||||
this.prevLidAngle = this.lidAngle;
|
||||
float f = 0.1F;
|
||||
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) {
|
||||
this.playSound(SoundEvents.BLOCK_CHEST_OPEN);
|
||||
}
|
||||
|
||||
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
|
||||
float f1 = this.lidAngle;
|
||||
if (this.numPlayersUsing > 0) {
|
||||
this.lidAngle += 0.1F;
|
||||
}
|
||||
else {
|
||||
this.lidAngle -= 0.1F;
|
||||
}
|
||||
|
||||
if (this.lidAngle > 1.0F) {
|
||||
this.lidAngle = 1.0F;
|
||||
}
|
||||
|
||||
float f2 = 0.5F;
|
||||
if (this.lidAngle < 0.5F && f1 >= 0.5F) {
|
||||
this.playSound(SoundEvents.BLOCK_CHEST_CLOSE);
|
||||
}
|
||||
|
||||
if (this.lidAngle < 0.0F) {
|
||||
this.lidAngle = 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getNumberOfPlayersUsing(World worldIn, LockableTileEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing) {
|
||||
if (!worldIn.isRemote && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) {
|
||||
numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z);
|
||||
}
|
||||
|
||||
return numPlayersUsing;
|
||||
}
|
||||
|
||||
public static int getNumberOfPlayersUsing(World world, LockableTileEntity lockableTileEntity, int x, int y, int z) {
|
||||
int i = 0;
|
||||
|
||||
for (PlayerEntity playerentity : world.getEntitiesWithinAABB(PlayerEntity.class, new AxisAlignedBB((double) ((float) x - 5.0F), (double) ((float) y - 5.0F), (double) ((float) z - 5.0F), (double) ((float) (x + 1) + 5.0F), (double) ((float) (y + 1) + 5.0F), (double) ((float) (z + 1) + 5.0F)))) {
|
||||
if (playerentity.openContainer instanceof IronChestContainer) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private void playSound(SoundEvent soundIn) {
|
||||
double d0 = (double) this.pos.getX() + 0.5D;
|
||||
double d1 = (double) this.pos.getY() + 0.5D;
|
||||
double d2 = (double) this.pos.getZ() + 0.5D;
|
||||
|
||||
this.world.playSound((PlayerEntity) null, d0, d1, d2, soundIn, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receiveClientEvent(int id, int type) {
|
||||
if (id == 1) {
|
||||
this.numPlayersUsing = type;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return super.receiveClientEvent(id, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player) {
|
||||
if (!player.isSpectator()) {
|
||||
if (this.numPlayersUsing < 0) {
|
||||
this.numPlayersUsing = 0;
|
||||
}
|
||||
|
||||
++this.numPlayersUsing;
|
||||
this.onOpenOrClose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player) {
|
||||
if (!player.isSpectator()) {
|
||||
--this.numPlayersUsing;
|
||||
this.onOpenOrClose();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onOpenOrClose() {
|
||||
Block block = this.getBlockState().getBlock();
|
||||
|
||||
if (block instanceof GenericIronChestBlock) {
|
||||
this.world.addBlockEvent(this.pos, block, 1, this.numPlayersUsing);
|
||||
this.world.notifyNeighborsOfStateChange(this.pos, block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getItems() {
|
||||
return this.chestContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(NonNullList<ItemStack> itemsIn) {
|
||||
this.chestContents = NonNullList.<ItemStack>withSize(this.getChestType().size, ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < itemsIn.size(); i++) {
|
||||
if (i < this.chestContents.size()) {
|
||||
this.getItems().set(i, itemsIn.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public float getLidAngle(float partialTicks) {
|
||||
return MathHelper.lerp(partialTicks, this.prevLidAngle, this.lidAngle);
|
||||
}
|
||||
|
||||
public static int getPlayersUsing(IBlockReader reader, BlockPos posIn) {
|
||||
BlockState blockstate = reader.getBlockState(posIn);
|
||||
if (blockstate.hasTileEntity()) {
|
||||
TileEntity tileentity = reader.getTileEntity(posIn);
|
||||
if (tileentity instanceof GenericIronChestTileEntity) {
|
||||
return ((GenericIronChestTileEntity) tileentity).numPlayersUsing;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int windowId, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createIronContainer(windowId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void wasPlaced(LivingEntity livingEntity, ItemStack stack) {
|
||||
}
|
||||
|
||||
public void removeAdornments() {
|
||||
}
|
||||
|
||||
public IronChestsTypes getChestType() {
|
||||
IronChestsTypes type = IronChestsTypes.IRON;
|
||||
|
||||
if (this.hasWorld()) {
|
||||
IronChestsTypes typeNew = GenericIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock());
|
||||
|
||||
if (typeNew != null) {
|
||||
type = typeNew;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public Block getBlockToUse() {
|
||||
return this.blockToUse.get();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class GoldChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public GoldChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestsTypes.GOLD, IronChestsBlocks.GOLD_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createGoldContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
|
||||
public class IronChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public IronChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestsTypes.IRON, IronChestsBlocks.IRON_CHEST::get);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class IronChestsTileEntityTypes {
|
||||
|
||||
public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = new DeferredRegister<>(ForgeRegistries.TILE_ENTITIES, IronChests.MODID);
|
||||
|
||||
public static final RegistryObject<TileEntityType<IronChestTileEntity>> IRON_CHEST = TILE_ENTITIES.register(
|
||||
"iron_chest", () -> new TileEntityType<>(IronChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.IRON_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<GoldChestTileEntity>> GOLD_CHEST = TILE_ENTITIES.register(
|
||||
"gold_chest", () -> new TileEntityType<>(GoldChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.GOLD_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<DiamondChestTileEntity>> DIAMOND_CHEST = TILE_ENTITIES.register(
|
||||
"diamond_chest", () -> new TileEntityType<>(DiamondChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIAMOND_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<CopperChestTileEntity>> COPPER_CHEST = TILE_ENTITIES.register(
|
||||
"copper_chest", () -> new TileEntityType<>(CopperChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.COPPER_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<SilverChestTileEntity>> SILVER_CHEST = TILE_ENTITIES.register(
|
||||
"silver_chest", () -> new TileEntityType<>(SilverChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.SILVER_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<CrystalChestTileEntity>> CRYSTAL_CHEST = TILE_ENTITIES.register(
|
||||
"crystal_chest", () -> new TileEntityType<>(CrystalChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.CRYSTAL_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<ObsidianChestTileEntity>> OBSIDIAN_CHEST = TILE_ENTITIES.register(
|
||||
"obsidian_chest", () -> new TileEntityType<>(ObsidianChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.OBSIDIAN_CHEST.get()), null));
|
||||
|
||||
public static final RegistryObject<TileEntityType<DirtChestTileEntity>> DIRT_CHEST = TILE_ENTITIES.register(
|
||||
"dirt_chest", () -> new TileEntityType<>(DirtChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIRT_CHEST.get()), null));
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class ObsidianChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public ObsidianChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.OBSIDIAN_CHEST.get(), IronChestsTypes.OBSIDIAN, IronChestsBlocks.OBSIDIAN_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createObsidianContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.progwml6.ironchest.common.block.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsBlocks;
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import com.progwml6.ironchest.common.inventory.IronChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class SilverChestTileEntity extends GenericIronChestTileEntity {
|
||||
|
||||
public SilverChestTileEntity() {
|
||||
super(IronChestsTileEntityTypes.SILVER_CHEST.get(), IronChestsTypes.SILVER, IronChestsBlocks.SILVER_CHEST::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory) {
|
||||
return IronChestContainer.createSilverContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,282 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.HorizontalBlock;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.passive.CatEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.pathfinding.PathType;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ChestBlock extends Block implements IWaterLoggable
|
||||
{
|
||||
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
|
||||
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
|
||||
protected static final VoxelShape IRON_CHEST_SHAPE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
|
||||
|
||||
private final ChestType type;
|
||||
|
||||
public ChestBlock(Properties properties, ChestType type)
|
||||
{
|
||||
super(properties);
|
||||
|
||||
this.type = type;
|
||||
|
||||
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(WATERLOGGED, Boolean.valueOf(false)));
|
||||
this.setRegistryName(new ResourceLocation(type.itemName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public boolean hasCustomBreakingProgress(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state)
|
||||
{
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
|
||||
{
|
||||
if (stateIn.get(WATERLOGGED))
|
||||
{
|
||||
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
|
||||
}
|
||||
|
||||
return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader iBlockReader, BlockPos pos, ISelectionContext selectionContext)
|
||||
{
|
||||
return IRON_CHEST_SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context)
|
||||
{
|
||||
Direction direction = context.getPlacementHorizontalFacing().getOpposite();
|
||||
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
|
||||
|
||||
return this.getDefaultState().with(FACING, direction).with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidState getFluidState(BlockState state)
|
||||
{
|
||||
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack)
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof IronChestTileEntity)
|
||||
{
|
||||
((IronChestTileEntity) tileentity).wasPlaced(placer, stack);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
((IronChestTileEntity) tileentity).setCustomName(stack.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving)
|
||||
{
|
||||
if (state.getBlock() != newState.getBlock())
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof IronChestTileEntity)
|
||||
{
|
||||
((IronChestTileEntity) tileentity).removeAdornments();
|
||||
InventoryHelper.dropInventoryItems(worldIn, pos, (IronChestTileEntity) tileentity);
|
||||
worldIn.updateComparatorOutputLevel(pos, this);
|
||||
}
|
||||
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit)
|
||||
{
|
||||
if (worldIn.isRemote)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
INamedContainerProvider inamedcontainerprovider = this.getContainer(state, worldIn, pos);
|
||||
if (inamedcontainerprovider != null)
|
||||
{
|
||||
player.openContainer(inamedcontainerprovider);
|
||||
player.addStat(this.getOpenStat());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Stat<ResourceLocation> getOpenStat()
|
||||
{
|
||||
return Stats.CUSTOM.get(Stats.OPEN_CHEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos)
|
||||
{
|
||||
TileEntity tileentity = world.getTileEntity(pos);
|
||||
return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider) tileentity : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eventReceived(BlockState state, World worldIn, BlockPos pos, int id, int param)
|
||||
{
|
||||
super.eventReceived(state, worldIn, pos, id, param);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
|
||||
}
|
||||
|
||||
private static boolean isBlocked(IWorld iWorld, BlockPos blockPos)
|
||||
{
|
||||
return isBelowSolidBlock(iWorld, blockPos) || isCatSittingOn(iWorld, blockPos);
|
||||
}
|
||||
|
||||
private static boolean isBelowSolidBlock(IBlockReader iBlockReader, BlockPos worldIn)
|
||||
{
|
||||
BlockPos blockpos = worldIn.up();
|
||||
return iBlockReader.getBlockState(blockpos).isNormalCube(iBlockReader, blockpos);
|
||||
}
|
||||
|
||||
private static boolean isCatSittingOn(IWorld iWorld, BlockPos blockPos)
|
||||
{
|
||||
List<CatEntity> list = iWorld.getEntitiesWithinAABB(CatEntity.class, new AxisAlignedBB((double) blockPos.getX(), (double) (blockPos.getY() + 1), (double) blockPos.getZ(), (double) (blockPos.getX() + 1), (double) (blockPos.getY() + 2), (double) (blockPos.getZ() + 1)));
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
for (CatEntity catentity : list)
|
||||
{
|
||||
if (catentity.isSitting())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos)
|
||||
{
|
||||
return Container.calcRedstoneFromInventory((IInventory) worldIn.getTileEntity(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rot)
|
||||
{
|
||||
return state.with(FACING, rot.rotate(state.get(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirrorIn)
|
||||
{
|
||||
return state.rotate(mirrorIn.toRotation(state.get(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
|
||||
{
|
||||
builder.add(FACING, WATERLOGGED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ChestType getTypeFromItem(Item itemIn)
|
||||
{
|
||||
return getTypeFromBlock(Block.getBlockFromItem(itemIn));
|
||||
}
|
||||
|
||||
public static ChestType getTypeFromBlock(Block blockIn)
|
||||
{
|
||||
return blockIn instanceof ChestBlock ? ((ChestBlock) blockIn).getType() : null;
|
||||
}
|
||||
|
||||
public ChestType getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.tileentity.CopperChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.CrystalChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.DiamondChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.DirtChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.GoldChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.ObsidianChestTileEntity;
|
||||
import com.progwml6.ironchest.common.tileentity.SilverChestTileEntity;
|
||||
import com.progwml6.ironchest.common.util.BlockNames;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public enum ChestType implements IStringSerializable
|
||||
{
|
||||
IRON(54, 9, "iron_chest.png", IronChestTileEntity.class, BlockNames.IRON_CHEST, 184, 222, new ResourceLocation("ironchest", "textures/gui/iron_container.png"), 256, 256),
|
||||
GOLD(81, 9, "gold_chest.png", GoldChestTileEntity.class, BlockNames.GOLD_CHEST, 184, 276, new ResourceLocation("ironchest", "textures/gui/gold_container.png"), 256, 276),
|
||||
DIAMOND(108, 12, "diamond_chest.png", DiamondChestTileEntity.class, BlockNames.DIAMOND_CHEST, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
COPPER(45, 9, "copper_chest.png", CopperChestTileEntity.class, BlockNames.COPPER_CHEST, 184, 204, new ResourceLocation("ironchest", "textures/gui/copper_container.png"), 256, 256),
|
||||
SILVER(72, 9, "silver_chest.png", SilverChestTileEntity.class, BlockNames.SILVER_CHEST, 184, 258, new ResourceLocation("ironchest", "textures/gui/silver_container.png"), 256, 276),
|
||||
CRYSTAL(108, 12, "crystal_chest.png", CrystalChestTileEntity.class, BlockNames.CRYSTAL_CHEST, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
OBSIDIAN(108, 12, "obsidian_chest.png", ObsidianChestTileEntity.class, BlockNames.OBSIDIAN_CHEST, 238, 276, new ResourceLocation("ironchest", "textures/gui/diamond_container.png"), 256, 276),
|
||||
DIRTCHEST9000(1, 1, "dirt_chest.png", DirtChestTileEntity.class, BlockNames.DIRT_CHEST, 184, 184, new ResourceLocation("ironchest", "textures/gui/dirt_container.png"), 256, 256),
|
||||
WOOD(0, 0, "", null, null, 0, 0, null, 0, 0);
|
||||
|
||||
public static final ChestType VALUES[] = values();
|
||||
|
||||
public final String name;
|
||||
|
||||
public final int size;
|
||||
|
||||
public final int rowLength;
|
||||
|
||||
public final String modelTexture;
|
||||
|
||||
public final Class<? extends TileEntity> clazz;
|
||||
|
||||
public final String itemName;
|
||||
|
||||
public final int xSize;
|
||||
|
||||
public final int ySize;
|
||||
|
||||
public final ResourceLocation guiTexture;
|
||||
|
||||
public final int textureXSize;
|
||||
|
||||
public final int textureYSize;
|
||||
|
||||
ChestType(int size, int rowLength, String modelTexture, Class<? extends IronChestTileEntity> clazz, String itemName, int xSize, int ySize, ResourceLocation guiTexture, int textureXSize, int textureYSize)
|
||||
{
|
||||
this.name = this.name().toLowerCase();
|
||||
this.size = size;
|
||||
this.rowLength = rowLength;
|
||||
this.modelTexture = modelTexture;
|
||||
this.clazz = clazz;
|
||||
this.itemName = itemName;
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
this.guiTexture = guiTexture;
|
||||
this.textureXSize = textureXSize;
|
||||
this.textureYSize = textureYSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getRowCount()
|
||||
{
|
||||
return this.size / this.rowLength;
|
||||
}
|
||||
|
||||
public boolean isTransparent()
|
||||
{
|
||||
return this == CRYSTAL;
|
||||
}
|
||||
|
||||
public static ChestType get(ResourceLocation resourceLocation)
|
||||
{
|
||||
switch (resourceLocation.toString())
|
||||
{
|
||||
case BlockNames.IRON_CHEST:
|
||||
return IRON;
|
||||
case BlockNames.GOLD_CHEST:
|
||||
return GOLD;
|
||||
case BlockNames.DIAMOND_CHEST:
|
||||
return DIAMOND;
|
||||
case BlockNames.COPPER_CHEST:
|
||||
return COPPER;
|
||||
case BlockNames.SILVER_CHEST:
|
||||
return SILVER;
|
||||
case BlockNames.CRYSTAL_CHEST:
|
||||
return CRYSTAL;
|
||||
case BlockNames.OBSIDIAN_CHEST:
|
||||
return OBSIDIAN;
|
||||
case BlockNames.DIRT_CHEST:
|
||||
return DIRTCHEST9000;
|
||||
default:
|
||||
return WOOD;
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockState get(ChestType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case IRON:
|
||||
return IronChestBlocks.ironChestBlock.getDefaultState();
|
||||
case GOLD:
|
||||
return IronChestBlocks.goldChestBlock.getDefaultState();
|
||||
case DIAMOND:
|
||||
return IronChestBlocks.diamondChestBlock.getDefaultState();
|
||||
case COPPER:
|
||||
return IronChestBlocks.copperChestBlock.getDefaultState();
|
||||
case SILVER:
|
||||
return IronChestBlocks.silverChestBlock.getDefaultState();
|
||||
case CRYSTAL:
|
||||
return IronChestBlocks.crystalChestBlock.getDefaultState();
|
||||
case OBSIDIAN:
|
||||
return IronChestBlocks.obsidianChestBlock.getDefaultState();
|
||||
case DIRTCHEST9000:
|
||||
return IronChestBlocks.dirtChestBlock.getDefaultState();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IronChestTileEntity makeEntity()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case IRON:
|
||||
return new IronChestTileEntity();
|
||||
case GOLD:
|
||||
return new GoldChestTileEntity();
|
||||
case DIAMOND:
|
||||
return new DiamondChestTileEntity();
|
||||
case COPPER:
|
||||
return new CopperChestTileEntity();
|
||||
case SILVER:
|
||||
return new SilverChestTileEntity();
|
||||
case CRYSTAL:
|
||||
return new CrystalChestTileEntity();
|
||||
case OBSIDIAN:
|
||||
return new ObsidianChestTileEntity();
|
||||
case DIRTCHEST9000:
|
||||
return new DirtChestTileEntity();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.CopperChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class CopperChestBlock extends ChestBlock
|
||||
{
|
||||
public CopperChestBlock(Properties properties)
|
||||
{
|
||||
super(properties, ChestType.COPPER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new CopperChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.CrystalChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class CrystalChestBlock extends ChestBlock
|
||||
{
|
||||
public CrystalChestBlock(Properties properties)
|
||||
{
|
||||
super(properties, ChestType.CRYSTAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new CrystalChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.DiamondChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class DiamondChestBlock extends ChestBlock
|
||||
{
|
||||
public DiamondChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.DIAMOND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new DiamondChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.DirtChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class DirtChestBlock extends ChestBlock
|
||||
{
|
||||
public DirtChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.DIRTCHEST9000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new DirtChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.GoldChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class GoldChestBlock extends ChestBlock
|
||||
{
|
||||
public GoldChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.GOLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new GoldChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class IronChestBlock extends ChestBlock
|
||||
{
|
||||
public IronChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.IRON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new IronChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.ObsidianChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class ObsidianChestBlock extends ChestBlock
|
||||
{
|
||||
public ObsidianChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.OBSIDIAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new ObsidianChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.blocks;
|
||||
|
||||
import com.progwml6.ironchest.common.tileentity.SilverChestTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
|
||||
public class SilverChestBlock extends ChestBlock
|
||||
{
|
||||
public SilverChestBlock(Block.Properties properties)
|
||||
{
|
||||
super(properties, ChestType.SILVER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new SilverChestTileEntity();
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.core;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.client.renderer.IronChestItemStackTileEntityRenderer;
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.CopperChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.CrystalChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.DiamondChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.DirtChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.GoldChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.IronChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.ObsidianChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.SilverChestBlock;
|
||||
import com.progwml6.ironchest.common.items.ChestItem;
|
||||
import com.progwml6.ironchest.common.util.BlockNames;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.Properties;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
public class IronChestBlocks
|
||||
{
|
||||
public static Properties itemBuilder;
|
||||
|
||||
@ObjectHolder(BlockNames.IRON_CHEST)
|
||||
public static ChestBlock ironChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.IRON_CHEST)
|
||||
public static Item ironChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.GOLD_CHEST)
|
||||
public static ChestBlock goldChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.GOLD_CHEST)
|
||||
public static Item goldChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.DIAMOND_CHEST)
|
||||
public static ChestBlock diamondChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.DIAMOND_CHEST)
|
||||
public static Item diamondChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.COPPER_CHEST)
|
||||
public static ChestBlock copperChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.COPPER_CHEST)
|
||||
public static Item copperChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.SILVER_CHEST)
|
||||
public static ChestBlock silverChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.SILVER_CHEST)
|
||||
public static Item silverChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.CRYSTAL_CHEST)
|
||||
public static ChestBlock crystalChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.CRYSTAL_CHEST)
|
||||
public static Item crystalChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.OBSIDIAN_CHEST)
|
||||
public static ChestBlock obsidianChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.OBSIDIAN_CHEST)
|
||||
public static Item obsidianChestItemBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.DIRT_CHEST)
|
||||
public static ChestBlock dirtChestBlock;
|
||||
|
||||
@ObjectHolder(BlockNames.DIRT_CHEST)
|
||||
public static Item dirtChestItemBlock;
|
||||
|
||||
public IronChestBlocks()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = IronChest.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerBlocks(final RegistryEvent.Register<Block> event)
|
||||
{
|
||||
IForgeRegistry<Block> blockRegistry = event.getRegistry();
|
||||
|
||||
blockRegistry.register(new IronChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new GoldChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new DiamondChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new CopperChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new SilverChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new CrystalChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
blockRegistry.register(new ObsidianChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 10000.0F)));
|
||||
blockRegistry.register(new DirtChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 3.0F)));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(final RegistryEvent.Register<Item> event)
|
||||
{
|
||||
IForgeRegistry<Item> itemRegistry = event.getRegistry();
|
||||
|
||||
itemBuilder = (new Properties()).group(IronChestItemGroups.IRON_CHESTS).setTEISR(() -> IronChestItemStackTileEntityRenderer::new);
|
||||
|
||||
itemRegistry.register(new ChestItem(ironChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(goldChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(diamondChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(copperChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(silverChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(crystalChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(obsidianChestBlock, itemBuilder));
|
||||
itemRegistry.register(new ChestItem(dirtChestBlock, itemBuilder));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.core;
|
||||
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class IronChestItemGroups
|
||||
{
|
||||
public static final ItemGroup IRON_CHESTS = new ItemGroup("ironchest")
|
||||
{
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public ItemStack createIcon()
|
||||
{
|
||||
return new ItemStack(IronChestBlocks.ironChestBlock);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.core;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.common.items.ChestChangerItem;
|
||||
import com.progwml6.ironchest.common.items.ChestChangerType;
|
||||
import com.progwml6.ironchest.common.util.ItemNames;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Item.Properties;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
public class IronChestItems
|
||||
{
|
||||
public static Properties itemProperties;
|
||||
|
||||
@ObjectHolder(ItemNames.IRON_GOLD_UPGRADE)
|
||||
public static Item ironToGoldUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.GOLD_DIAMOND_UPGRADE)
|
||||
public static Item goldToDiamondUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.COPPER_SILVER_UPGRADE)
|
||||
public static Item copperToSilverUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.SILVER_GOLD_UPGRADE)
|
||||
public static Item silverToGoldUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.COPPER_IRON_UPGRADE)
|
||||
public static Item copperToIronUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.DIAMOND_CRYSTAL_UPGRADE)
|
||||
public static Item diamondToCrystalUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.WOOD_IRON_UPGRADE)
|
||||
public static Item woodToIronUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.WOOD_COPPER_UPGRADE)
|
||||
public static Item woodToCopperUpgrade;
|
||||
|
||||
@ObjectHolder(ItemNames.DIAMOND_OBSIDIAN_UPGRADE)
|
||||
public static Item diamondToObsidianUpgrade;
|
||||
|
||||
public IronChestItems()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = IronChest.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void registerItems(final RegistryEvent.Register<Item> event)
|
||||
{
|
||||
IForgeRegistry<Item> itemRegistry = event.getRegistry();
|
||||
|
||||
itemProperties = (new Properties()).group(IronChestItemGroups.IRON_CHESTS).maxStackSize(1);
|
||||
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.IRON_GOLD));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.GOLD_DIAMOND));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.COPPER_SILVER));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.SILVER_GOLD));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.COPPER_IRON));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.DIAMOND_CRYSTAL));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.WOOD_IRON));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.WOOD_COPPER));
|
||||
itemRegistry.register(new ChestChangerItem(itemProperties, ChestChangerType.DIAMOND_OBSIDIAN));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.inventory;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class ChestContainer extends Container
|
||||
{
|
||||
private final IInventory inventory;
|
||||
|
||||
private final ChestType chestType;
|
||||
|
||||
private ChestContainer(ContainerType<?> containerType, int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
this(containerType, windowId, playerInventory, new Inventory(ChestType.WOOD.size), ChestType.WOOD);
|
||||
}
|
||||
|
||||
public static ChestContainer createIronContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.IRON_CHEST, windowId, playerInventory, new Inventory(ChestType.IRON.size), ChestType.IRON);
|
||||
}
|
||||
|
||||
public static ChestContainer createIronContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.IRON_CHEST, windowId, playerInventory, inventory, ChestType.IRON);
|
||||
}
|
||||
|
||||
public static ChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.GOLD_CHEST, windowId, playerInventory, new Inventory(ChestType.GOLD.size), ChestType.GOLD);
|
||||
}
|
||||
|
||||
public static ChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.GOLD_CHEST, windowId, playerInventory, inventory, ChestType.GOLD);
|
||||
}
|
||||
|
||||
public static ChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.DIAMOND_CHEST, windowId, playerInventory, new Inventory(ChestType.DIAMOND.size), ChestType.DIAMOND);
|
||||
}
|
||||
|
||||
public static ChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.DIAMOND_CHEST, windowId, playerInventory, inventory, ChestType.DIAMOND);
|
||||
}
|
||||
|
||||
public static ChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.CRYSTAL_CHEST, windowId, playerInventory, new Inventory(ChestType.CRYSTAL.size), ChestType.CRYSTAL);
|
||||
}
|
||||
|
||||
public static ChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.CRYSTAL_CHEST, windowId, playerInventory, inventory, ChestType.CRYSTAL);
|
||||
}
|
||||
|
||||
public static ChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.COPPER_CHEST, windowId, playerInventory, new Inventory(ChestType.COPPER.size), ChestType.COPPER);
|
||||
}
|
||||
|
||||
public static ChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.COPPER_CHEST, windowId, playerInventory, inventory, ChestType.COPPER);
|
||||
}
|
||||
|
||||
public static ChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.SILVER_CHEST, windowId, playerInventory, new Inventory(ChestType.CRYSTAL.size), ChestType.SILVER);
|
||||
}
|
||||
|
||||
public static ChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.SILVER_CHEST, windowId, playerInventory, inventory, ChestType.SILVER);
|
||||
}
|
||||
|
||||
public static ChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.OBSIDIAN_CHEST, windowId, playerInventory, new Inventory(ChestType.OBSIDIAN.size), ChestType.OBSIDIAN);
|
||||
}
|
||||
|
||||
public static ChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.OBSIDIAN_CHEST, windowId, playerInventory, inventory, ChestType.OBSIDIAN);
|
||||
}
|
||||
|
||||
public static ChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.DIRT_CHEST, windowId, playerInventory, new Inventory(ChestType.DIRTCHEST9000.size), ChestType.DIRTCHEST9000);
|
||||
}
|
||||
|
||||
public static ChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory, IInventory inventory)
|
||||
{
|
||||
return new ChestContainer(ChestContainerType.DIRT_CHEST, windowId, playerInventory, inventory, ChestType.DIRTCHEST9000);
|
||||
}
|
||||
|
||||
public ChestContainer(ContainerType<?> containerType, int windowId, PlayerInventory playerInventory, IInventory inventory, ChestType chestType)
|
||||
{
|
||||
super(containerType, windowId);
|
||||
assertInventorySize(inventory, chestType.size);
|
||||
|
||||
this.inventory = inventory;
|
||||
this.chestType = chestType;
|
||||
|
||||
inventory.openInventory(playerInventory.player);
|
||||
|
||||
if (chestType == ChestType.DIRTCHEST9000)
|
||||
{
|
||||
this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int chestRow = 0; chestRow < chestType.getRowCount(); chestRow++)
|
||||
{
|
||||
for (int chestCol = 0; chestCol < chestType.rowLength; chestCol++)
|
||||
{
|
||||
this.addSlot(new Slot(inventory, chestCol + chestRow * chestType.rowLength, 12 + chestCol * 18, 18 + chestRow * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int leftCol = (chestType.xSize - 162) / 2 + 1;
|
||||
|
||||
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++)
|
||||
{
|
||||
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
|
||||
{
|
||||
this.addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, chestType.ySize - (4 - playerInvRow) * 18 - 10));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++)
|
||||
{
|
||||
this.addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, chestType.ySize - 24));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn)
|
||||
{
|
||||
return this.inventory.isUsableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot = this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (index < this.chestType.size)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, this.chestType.size, this.inventorySlots.size(), true))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.chestType.size, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn)
|
||||
{
|
||||
super.onContainerClosed(playerIn);
|
||||
this.inventory.closeInventory(playerIn);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public ChestType getChestType()
|
||||
{
|
||||
return this.chestType;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.inventory;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.client.inventory.ChestScreen;
|
||||
import com.progwml6.ironchest.common.util.ContainerNames;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
public class ChestContainerType
|
||||
{
|
||||
@ObjectHolder(ContainerNames.IRON_CHEST)
|
||||
public static ContainerType<ChestContainer> IRON_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.GOLD_CHEST)
|
||||
public static ContainerType<ChestContainer> GOLD_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.DIAMOND_CHEST)
|
||||
public static ContainerType<ChestContainer> DIAMOND_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.CRYSTAL_CHEST)
|
||||
public static ContainerType<ChestContainer> CRYSTAL_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.COPPER_CHEST)
|
||||
public static ContainerType<ChestContainer> COPPER_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.SILVER_CHEST)
|
||||
public static ContainerType<ChestContainer> SILVER_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.OBSIDIAN_CHEST)
|
||||
public static ContainerType<ChestContainer> OBSIDIAN_CHEST;
|
||||
|
||||
@ObjectHolder(ContainerNames.DIRT_CHEST)
|
||||
public static ContainerType<ChestContainer> DIRT_CHEST;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = IronChest.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onContainerTypeRegistry(final RegistryEvent.Register<ContainerType<?>> e)
|
||||
{
|
||||
e.getRegistry().registerAll(
|
||||
new ContainerType<>(ChestContainer::createIronContainer).setRegistryName(ContainerNames.IRON_CHEST),
|
||||
new ContainerType<>(ChestContainer::createGoldContainer).setRegistryName(ContainerNames.GOLD_CHEST),
|
||||
new ContainerType<>(ChestContainer::createDiamondContainer).setRegistryName(ContainerNames.DIAMOND_CHEST),
|
||||
new ContainerType<>(ChestContainer::createCrystalContainer).setRegistryName(ContainerNames.CRYSTAL_CHEST),
|
||||
new ContainerType<>(ChestContainer::createCopperContainer).setRegistryName(ContainerNames.COPPER_CHEST),
|
||||
new ContainerType<>(ChestContainer::createSilverContainer).setRegistryName(ContainerNames.SILVER_CHEST),
|
||||
new ContainerType<>(ChestContainer::createObsidianContainer).setRegistryName(ContainerNames.OBSIDIAN_CHEST),
|
||||
new ContainerType<>(ChestContainer::createDirtContainer).setRegistryName(ContainerNames.DIRT_CHEST)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static void registerScreenFactories()
|
||||
{
|
||||
ScreenManager.registerFactory(IRON_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(GOLD_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(DIAMOND_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(CRYSTAL_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(COPPER_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(SILVER_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(OBSIDIAN_CHEST, ChestScreen::new);
|
||||
ScreenManager.registerFactory(DIRT_CHEST, ChestScreen::new);
|
||||
}
|
||||
}
|
|
@ -1,13 +1,3 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.inventory;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -16,16 +6,14 @@ import net.minecraft.inventory.container.Slot;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class DirtChestSlot extends Slot
|
||||
{
|
||||
public DirtChestSlot(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
}
|
||||
public class DirtChestSlot extends Slot {
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return stack.isEmpty() || stack.getItem() == Item.getItemFromBlock(Blocks.DIRT);
|
||||
}
|
||||
}
|
||||
public DirtChestSlot(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) {
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return stack.isEmpty() || stack.getItem() == Item.getItemFromBlock(Blocks.DIRT);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
package com.progwml6.ironchest.common.inventory;
|
||||
|
||||
import com.progwml6.ironchest.common.block.IronChestsTypes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public class IronChestContainer extends Container {
|
||||
|
||||
private final IInventory inventory;
|
||||
|
||||
private final IronChestsTypes chestType;
|
||||
|
||||
private IronChestContainer(ContainerType<?> containerType, int windowId, PlayerInventory playerInventory) {
|
||||
this(containerType, windowId, playerInventory, new Inventory(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD);
|
||||
}
|
||||
|
||||
public static IronChestContainer createIronContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.IRON.size), IronChestsTypes.IRON);
|
||||
}
|
||||
|
||||
public static IronChestContainer createIronContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.IRON);
|
||||
}
|
||||
|
||||
public static IronChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD);
|
||||
}
|
||||
|
||||
public static IronChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.GOLD);
|
||||
}
|
||||
|
||||
public static IronChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND);
|
||||
}
|
||||
|
||||
public static IronChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIAMOND);
|
||||
}
|
||||
|
||||
public static IronChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL);
|
||||
}
|
||||
|
||||
public static IronChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.CRYSTAL);
|
||||
}
|
||||
|
||||
public static IronChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER);
|
||||
}
|
||||
|
||||
public static IronChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.COPPER);
|
||||
}
|
||||
|
||||
public static IronChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER);
|
||||
}
|
||||
|
||||
public static IronChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.SILVER);
|
||||
}
|
||||
|
||||
public static IronChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN);
|
||||
}
|
||||
|
||||
public static IronChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.OBSIDIAN);
|
||||
}
|
||||
|
||||
public static IronChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIRTCHEST9000.size), IronChestsTypes.DIRTCHEST9000);
|
||||
}
|
||||
|
||||
public static IronChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) {
|
||||
return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIRTCHEST9000);
|
||||
}
|
||||
|
||||
public IronChestContainer(ContainerType<?> containerType, int windowId, PlayerInventory playerInventory, IInventory inventory, IronChestsTypes chestType) {
|
||||
super(containerType, windowId);
|
||||
assertInventorySize(inventory, chestType.size);
|
||||
|
||||
this.inventory = inventory;
|
||||
this.chestType = chestType;
|
||||
|
||||
inventory.openInventory(playerInventory.player);
|
||||
|
||||
if (chestType == IronChestsTypes.DIRTCHEST9000) {
|
||||
this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18));
|
||||
}
|
||||
else {
|
||||
for (int chestRow = 0; chestRow < chestType.getRowCount(); chestRow++) {
|
||||
for (int chestCol = 0; chestCol < chestType.rowLength; chestCol++) {
|
||||
this.addSlot(new Slot(inventory, chestCol + chestRow * chestType.rowLength, 12 + chestCol * 18, 18 + chestRow * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int leftCol = (chestType.xSize - 162) / 2 + 1;
|
||||
|
||||
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) {
|
||||
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) {
|
||||
this.addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, chestType.ySize - (4 - playerInvRow) * 18 - 10));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) {
|
||||
this.addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, chestType.ySize - 24));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(PlayerEntity playerIn) {
|
||||
return this.inventory.isUsableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
|
||||
ItemStack itemstack = ItemStack.EMPTY;
|
||||
Slot slot = this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (index < this.chestType.size) {
|
||||
if (!this.mergeItemStack(itemstack1, this.chestType.size, this.inventorySlots.size(), true)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, this.chestType.size, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if (itemstack1.isEmpty()) {
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
}
|
||||
else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
this.inventory.closeInventory(playerIn);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public IronChestsTypes getChestType() {
|
||||
return this.chestType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.progwml6.ironchest.common.inventory;
|
||||
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class IronChestsContainerTypes {
|
||||
|
||||
public static final DeferredRegister<ContainerType<?>> CONTAINERS = new DeferredRegister<>(ForgeRegistries.CONTAINERS, IronChests.MODID);
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> IRON_CHEST = CONTAINERS.register("iron_chest", () -> new ContainerType<>(IronChestContainer::createIronContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> GOLD_CHEST = CONTAINERS.register("gold_chest", () -> new ContainerType<>(IronChestContainer::createGoldContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> DIAMOND_CHEST = CONTAINERS.register("diamond_chest", () -> new ContainerType<>(IronChestContainer::createDiamondContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> CRYSTAL_CHEST = CONTAINERS.register("crystal_chest", () -> new ContainerType<>(IronChestContainer::createCrystalContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> COPPER_CHEST = CONTAINERS.register("copper_chest", () -> new ContainerType<>(IronChestContainer::createCopperContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> SILVER_CHEST = CONTAINERS.register("silver_chest", () -> new ContainerType<>(IronChestContainer::createSilverContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> OBSIDIAN_CHEST = CONTAINERS.register("obsidian_chest", () -> new ContainerType<>(IronChestContainer::createObsidianContainer));
|
||||
|
||||
public static final RegistryObject<ContainerType<IronChestContainer>> DIRT_CHEST = CONTAINERS.register("dirt_chest", () -> new ContainerType<>(IronChestContainer::createDirtContainer));
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.progwml6.ironchest.common.item;
|
||||
|
||||
import com.progwml6.ironchest.IronChests;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class IronChestsItems {
|
||||
|
||||
public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, IronChests.MODID);
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.items;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.tileentity.IronChestTileEntity;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.tileentity.ChestTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ChestChangerItem extends TooltipItem
|
||||
{
|
||||
public final ChestChangerType type;
|
||||
|
||||
public ChestChangerItem(Properties properties, ChestChangerType chestChangerType)
|
||||
{
|
||||
super(properties);
|
||||
this.type = chestChangerType;
|
||||
this.setRegistryName(chestChangerType.itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context)
|
||||
{
|
||||
PlayerEntity entityPlayer = context.getPlayer();
|
||||
BlockPos blockPos = context.getPos();
|
||||
World world = context.getWorld();
|
||||
ItemStack itemStack = context.getItem();
|
||||
|
||||
if (world.isRemote)
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
if (this.type.canUpgrade(ChestType.WOOD))
|
||||
{
|
||||
if (!(world.getBlockState(blockPos).getBlock() instanceof net.minecraft.block.ChestBlock))
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (world.getBlockState(blockPos).getBlock().getDefaultState() != ChestType.get(this.type.source))
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
|
||||
if (this.type.canUpgrade(ChestType.WOOD))
|
||||
{
|
||||
if (!(tileEntity instanceof ChestTileEntity))
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
IronChestTileEntity newChest = new IronChestTileEntity();
|
||||
|
||||
ITextComponent customName = null;
|
||||
|
||||
NonNullList<ItemStack> chestContents = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
|
||||
Direction chestFacing = Direction.NORTH;
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
if (tileEntity instanceof IronChestTileEntity)
|
||||
{
|
||||
IronChestTileEntity chest = (IronChestTileEntity) tileEntity;
|
||||
BlockState chestState = world.getBlockState(blockPos);
|
||||
|
||||
chestContents = chest.getItems();
|
||||
chestFacing = chestState.get(ChestBlock.FACING);
|
||||
customName = chest.getCustomName();
|
||||
newChest = this.type.target.makeEntity();
|
||||
|
||||
if (newChest == null)
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof ChestTileEntity)
|
||||
{
|
||||
BlockState chestState = world.getBlockState(blockPos);
|
||||
chestFacing = chestState.get(net.minecraft.block.ChestBlock.FACING);
|
||||
ChestTileEntity chest = (ChestTileEntity) tileEntity;
|
||||
|
||||
if (ChestTileEntity.getPlayersUsing(world, blockPos) > 0)
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
if (!this.type.canUpgrade(ChestType.WOOD))
|
||||
{
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
chestContents = NonNullList.<ItemStack>withSize(chest.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for (int slot = 0; slot < chestContents.size(); slot++)
|
||||
{
|
||||
chestContents.set(slot, chest.getStackInSlot(slot));
|
||||
}
|
||||
|
||||
customName = chest.getCustomName();
|
||||
|
||||
newChest = this.type.target.makeEntity();
|
||||
}
|
||||
}
|
||||
|
||||
tileEntity.updateContainingBlockInfo();
|
||||
|
||||
world.removeTileEntity(blockPos);
|
||||
world.removeBlock(blockPos, false);
|
||||
|
||||
BlockState iBlockState = ChestType.get(this.type.target).with(ChestBlock.FACING, chestFacing);
|
||||
|
||||
world.setTileEntity(blockPos, newChest);
|
||||
world.setBlockState(blockPos, iBlockState, 3);
|
||||
|
||||
world.notifyBlockUpdate(blockPos, iBlockState, iBlockState, 3);
|
||||
|
||||
TileEntity tileEntity2 = world.getTileEntity(blockPos);
|
||||
|
||||
if (tileEntity2 instanceof IronChestTileEntity)
|
||||
{
|
||||
if (customName != null)
|
||||
{
|
||||
((IronChestTileEntity) tileEntity2).setCustomName(customName);
|
||||
}
|
||||
|
||||
((IronChestTileEntity) tileEntity2).setItems(chestContents);
|
||||
}
|
||||
|
||||
if (!entityPlayer.abilities.isCreativeMode)
|
||||
{
|
||||
itemStack.shrink(1);
|
||||
}
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.items;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.util.ItemNames;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.COPPER;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.CRYSTAL;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.DIAMOND;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.GOLD;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.IRON;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.OBSIDIAN;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.SILVER;
|
||||
import static com.progwml6.ironchest.common.blocks.ChestType.WOOD;
|
||||
|
||||
public enum ChestChangerType
|
||||
{
|
||||
//@formatter:off
|
||||
IRON_GOLD(IRON, GOLD, ItemNames.IRON_GOLD_UPGRADE),
|
||||
GOLD_DIAMOND(GOLD, DIAMOND, ItemNames.GOLD_DIAMOND_UPGRADE),
|
||||
COPPER_SILVER(COPPER, SILVER, ItemNames.COPPER_SILVER_UPGRADE),
|
||||
SILVER_GOLD(SILVER, GOLD, ItemNames.SILVER_GOLD_UPGRADE),
|
||||
COPPER_IRON(COPPER, IRON, ItemNames.COPPER_IRON_UPGRADE),
|
||||
DIAMOND_CRYSTAL(DIAMOND, CRYSTAL, ItemNames.DIAMOND_CRYSTAL_UPGRADE),
|
||||
WOOD_IRON(WOOD, IRON, ItemNames.WOOD_IRON_UPGRADE),
|
||||
WOOD_COPPER(WOOD, COPPER, ItemNames.WOOD_COPPER_UPGRADE),
|
||||
DIAMOND_OBSIDIAN(DIAMOND, OBSIDIAN, ItemNames.DIAMOND_OBSIDIAN_UPGRADE);
|
||||
//@formatter:on
|
||||
|
||||
public final ChestType source;
|
||||
|
||||
public final ChestType target;
|
||||
|
||||
public final ResourceLocation itemName;
|
||||
|
||||
ChestChangerType(ChestType source, ChestType target, String itemName)
|
||||
{
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.itemName = new ResourceLocation(itemName);
|
||||
}
|
||||
|
||||
public boolean canUpgrade(ChestType from)
|
||||
{
|
||||
return from == this.source;
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.items;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ChestItem extends BlockItem
|
||||
{
|
||||
public ChestItem(Block block, Item.Properties properties)
|
||||
{
|
||||
super(block, properties);
|
||||
|
||||
this.setRegistryName(block.getRegistryName());
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.items;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class TooltipItem extends Item
|
||||
{
|
||||
public TooltipItem(Properties properties)
|
||||
{
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn)
|
||||
{
|
||||
addOptionalTooltip(stack, tooltip);
|
||||
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
}
|
||||
|
||||
public static void addOptionalTooltip(ItemStack stack, List<ITextComponent> tooltip)
|
||||
{
|
||||
if (I18n.hasKey(stack.getDisplayName() + ".tooltip"))
|
||||
{
|
||||
for (String tooltipString : getTooltips(TextFormatting.GRAY.toString() + translateRecursive(stack.getDisplayName() + ".tooltip")))
|
||||
{
|
||||
tooltip.add(new StringTextComponent(tooltipString));
|
||||
}
|
||||
}
|
||||
else if (I18n.hasKey(stack.getDisplayName() + ".tooltip"))
|
||||
{
|
||||
for (String tooltipString : getTooltips(TextFormatting.GRAY.toString() + translateRecursive(stack.getDisplayName() + ".tooltip")))
|
||||
{
|
||||
tooltip.add(new StringTextComponent(tooltipString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String translateRecursive(String key, Object... params)
|
||||
{
|
||||
return I18n.format(I18n.format(key, params));
|
||||
}
|
||||
|
||||
public static List<String> getTooltips(String text)
|
||||
{
|
||||
List<String> list = Lists.newLinkedList();
|
||||
if (text == null)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
int j = 0;
|
||||
int k;
|
||||
while ((k = text.indexOf("\\n", j)) >= 0)
|
||||
{
|
||||
list.add(text.substring(j, k));
|
||||
j = k + 2;
|
||||
}
|
||||
|
||||
list.add(text.substring(j, text.length()));
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.network;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.common.network.packets.PacketTopStackSyncChest;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
public final class PacketHandler
|
||||
{
|
||||
private static final String PROTOCOL_VERSION = Integer.toString(1);
|
||||
|
||||
private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(IronChest.MOD_ID, "main_channel"))
|
||||
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
|
||||
.networkProtocolVersion(() -> PROTOCOL_VERSION)
|
||||
.simpleChannel();
|
||||
|
||||
public static void register()
|
||||
{
|
||||
int disc = 0;
|
||||
|
||||
HANDLER.registerMessage(disc++, PacketTopStackSyncChest.class, PacketTopStackSyncChest::encode, PacketTopStackSyncChest::decode, PacketTopStackSyncChest.Handler::handle);
|
||||
}
|
||||
|
||||
public static <MSG> void send(PacketDistributor.PacketTarget target, MSG message)
|
||||
{
|
||||
HANDLER.send(target, message);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.network.packets;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.common.tileentity.CrystalChestTileEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PacketTopStackSyncChest
|
||||
{
|
||||
private final int dimension;
|
||||
|
||||
private final BlockPos pos;
|
||||
|
||||
private final NonNullList<ItemStack> topStacks;
|
||||
|
||||
public PacketTopStackSyncChest(int dimension, BlockPos pos, NonNullList<ItemStack> topStacks)
|
||||
{
|
||||
this.dimension = dimension;
|
||||
this.pos = pos;
|
||||
this.topStacks = topStacks;
|
||||
}
|
||||
|
||||
public static void encode(PacketTopStackSyncChest msg, PacketBuffer buf)
|
||||
{
|
||||
buf.writeInt(msg.dimension);
|
||||
buf.writeInt(msg.pos.getX());
|
||||
buf.writeInt(msg.pos.getY());
|
||||
buf.writeInt(msg.pos.getZ());
|
||||
buf.writeInt(msg.topStacks.size());
|
||||
|
||||
for (ItemStack stack : msg.topStacks)
|
||||
{
|
||||
buf.writeItemStack(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketTopStackSyncChest decode(PacketBuffer buf)
|
||||
{
|
||||
int dimension = buf.readInt();
|
||||
BlockPos pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||
|
||||
int size = buf.readInt();
|
||||
NonNullList<ItemStack> topStacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY);
|
||||
|
||||
for (int item = 0; item < size; item++)
|
||||
{
|
||||
ItemStack itemStack = buf.readItemStack();
|
||||
|
||||
topStacks.set(item, itemStack);
|
||||
}
|
||||
|
||||
return new PacketTopStackSyncChest(dimension, pos, topStacks);
|
||||
}
|
||||
|
||||
public static class Handler
|
||||
{
|
||||
public static void handle(final PacketTopStackSyncChest message, Supplier<NetworkEvent.Context> ctx)
|
||||
{
|
||||
ctx.get().enqueueWork(() -> {
|
||||
World world = IronChest.proxy.getClientWorld();
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(message.pos);
|
||||
|
||||
if (tile instanceof CrystalChestTileEntity)
|
||||
{
|
||||
((CrystalChestTileEntity) tile).receiveMessageFromServer(message.topStacks);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.util.TileEntityNames;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ChestTileEntityType
|
||||
{
|
||||
@ObjectHolder(TileEntityNames.IRON_CHEST)
|
||||
public static TileEntityType<?> IRON_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.GOLD_CHEST)
|
||||
public static TileEntityType<?> GOLD_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.DIAMOND_CHEST)
|
||||
public static TileEntityType<?> DIAMOND_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.CRYSTAL_CHEST)
|
||||
public static TileEntityType<?> CRYSTAL_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.DIRT_CHEST)
|
||||
public static TileEntityType<?> DIRT_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.COPPER_CHEST)
|
||||
public static TileEntityType<?> COPPER_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.SILVER_CHEST)
|
||||
public static TileEntityType<?> SILVER_CHEST;
|
||||
|
||||
@ObjectHolder(TileEntityNames.OBSIDIAN_CHEST)
|
||||
public static TileEntityType<?> OBSIDIAN_CHEST;
|
||||
|
||||
public ChestTileEntityType()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = IronChest.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class Registration
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onTileEntityRegistry(final RegistryEvent.Register<TileEntityType<?>> e)
|
||||
{
|
||||
e.getRegistry().registerAll(
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) IronChestTileEntity::new, IronChestBlocks.ironChestBlock).build(null).setRegistryName(TileEntityNames.IRON_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) GoldChestTileEntity::new, IronChestBlocks.goldChestBlock).build(null).setRegistryName(TileEntityNames.GOLD_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) DiamondChestTileEntity::new, IronChestBlocks.diamondChestBlock).build(null).setRegistryName(TileEntityNames.DIAMOND_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) CrystalChestTileEntity::new, IronChestBlocks.crystalChestBlock).build(null).setRegistryName(TileEntityNames.CRYSTAL_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) DirtChestTileEntity::new, IronChestBlocks.dirtChestBlock).build(null).setRegistryName(TileEntityNames.DIRT_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) CopperChestTileEntity::new, IronChestBlocks.copperChestBlock).build(null).setRegistryName(TileEntityNames.COPPER_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) SilverChestTileEntity::new, IronChestBlocks.silverChestBlock).build(null).setRegistryName(TileEntityNames.SILVER_CHEST),
|
||||
TileEntityType.Builder.create((Supplier<TileEntity>) ObsidianChestTileEntity::new, IronChestBlocks.obsidianChestBlock).build(null).setRegistryName(TileEntityNames.OBSIDIAN_CHEST)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class CopperChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
public CopperChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.COPPER_CHEST, ChestType.COPPER, IronChestBlocks.copperChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createCopperContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import com.progwml6.ironchest.common.network.PacketHandler;
|
||||
import com.progwml6.ironchest.common.network.packets.PacketTopStackSyncChest;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class CrystalChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
private NonNullList<ItemStack> topStacks;
|
||||
|
||||
private boolean inventoryTouched;
|
||||
|
||||
private boolean hadStuff;
|
||||
|
||||
public CrystalChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.CRYSTAL_CHEST, ChestType.CRYSTAL, IronChestBlocks.crystalChestBlock);
|
||||
this.topStacks = NonNullList.<ItemStack>withSize(8, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createCrystalContainer(id, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
super.tick();
|
||||
|
||||
if (!this.world.isRemote && this.inventoryTouched)
|
||||
{
|
||||
this.inventoryTouched = false;
|
||||
|
||||
this.sortTopStacks();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(NonNullList<ItemStack> contents)
|
||||
{
|
||||
super.setItems(contents);
|
||||
|
||||
this.inventoryTouched = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index)
|
||||
{
|
||||
this.inventoryTouched = true;
|
||||
|
||||
return super.getStackInSlot(index);
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> getTopItems()
|
||||
{
|
||||
return this.topStacks;
|
||||
}
|
||||
|
||||
private void sortTopStacks()
|
||||
{
|
||||
if (!this.getChestType().isTransparent() || (this.world != null && this.world.isRemote))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
boolean hasStuff = false;
|
||||
|
||||
int compressedIdx = 0;
|
||||
|
||||
mainLoop:
|
||||
for (int i = 0; i < this.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack itemStack = this.getItems().get(i);
|
||||
|
||||
if (!itemStack.isEmpty())
|
||||
{
|
||||
for (int j = 0; j < compressedIdx; j++)
|
||||
{
|
||||
ItemStack tempCopyStack = tempCopy.get(j);
|
||||
|
||||
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack))
|
||||
{
|
||||
if (itemStack.getCount() != tempCopyStack.getCount())
|
||||
{
|
||||
tempCopyStack.grow(itemStack.getCount());
|
||||
}
|
||||
|
||||
continue mainLoop;
|
||||
}
|
||||
}
|
||||
|
||||
tempCopy.set(compressedIdx, itemStack.copy());
|
||||
|
||||
compressedIdx++;
|
||||
|
||||
hasStuff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStuff && this.hadStuff)
|
||||
{
|
||||
this.hadStuff = false;
|
||||
|
||||
for (int i = 0; i < this.getTopItems().size(); i++)
|
||||
{
|
||||
this.getTopItems().set(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (this.world != null)
|
||||
{
|
||||
BlockState iblockstate = this.world.getBlockState(this.pos);
|
||||
|
||||
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.hadStuff = true;
|
||||
|
||||
Collections.sort(tempCopy, (stack1, stack2) -> {
|
||||
if (stack1.isEmpty())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (stack2.isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return stack2.getCount() - stack1.getCount();
|
||||
}
|
||||
});
|
||||
|
||||
int p = 0;
|
||||
|
||||
for (ItemStack element : tempCopy)
|
||||
{
|
||||
if (!element.isEmpty() && element.getCount() > 0)
|
||||
{
|
||||
if (p == this.getTopItems().size())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.getTopItems().set(p, element);
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = p; i < this.getTopItems().size(); i++)
|
||||
{
|
||||
this.getTopItems().set(i, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
if (this.world != null)
|
||||
{
|
||||
BlockState iblockstate = this.world.getBlockState(this.pos);
|
||||
|
||||
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
|
||||
}
|
||||
|
||||
sendTopStacksPacket();
|
||||
}
|
||||
|
||||
public NonNullList<ItemStack> buildItemStackDataList()
|
||||
{
|
||||
if (this.getChestType().isTransparent())
|
||||
{
|
||||
NonNullList<ItemStack> sortList = NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
|
||||
|
||||
int pos = 0;
|
||||
|
||||
for (ItemStack is : this.topStacks)
|
||||
{
|
||||
if (!is.isEmpty())
|
||||
{
|
||||
sortList.set(pos, is);
|
||||
}
|
||||
else
|
||||
{
|
||||
sortList.set(pos, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
pos++;
|
||||
}
|
||||
|
||||
return sortList;
|
||||
}
|
||||
|
||||
return NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
protected void sendTopStacksPacket()
|
||||
{
|
||||
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
|
||||
|
||||
PacketHandler.send(PacketDistributor.TRACKING_CHUNK.with(() -> (Chunk) this.getWorld().getChunk(this.getPos())), new PacketTopStackSyncChest(this.getWorld().getDimension().getType().getId(), this.getPos(), stacks));
|
||||
}
|
||||
|
||||
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks)
|
||||
{
|
||||
this.topStacks = topStacks;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class DiamondChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
public DiamondChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.DIAMOND_CHEST, ChestType.DIAMOND, IronChestBlocks.diamondChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createDiamondContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.StringNBT;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public class DirtChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.WRITTEN_BOOK);
|
||||
|
||||
private static boolean bookDataCreated = false;
|
||||
|
||||
public DirtChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.DIRT_CHEST, ChestType.DIRTCHEST9000, IronChestBlocks.dirtChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createDirtContainer(id, playerInventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wasPlaced(LivingEntity entityLivingBase, ItemStack itemStack)
|
||||
{
|
||||
if (!(itemStack.hasTag() && itemStack.getTag().getBoolean("been_placed")))
|
||||
{
|
||||
this.setInventorySlotContents(0, dirtChest9000GuideBook.copy());
|
||||
}
|
||||
|
||||
if (!bookDataCreated)
|
||||
{
|
||||
createBookData();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAdornments()
|
||||
{
|
||||
if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).isItemEqual(dirtChest9000GuideBook))
|
||||
{
|
||||
this.getItems().set(0, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createBookData()
|
||||
{
|
||||
dirtChest9000GuideBook.setTagInfo("author", new StringNBT("cpw"));
|
||||
|
||||
dirtChest9000GuideBook.setTagInfo("title", new StringNBT(I18n.format("book.ironchest.dirtchest9000.title")));
|
||||
|
||||
ListNBT pages = new ListNBT();
|
||||
pages.add(new StringNBT(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page1"))));
|
||||
pages.add(new StringNBT(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page2"))));
|
||||
pages.add(new StringNBT(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page3"))));
|
||||
pages.add(new StringNBT(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page4"))));
|
||||
pages.add(new StringNBT(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page5"))));
|
||||
|
||||
dirtChest9000GuideBook.setTagInfo("pages", pages);
|
||||
|
||||
bookDataCreated = true;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class GoldChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
public GoldChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.GOLD_CHEST, ChestType.GOLD, IronChestBlocks.goldChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createGoldContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,339 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestBlock;
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.ItemStackHelper;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.IChestLid;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
import net.minecraft.tileentity.LockableLootTileEntity;
|
||||
import net.minecraft.tileentity.LockableTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@OnlyIn(
|
||||
value = Dist.CLIENT,
|
||||
_interface = IChestLid.class
|
||||
)
|
||||
public class IronChestTileEntity extends LockableLootTileEntity implements IChestLid, ITickableTileEntity
|
||||
{
|
||||
private NonNullList<ItemStack> chestContents;
|
||||
|
||||
protected float lidAngle;
|
||||
|
||||
protected float prevLidAngle;
|
||||
|
||||
protected int numPlayersUsing;
|
||||
|
||||
private int ticksSinceSync;
|
||||
|
||||
private ChestType chestType;
|
||||
|
||||
private Block blockToUse;
|
||||
|
||||
protected IronChestTileEntity(TileEntityType<?> typeIn, ChestType chestTypeIn, Block blockToUseIn)
|
||||
{
|
||||
super(typeIn);
|
||||
|
||||
this.chestContents = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY);
|
||||
this.chestType = chestTypeIn;
|
||||
this.blockToUse = blockToUseIn;
|
||||
}
|
||||
|
||||
public IronChestTileEntity()
|
||||
{
|
||||
this(ChestTileEntityType.IRON_CHEST, ChestType.IRON, IronChestBlocks.ironChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.getItems().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for (ItemStack itemstack : this.chestContents)
|
||||
{
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ITextComponent getDefaultName()
|
||||
{
|
||||
return new TranslationTextComponent("container.chest");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(CompoundNBT compound)
|
||||
{
|
||||
super.read(compound);
|
||||
|
||||
this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
if (!this.checkLootAndRead(compound))
|
||||
{
|
||||
ItemStackHelper.loadAllItems(compound, this.chestContents);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundNBT write(CompoundNBT compound)
|
||||
{
|
||||
super.write(compound);
|
||||
|
||||
if (!this.checkLootAndWrite(compound))
|
||||
{
|
||||
ItemStackHelper.saveAllItems(compound, this.chestContents);
|
||||
}
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
int i = this.pos.getX();
|
||||
int j = this.pos.getY();
|
||||
int k = this.pos.getZ();
|
||||
++this.ticksSinceSync;
|
||||
this.numPlayersUsing = getNumberOfPlayersUsing(this.world, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing);
|
||||
this.prevLidAngle = this.lidAngle;
|
||||
float f = 0.1F;
|
||||
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F)
|
||||
{
|
||||
this.playSound(SoundEvents.BLOCK_CHEST_OPEN);
|
||||
}
|
||||
|
||||
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
|
||||
{
|
||||
float f1 = this.lidAngle;
|
||||
if (this.numPlayersUsing > 0)
|
||||
{
|
||||
this.lidAngle += 0.1F;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lidAngle -= 0.1F;
|
||||
}
|
||||
|
||||
if (this.lidAngle > 1.0F)
|
||||
{
|
||||
this.lidAngle = 1.0F;
|
||||
}
|
||||
|
||||
float f2 = 0.5F;
|
||||
if (this.lidAngle < 0.5F && f1 >= 0.5F)
|
||||
{
|
||||
this.playSound(SoundEvents.BLOCK_CHEST_CLOSE);
|
||||
}
|
||||
|
||||
if (this.lidAngle < 0.0F)
|
||||
{
|
||||
this.lidAngle = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int getNumberOfPlayersUsing(World worldIn, LockableTileEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing)
|
||||
{
|
||||
if (!worldIn.isRemote && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0)
|
||||
{
|
||||
numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z);
|
||||
}
|
||||
|
||||
return numPlayersUsing;
|
||||
}
|
||||
|
||||
public static int getNumberOfPlayersUsing(World world, LockableTileEntity lockableTileEntity, int x, int y, int z)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (PlayerEntity playerentity : world.getEntitiesWithinAABB(PlayerEntity.class, new AxisAlignedBB((double) ((float) x - 5.0F), (double) ((float) y - 5.0F), (double) ((float) z - 5.0F), (double) ((float) (x + 1) + 5.0F), (double) ((float) (y + 1) + 5.0F), (double) ((float) (z + 1) + 5.0F))))
|
||||
{
|
||||
if (playerentity.openContainer instanceof ChestContainer)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private void playSound(SoundEvent soundIn)
|
||||
{
|
||||
double d0 = (double) this.pos.getX() + 0.5D;
|
||||
double d1 = (double) this.pos.getY() + 0.5D;
|
||||
double d2 = (double) this.pos.getZ() + 0.5D;
|
||||
|
||||
this.world.playSound((PlayerEntity) null, d0, d1, d2, soundIn, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean receiveClientEvent(int id, int type)
|
||||
{
|
||||
if (id == 1)
|
||||
{
|
||||
this.numPlayersUsing = type;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.receiveClientEvent(id, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player)
|
||||
{
|
||||
if (!player.isSpectator())
|
||||
{
|
||||
if (this.numPlayersUsing < 0)
|
||||
{
|
||||
this.numPlayersUsing = 0;
|
||||
}
|
||||
|
||||
++this.numPlayersUsing;
|
||||
this.onOpenOrClose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player)
|
||||
{
|
||||
if (!player.isSpectator())
|
||||
{
|
||||
--this.numPlayersUsing;
|
||||
this.onOpenOrClose();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onOpenOrClose()
|
||||
{
|
||||
Block block = this.getBlockState().getBlock();
|
||||
|
||||
if (block instanceof ChestBlock)
|
||||
{
|
||||
this.world.addBlockEvent(this.pos, block, 1, this.numPlayersUsing);
|
||||
this.world.notifyNeighborsOfStateChange(this.pos, block);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getItems()
|
||||
{
|
||||
return this.chestContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(NonNullList<ItemStack> itemsIn)
|
||||
{
|
||||
this.chestContents = NonNullList.<ItemStack>withSize(this.getChestType().size, ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < itemsIn.size(); i++)
|
||||
{
|
||||
if (i < this.chestContents.size())
|
||||
{
|
||||
this.getItems().set(i, itemsIn.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public float getLidAngle(float partialTicks)
|
||||
{
|
||||
return MathHelper.lerp(partialTicks, this.prevLidAngle, this.lidAngle);
|
||||
}
|
||||
|
||||
public static int getPlayersUsing(IBlockReader reader, BlockPos posIn)
|
||||
{
|
||||
BlockState blockstate = reader.getBlockState(posIn);
|
||||
if (blockstate.hasTileEntity())
|
||||
{
|
||||
TileEntity tileentity = reader.getTileEntity(posIn);
|
||||
if (tileentity instanceof IronChestTileEntity)
|
||||
{
|
||||
return ((IronChestTileEntity) tileentity).numPlayersUsing;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int windowId, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createIronContainer(windowId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void wasPlaced(LivingEntity entityliving, ItemStack stack)
|
||||
{
|
||||
}
|
||||
|
||||
public void removeAdornments()
|
||||
{
|
||||
}
|
||||
|
||||
public ChestType getChestType()
|
||||
{
|
||||
ChestType type = ChestType.IRON;
|
||||
|
||||
if (this.hasWorld())
|
||||
{
|
||||
ChestType typeNew = ChestBlock.getTypeFromBlock(this.getBlockState().getBlock());
|
||||
|
||||
if (typeNew != null)
|
||||
{
|
||||
type = typeNew;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public Block getBlockToUse()
|
||||
{
|
||||
return this.blockToUse;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class ObsidianChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
public ObsidianChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.OBSIDIAN_CHEST, ChestType.OBSIDIAN, IronChestBlocks.obsidianChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createObsidianContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.tileentity;
|
||||
|
||||
import com.progwml6.ironchest.common.blocks.ChestType;
|
||||
import com.progwml6.ironchest.common.core.IronChestBlocks;
|
||||
import com.progwml6.ironchest.common.inventory.ChestContainer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
public class SilverChestTileEntity extends IronChestTileEntity
|
||||
{
|
||||
public SilverChestTileEntity()
|
||||
{
|
||||
super(ChestTileEntityType.SILVER_CHEST, ChestType.SILVER, IronChestBlocks.silverChestBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Container createMenu(int id, PlayerInventory playerInventory)
|
||||
{
|
||||
return ChestContainer.createSilverContainer(id, playerInventory, this);
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.util;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
|
||||
public class BlockNames
|
||||
{
|
||||
public static final String IRON_CHEST = IronChest.MOD_ID + ":iron_chest";
|
||||
|
||||
public static final String GOLD_CHEST = IronChest.MOD_ID + ":gold_chest";
|
||||
|
||||
public static final String DIAMOND_CHEST = IronChest.MOD_ID + ":diamond_chest";
|
||||
|
||||
public static final String COPPER_CHEST = IronChest.MOD_ID + ":copper_chest";
|
||||
|
||||
public static final String SILVER_CHEST = IronChest.MOD_ID + ":silver_chest";
|
||||
|
||||
public static final String CRYSTAL_CHEST = IronChest.MOD_ID + ":crystal_chest";
|
||||
|
||||
public static final String OBSIDIAN_CHEST = IronChest.MOD_ID + ":obsidian_chest";
|
||||
|
||||
public static final String DIRT_CHEST = IronChest.MOD_ID + ":dirt_chest";
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.util;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
|
||||
public class ContainerNames
|
||||
{
|
||||
public static final String IRON_CHEST = IronChest.MOD_ID + ":iron_chest";
|
||||
|
||||
public static final String GOLD_CHEST = IronChest.MOD_ID + ":gold_chest";
|
||||
|
||||
public static final String DIAMOND_CHEST = IronChest.MOD_ID + ":diamond_chest";
|
||||
|
||||
public static final String COPPER_CHEST = IronChest.MOD_ID + ":copper_chest";
|
||||
|
||||
public static final String SILVER_CHEST = IronChest.MOD_ID + ":silver_chest";
|
||||
|
||||
public static final String CRYSTAL_CHEST = IronChest.MOD_ID + ":crystal_chest";
|
||||
|
||||
public static final String OBSIDIAN_CHEST = IronChest.MOD_ID + ":obsidian_chest";
|
||||
|
||||
public static final String DIRT_CHEST = IronChest.MOD_ID + ":dirt_chest";
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.util;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
|
||||
public class ItemNames
|
||||
{
|
||||
public static final String IRON_GOLD_UPGRADE = IronChest.MOD_ID + ":iron_gold_chest_upgrade";
|
||||
|
||||
public static final String GOLD_DIAMOND_UPGRADE = IronChest.MOD_ID + ":gold_diamond_chest_upgrade";
|
||||
|
||||
public static final String COPPER_SILVER_UPGRADE = IronChest.MOD_ID + ":copper_silver_chest_upgrade";
|
||||
|
||||
public static final String SILVER_GOLD_UPGRADE = IronChest.MOD_ID + ":silver_gold_chest_upgrade";
|
||||
|
||||
public static final String COPPER_IRON_UPGRADE = IronChest.MOD_ID + ":copper_iron_chest_upgrade";
|
||||
|
||||
public static final String DIAMOND_CRYSTAL_UPGRADE = IronChest.MOD_ID + ":diamond_crystal_chest_upgrade";
|
||||
|
||||
public static final String WOOD_IRON_UPGRADE = IronChest.MOD_ID + ":wood_iron_chest_upgrade";
|
||||
|
||||
public static final String WOOD_COPPER_UPGRADE = IronChest.MOD_ID + ":wood_copper_chest_upgrade";
|
||||
|
||||
public static final String DIAMOND_OBSIDIAN_UPGRADE = IronChest.MOD_ID + ":diamond_obsidian_chest_upgrade";
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2012 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
* <p>
|
||||
* Contributors:
|
||||
* cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package com.progwml6.ironchest.common.util;
|
||||
|
||||
import com.progwml6.ironchest.IronChest;
|
||||
|
||||
public class TileEntityNames
|
||||
{
|
||||
public static final String IRON_CHEST = IronChest.MOD_ID + ":iron_chest";
|
||||
|
||||
public static final String GOLD_CHEST = IronChest.MOD_ID + ":gold_chest";
|
||||
|
||||
public static final String DIAMOND_CHEST = IronChest.MOD_ID + ":diamond_chest";
|
||||
|
||||
public static final String COPPER_CHEST = IronChest.MOD_ID + ":copper_chest";
|
||||
|
||||
public static final String SILVER_CHEST = IronChest.MOD_ID + ":silver_chest";
|
||||
|
||||
public static final String CRYSTAL_CHEST = IronChest.MOD_ID + ":crystal_chest";
|
||||
|
||||
public static final String OBSIDIAN_CHEST = IronChest.MOD_ID + ":obsidian_chest";
|
||||
|
||||
public static final String DIRT_CHEST = IronChest.MOD_ID + ":dirt_chest";
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"pack": {
|
||||
"description": "Iron Chests Resources",
|
||||
"pack_format": 4,
|
||||
"_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods."
|
||||
"pack_format": 5,
|
||||
"_comment": "A pack_format of 5 requires json lang files. Note: we require v5 pack meta for all mods."
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue