Skip to content

Commit

Permalink
fix: player starting inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert committed May 10, 2020
1 parent 957b24c commit 1fe1846
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
2 changes: 1 addition & 1 deletion module.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id" : "CoreSampleGameplay",
"version" : "4.0.0",
"version" : "4.0.1",
"isReleaseManaged": true,
"displayName" : "Core Gameplay",
"description" : "Minimal gameplay template. Little content but a few starting items.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,68 @@ public class PlayerStartingInventorySystem extends BaseComponentSystem {
@ReceiveEvent(components = InventoryComponent.class)
public void onPlayerSpawnedEvent(OnPlayerSpawnedEvent event, EntityRef player) {
BlockItemFactory blockFactory = new BlockItemFactory(entityManager);
// Goodie chest
EntityRef chest = blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:chest"));

EntityRef bonusChest = getBonusChest(blockFactory);
EntityRef explosivesChest = getExplosivesChest(blockFactory);
EntityRef improvedToolsChest = getImprovedToolsChest(blockFactory);

inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("CoreAssets:pickaxe"));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("CoreAssets:axe"));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("CoreAssets:shovel"));
inventoryManager.giveItem(player, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Torch"), 99));
inventoryManager.giveItem(player, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreSampleGameplay:companion"), 99));
inventoryManager.giveItem(player, EntityRef.NULL, bonusChest);
inventoryManager.giveItem(player, EntityRef.NULL, improvedToolsChest);
inventoryManager.giveItem(player, EntityRef.NULL, explosivesChest);
}

private EntityRef getImprovedToolsChest(BlockItemFactory blockFactory) {
EntityRef chest = blockFactory.newInstance(blockManager.getBlockFamily("CoreAdvancedAssets:chest"));
chest.addComponent(new InventoryComponent(30));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAssets:pickaxeImproved"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAssets:axeImproved"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAssets:shovelImproved"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAssets:gooeysFist"));
return chest;
}

inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("Core:companion"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Brick:engine:stair"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Tnt"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:fuseShort"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:fuseLong"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:shallowRailgunTool"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:thoroughRailgunTool"));
private EntityRef getExplosivesChest(BlockItemFactory blockFactory) {
EntityRef chest = blockFactory.newInstance(blockManager.getBlockFamily("CoreAdvancedAssets:chest"));
chest.addComponent(new InventoryComponent(30));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAdvancedAssets:Tnt"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:fuseShort"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:fuseLong"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:dynamite"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:dynamiteBundle"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:gun"));
inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("CoreAdvancedAssets:gunImproved"));

inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:railgunTool"));
return chest;
}

inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:mrbarsack"));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Brick"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Ice"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Plank"), 99));
private EntityRef getBonusChest(BlockItemFactory blockFactory) {
EntityRef chest = blockFactory.newInstance(blockManager.getBlockFamily("CoreAdvancedAssets:chest"));
chest.addComponent(new InventoryComponent(30));

EntityRef doorItem = entityManager.create("CoreBlocks:door");
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Brick:engine:stair"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Cobblestone"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Plank"), 99));

inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:lava"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:water"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Ice"), 99));

inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Iris"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Dandelion"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:Tulip"), 99));
inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreAssets:YellowFlower"), 99));

EntityRef doorItem = entityManager.create("CoreAdvancedAssets:door");
ItemComponent doorItemComp = doorItem.getComponent(ItemComponent.class);
doorItemComp.stackCount = 20;
doorItem.saveComponent(doorItemComp);
inventoryManager.giveItem(chest, EntityRef.NULL, doorItem);

// Inner goodie chest
EntityRef innerChest = blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Chest"));
innerChest.addComponent(new InventoryComponent(30));

inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:lava"), 99));
inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:water"), 99));

inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Iris"), 99));
inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Dandelion"), 99));
inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Tulip"), 99));
inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:YellowFlower"), 99));

// Place inner chest into outer chest
inventoryManager.giveItem(chest, EntityRef.NULL, innerChest);

inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:pickaxe"));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:axe"));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:shovel"));
inventoryManager.giveItem(player, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("CoreBlocks:Torch"), 99));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:explodeTool"));
inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:railgunTool"));
inventoryManager.giveItem(player, EntityRef.NULL, chest);
return chest;
}
}

0 comments on commit 1fe1846

Please sign in to comment.