Dispenser Loot

- Added loot tables for Dispensers
 - Added block counters for dispensers and valuable blocks to SchematicConverter
This commit is contained in:
Robijnvogel 2018-01-19 20:19:42 +01:00
parent f4131ac34e
commit f7f1bab5fc
6 changed files with 172 additions and 33 deletions

View file

@ -3,7 +3,6 @@ package org.dimdev.dimdoors.shared;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.client.IRenderHandler;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.shared.blocks.ModBlocks;
import org.dimdev.dimdoors.shared.entities.EntityMonolith;
@ -60,6 +59,8 @@ public abstract class CommonProxy {
public void onInitialization(FMLInitializationEvent event) {
SchematicHandler.INSTANCE.loadSchematics();
LootTableList.register(new ResourceLocation(DimDoors.MODID, "dungeon_chest"));
LootTableList.register(new ResourceLocation(DimDoors.MODID, "dispenser_projectiles"));
LootTableList.register(new ResourceLocation(DimDoors.MODID, "dispenser_fire"));
}
public void registerTileEntities() {

View file

@ -12,9 +12,14 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.minecraft.block.BlockDispenser;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
@ -75,6 +80,25 @@ public class PocketTemplate {
LootContext ctx = new LootContext.Builder(world).build();
table.fillInventory(chest, world.rand, ctx);
DimDoors.log.info("Chest should be populated now. Chest is: " + (chest.isEmpty() ? "emtpy." : "filled."));
} else if (tile instanceof TileEntityDispenser) {
DimDoors.log.info("Now populating dispenser.");
TileEntityDispenser dispenser = (TileEntityDispenser) tile;
IBlockState blockState = world.getBlockState(pos);
if (!blockState.getBlock().equals(Blocks.DISPENSER)) {
DimDoors.log.error("Wanted to place a TileEntityDispenser at a position, after generating a schematic, but the block doesn't seem to be a dispenser. Something is terribly wrong!");
} else {
LootTable table;
IBlockState fireState1 = Blocks.DISPENSER.getDefaultState().withProperty(BlockDispenser.FACING, EnumFacing.DOWN).withProperty(BlockDispenser.TRIGGERED, false);
IBlockState fireState2 = Blocks.DISPENSER.getDefaultState().withProperty(BlockDispenser.FACING, EnumFacing.DOWN).withProperty(BlockDispenser.TRIGGERED, true);
if (blockState.equals(fireState1) || blockState.equals(fireState2)) {
table = world.getLootTableManager().getLootTableFromLocation(new ResourceLocation(DimDoors.MODID + ":dispenser_fire"));
} else {
table = world.getLootTableManager().getLootTableFromLocation(new ResourceLocation(DimDoors.MODID + ":dispenser_projectiles"));
}
LootContext ctx = new LootContext.Builder(world).build();
table.fillInventory(dispenser, world.rand, ctx);
}
DimDoors.log.info("Dispenser should be populated now. Dispenser is: " + (dispenser.isEmpty() ? "emtpy." : "filled."));
}
}
}

View file

@ -35,7 +35,7 @@ public final class SchematicConverter {
schematic.version = 1; //already the default value
schematic.author = author;
schematic.name = name;
schematic.name = name; // TODO: this is still null at the moment
schematic.creationDate = System.currentTimeMillis();
schematic.requiredMods = new String[]{DimDoors.MODID};
@ -50,6 +50,10 @@ public final class SchematicConverter {
int sandstoneDoors = 0;
int monoliths = 0;
int chests = 0;
int dispensers = 0;
int diamondBlocks = 0;
int goldBlocks = 0;
int ironBlocks = 0;
byte[] blockIdArray = nbt.getByteArray("Blocks");
byte[] addId = nbt.getByteArray("AddBlocks");
@ -92,8 +96,12 @@ public final class SchematicConverter {
if (id != 0 && block.getBlock().getRegistryName().toString().equals("minecraft:air")) {
throw new RuntimeException("Unknown ID " + id + " in schematic " + schematicId);
}
if (block.equals(Blocks.IRON_DOOR)) block = ModBlocks.DIMENSIONAL_DOOR.getDefaultState();
if (block.equals(Blocks.OAK_DOOR)) block = ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState();
if (block.equals(Blocks.IRON_DOOR)) {
block = ModBlocks.DIMENSIONAL_DOOR.getDefaultState();
}
if (block.equals(Blocks.OAK_DOOR)) {
block = ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState();
}
schematic.pallette.add(block);
palletteMap.put(id, currentPalletteIndex);
blockIdArray[i] = currentPalletteIndex;
@ -107,7 +115,9 @@ public final class SchematicConverter {
switch (tileEntityNBT.getString("id")) {
case "TileEntityDimDoor":
case "TileEntityRift":
continue;
case "TileEntityChest":
case "TileEntityDispenser":
continue; // remove all Rifts and containers from the TileEntities. These will get added back later
case "Sign":
tileEntityNBT.setString("Text1", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text1"))));
tileEntityNBT.setString("Text2", ITextComponent.Serializer.componentToJson(new TextComponentString(tileEntityNBT.getString("Text2"))));
@ -144,20 +154,43 @@ public final class SchematicConverter {
//DimDoors.log.info("New blockstate detected. Original blockInt = " + blockInt + " and blockState is " + blockState);
blockInt = schematic.pallette.size() - 1;
}
if (blockState.getBlock().equals(Blocks.CHEST)) chests++;
if (blockState.getBlock().equals(ModBlocks.DIMENSIONAL_DOOR) || blockState.getBlock().equals(ModBlocks.WARP_DIMENSIONAL_DOOR) || blockState.getBlock().equals(ModBlocks.DIMENSIONAL_PORTAL)) {
//DimDoors.log.info("Door found: " + blockState.getBlock().getUnlocalizedName());
Block block = blockState.getBlock();
if (block.equals(Blocks.DIAMOND_BLOCK)) {
diamondBlocks++;
} else if (block.equals(Blocks.GOLD_BLOCK)) {
goldBlocks++;
} else if (block.equals(Blocks.IRON_BLOCK)) {
ironBlocks++;
} else if (block.equals(Blocks.CHEST)) {
chests++;
TileEntityChest chest = new TileEntityChest();
chest.setPos(new BlockPos(x, y, z));
schematic.tileEntities.add(chest.serializeNBT());
} else if (block.equals(Blocks.DISPENSER)) {
dispensers++;
// TODO: Are some dispensers achtually already pre-filled? And if so, what should I actually be doing here?
TileEntityDispenser dispenser = new TileEntityDispenser();
dispenser.setPos(new BlockPos(x, y, z));
schematic.tileEntities.add(dispenser.serializeNBT());
} else if (block.equals(Blocks.END_PORTAL_FRAME)) {
monoliths++;
// I think it's safe to assume that air is present
blockInt = schematic.pallette.indexOf(Blocks.AIR.getDefaultState());
EntityMonolith monolith = new EntityMonolith(null);
EnumFacing facing = blockState.getValue(BlockEndPortalFrame.FACING);
monolith.setLocationAndAngles(x + 0.5d, y, z + 0.5d, facing.getHorizontalAngle(), 0);
schematic.entities.add(monolith.serializeNBT());
} else if (block.equals(ModBlocks.DIMENSIONAL_DOOR) || block.equals(ModBlocks.WARP_DIMENSIONAL_DOOR) || block.equals(ModBlocks.DIMENSIONAL_PORTAL)) {
//DimDoors.log.info("Door found: " + block.getUnlocalizedName());
if (blockState.getProperties().get(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.LOWER)) {
TileEntityEntranceRift rift = (TileEntityEntranceRift) blockState.getBlock().createTileEntity(null, blockState);
TileEntityEntranceRift rift = (TileEntityEntranceRift) block.createTileEntity(null, blockState);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.linksRemaining(1).build());
if (blockState.getBlock().equals(ModBlocks.DIMENSIONAL_DOOR)) {
if (block.equals(ModBlocks.DIMENSIONAL_DOOR)) {
ironDoors++;
rift.setDestination(AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0))
@ -166,7 +199,7 @@ public final class SchematicConverter {
.positiveDepthFactor(80)
.weightMaximum(100)
.newRiftWeight(1).build());
} else if (blockState.getBlock().equals(ModBlocks.WARP_DIMENSIONAL_DOOR)) {
} else if (block.equals(ModBlocks.WARP_DIMENSIONAL_DOOR)) {
IBlockState stateBelow = schematic.pallette.get(schematic.blockData[x][y - 1][z]);
if (stateBelow.getBlock().equals(Blocks.SANDSTONE)) {
sandstoneDoors++;
@ -197,7 +230,7 @@ public final class SchematicConverter {
.weightMaximum(100)
.newRiftWeight(1).build()).build());
}
} else if (blockState.getBlock().equals(ModBlocks.DIMENSIONAL_PORTAL)) {
} else if (block.equals(ModBlocks.DIMENSIONAL_PORTAL)) {
rift.setProperties(LinkProperties.builder()
.groups(new HashSet<>(Arrays.asList(0, 1)))
.entranceWeight(50)
@ -215,16 +248,6 @@ public final class SchematicConverter {
schematic.tileEntities.add(rift.serializeNBT());
}
}
if (blockState.getBlock().equals(Blocks.END_PORTAL_FRAME)) {
monoliths++;
// I think it's safe to assume that air is present
blockInt = schematic.pallette.indexOf(Blocks.AIR.getDefaultState());
EntityMonolith monolith = new EntityMonolith(null);
EnumFacing facing = blockState.getValue(BlockEndPortalFrame.FACING);
monolith.setLocationAndAngles(x + 0.5d, y, z + 0.5d, facing.getHorizontalAngle(), 0);
schematic.entities.add(monolith.serializeNBT());
}
} else { // if this is ancient fabric
blockInt = schematic.pallette.indexOf(baseState);
}
@ -233,11 +256,13 @@ public final class SchematicConverter {
}
}
}
if (!nbt.getTag("Entities").hasNoTags())
if (!nbt.getTag("Entities").hasNoTags()) {
throw new RuntimeException("Schematic contains entities, but those aren't implemented in the conversion code");
}
schematic.paletteMax = schematic.pallette.size() - 1;
DimDoors.log.info(schematicId + "," + schematic.name + "," + ironDoors + "," + woodDoors + "," + sandstoneDoors + "," + monoliths + "," + chests);
DimDoors.log.info(schematicId + "," + ironDoors + "," + woodDoors + "," + sandstoneDoors + "," + monoliths + "," +
chests + "," + dispensers + "," + diamondBlocks + "," + goldBlocks + "," + ironBlocks);
return schematic;
}

View file

@ -0,0 +1,24 @@
{
"pools": [
{
"name": "default",
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:fire_charge",
"functions": [
{
"function": "set_count",
"count": {
"min": 2,
"max": 5
}
}
],
"weight": 1
}
]
}
]
}

View file

@ -0,0 +1,65 @@
{
"pools": [
{
"name": "default",
"rolls": {
"min": 2,
"max": 3
},
"entries": [
{
"type": "item",
"name": "minecraft:arrow",
"functions": [
{
"function": "set_count",
"count": {
"min": 2,
"max": 5
}
}
],
"weight": 100
},
{
"type": "item",
"name": "minecraft:fire_charge",
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 3
}
}
],
"weight": 15
},
{
"type": "item",
"name": "minecraft:water_bucket",
"weight": 5
},
{
"type": "item",
"name": "minecraft:lava_bucket",
"weight": 2
},
{
"type": "item",
"name": "minecraft:splash_potion",
"functions": [
{
"function": "set_count",
"count": {
"min": 1,
"max": 2
}
}
],
"weight": 15
}
]
}
]
}