mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Replace chests in village houses and lush caves with storage crates.
Also closes #382
This commit is contained in:
parent
659d424467
commit
b39ee8228d
4 changed files with 86 additions and 14 deletions
|
@ -83,6 +83,7 @@ public class BlockGiantChest extends BlockContainerBase{
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
TileEntityGiantChest chest = (TileEntityGiantChest)world.getTileEntity(pos);
|
TileEntityGiantChest chest = (TileEntityGiantChest)world.getTileEntity(pos);
|
||||||
if(chest != null){
|
if(chest != null){
|
||||||
|
chest.fillWithLoot(player);
|
||||||
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.GIANT_CHEST.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.GIANT_CHEST.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -10,11 +10,16 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.gen;
|
package de.ellpeck.actuallyadditions.mod.gen;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot;
|
import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChest;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
import net.minecraft.world.gen.structure.StructureBoundingBox;
|
||||||
import net.minecraft.world.gen.structure.StructureComponent;
|
import net.minecraft.world.gen.structure.StructureComponent;
|
||||||
|
@ -184,7 +189,7 @@ public class VillageComponentJamHouse extends StructureVillagePieces.House1{
|
||||||
this.fillWithBlocks(world, sbb, 3, 1, 4, 4, 1, 6, Blocks.CARPET.getStateFromMeta(10), Blocks.CARPET.getStateFromMeta(10), false);
|
this.fillWithBlocks(world, sbb, 3, 1, 4, 4, 1, 6, Blocks.CARPET.getStateFromMeta(10), Blocks.CARPET.getStateFromMeta(10), false);
|
||||||
|
|
||||||
//Loot Chest
|
//Loot Chest
|
||||||
this.generateChest(world, this.boundingBox, rand, 8, 1, 6, DungeonLoot.JAM_HOUSE);
|
this.generateCrate(world, this.boundingBox, 8, 1, 6, DungeonLoot.JAM_HOUSE);
|
||||||
|
|
||||||
//Torches
|
//Torches
|
||||||
this.setBlockState(world, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.SOUTH), 6, 2, 0, sbb);
|
this.setBlockState(world, Blocks.TORCH.getDefaultState().withProperty(BlockTorch.FACING, EnumFacing.SOUTH), 6, 2, 0, sbb);
|
||||||
|
@ -201,4 +206,22 @@ public class VillageComponentJamHouse extends StructureVillagePieces.House1{
|
||||||
protected VillagerProfession chooseForgeProfession(int count, VillagerProfession prof){
|
protected VillagerProfession chooseForgeProfession(int count, VillagerProfession prof){
|
||||||
return InitVillager.jamProfession;
|
return InitVillager.jamProfession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean generateCrate(World world, StructureBoundingBox box, int x, int y, int z, ResourceLocation loot){
|
||||||
|
BlockPos pos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
|
||||||
|
|
||||||
|
if(box.isVecInside(pos) && (world.getBlockState(pos).getBlock() != InitBlocks.blockGiantChest)){
|
||||||
|
world.setBlockState(pos, InitBlocks.blockGiantChest.getDefaultState(), 2);
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
if(tile instanceof TileEntityGiantChest){
|
||||||
|
((TileEntityGiantChest)tile).lootTable = loot;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.gen;
|
package de.ellpeck.actuallyadditions.mod.gen;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot;
|
import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChest;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
@ -70,13 +72,13 @@ public class WorldGenLushCaves{
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!possiblePoses.isEmpty()){
|
if(!possiblePoses.isEmpty()){
|
||||||
boolean chestGenDone = false;
|
boolean crateGenDone = false;
|
||||||
|
|
||||||
for(int i = 0; i <= amount; i++){
|
for(int i = 0; i <= amount; i++){
|
||||||
Collections.shuffle(possiblePoses);
|
Collections.shuffle(possiblePoses);
|
||||||
BlockPos pos = possiblePoses.get(0);
|
BlockPos pos = possiblePoses.get(0);
|
||||||
if(rand.nextBoolean()){
|
if(rand.nextBoolean()){
|
||||||
boolean genChest = false;
|
boolean genCrate = false;
|
||||||
|
|
||||||
WorldGenAbstractTree trees;
|
WorldGenAbstractTree trees;
|
||||||
if(rand.nextBoolean()){
|
if(rand.nextBoolean()){
|
||||||
|
@ -85,7 +87,7 @@ public class WorldGenLushCaves{
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
trees = new WorldGenShrub(Blocks.LOG.getDefaultState(), Blocks.LEAVES.getDefaultState());
|
trees = new WorldGenShrub(Blocks.LOG.getDefaultState(), Blocks.LEAVES.getDefaultState());
|
||||||
genChest = true;
|
genCrate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -93,20 +95,20 @@ public class WorldGenLushCaves{
|
||||||
}
|
}
|
||||||
trees.generate(world, rand, pos.up());
|
trees.generate(world, rand, pos.up());
|
||||||
|
|
||||||
if(!chestGenDone && genChest){
|
if(!crateGenDone && genCrate){
|
||||||
BlockPos chestPos = pos.add(MathHelper.getRandomIntegerInRange(rand, -2, 2), MathHelper.getRandomIntegerInRange(rand, 3, 8), MathHelper.getRandomIntegerInRange(rand, -2, 2));
|
BlockPos cratePos = pos.add(MathHelper.getRandomIntegerInRange(rand, -2, 2), MathHelper.getRandomIntegerInRange(rand, 3, 8), MathHelper.getRandomIntegerInRange(rand, -2, 2));
|
||||||
|
|
||||||
IBlockState state = world.getBlockState(chestPos);
|
IBlockState state = world.getBlockState(cratePos);
|
||||||
if(state != null && state.getBlock().isLeaves(state, world, chestPos)){
|
if(state != null && state.getBlock().isLeaves(state, world, cratePos)){
|
||||||
world.setBlockState(chestPos, Blocks.CHEST.getDefaultState());
|
world.setBlockState(cratePos, InitBlocks.blockGiantChest.getDefaultState());
|
||||||
|
|
||||||
TileEntity chest = world.getTileEntity(chestPos);
|
TileEntity tile = world.getTileEntity(cratePos);
|
||||||
if(chest instanceof TileEntityChest){
|
if(tile instanceof TileEntityGiantChest){
|
||||||
((TileEntityChest)chest).setLootTable(DungeonLoot.LUSH_CAVES, rand.nextLong());
|
((TileEntityGiantChest)tile).lootTable = DungeonLoot.LUSH_CAVES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chestGenDone = true;
|
crateGenDone = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -16,9 +16,19 @@ import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
import net.minecraft.world.storage.loot.ILootContainer;
|
||||||
|
import net.minecraft.world.storage.loot.LootContext;
|
||||||
|
import net.minecraft.world.storage.loot.LootTable;
|
||||||
|
|
||||||
public class TileEntityGiantChest extends TileEntityInventoryBase implements IButtonReactor{
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class TileEntityGiantChest extends TileEntityInventoryBase implements IButtonReactor, ILootContainer{
|
||||||
|
|
||||||
|
public ResourceLocation lootTable;
|
||||||
|
|
||||||
public TileEntityGiantChest(int slotAmount, String name){
|
public TileEntityGiantChest(int slotAmount, String name){
|
||||||
super(slotAmount, name);
|
super(slotAmount, name);
|
||||||
|
@ -28,6 +38,24 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
|
||||||
this(9*13, "giantChest");
|
this(9*13, "giantChest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
|
super.writeSyncableNBT(compound, type);
|
||||||
|
|
||||||
|
if(this.lootTable != null){
|
||||||
|
compound.setString("LootTable", this.lootTable.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
||||||
|
super.readSyncableNBT(compound, type);
|
||||||
|
|
||||||
|
if(compound.hasKey("LootTable")){
|
||||||
|
this.lootTable = new ResourceLocation(compound.getString("LootTable"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
||||||
return this.isItemValidForSlot(slot, stack);
|
return this.isItemValidForSlot(slot, stack);
|
||||||
|
@ -61,4 +89,22 @@ public class TileEntityGiantChest extends TileEntityInventoryBase implements IBu
|
||||||
player.openGui(ActuallyAdditions.instance, type.ordinal(), this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ());
|
player.openGui(ActuallyAdditions.instance, type.ordinal(), this.worldObj, this.pos.getX(), this.pos.getY(), this.pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getLootTable(){
|
||||||
|
return this.lootTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillWithLoot(EntityPlayer player){
|
||||||
|
if(this.lootTable != null && !this.worldObj.isRemote && this.worldObj instanceof WorldServer){
|
||||||
|
LootTable table = this.worldObj.getLootTableManager().getLootTableFromLocation(this.lootTable);
|
||||||
|
this.lootTable = null;
|
||||||
|
|
||||||
|
LootContext.Builder builder = new LootContext.Builder((WorldServer)this.worldObj);
|
||||||
|
if(player != null){
|
||||||
|
builder.withLuck(player.getLuck());
|
||||||
|
}
|
||||||
|
table.fillInventory(this, new Random(), builder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue