/** creates a zonelist component used to save all zones (persist) */ private static void createZoneList() { zonelist = CoreRegistry.get(EntityManager.class).create(); ZoneListComponent zonecomp = new ZoneListComponent(); zonelist.addComponent(zonecomp); zonelist.setPersisted(true); zonelist.saveComponent(zonecomp); }
@ReceiveEvent(components = {FenceGateComponent.class}) public void onActivate(ActivateEvent event, EntityRef entity) { FenceGateComponent fenceGateComponent = entity.getComponent(FenceGateComponent.class); fenceGateComponent.isClosed = !fenceGateComponent.isClosed; entity.saveComponent(fenceGateComponent); BlockComponent blockComp = entity.getComponent(BlockComponent.class); if (blockComp == null) { event.cancel(); return; } Vector3i primePos = new Vector3i(blockComp.getPosition()); Block primeBlock = worldProvider.getBlock(primePos); Block newBlock = null; if (fenceGateComponent.isClosed) { newBlock = BlockManager.getInstance() .getBlockFamily("fences:FenceGateClosed") .getBlockForPlacing(worldProvider, primePos, primeBlock.getDirection(), Side.FRONT); } else { newBlock = BlockManager.getInstance() .getBlockFamily("fences:FenceGateOpen") .getBlockForPlacing(worldProvider, primePos, primeBlock.getDirection(), Side.FRONT); } if (newBlock != null) { blockEntityRegistry.setBlock(primePos, newBlock, primeBlock, entity); } }
/** * adds a new zone to the corresponding zone list * * @param zone the zone to be added */ public static void addZone(Zone zone) { ZoneListComponent zonelistcomp = zonelist.getComponent(ZoneListComponent.class); switch (zone.zonetype) { case Gather: { zonelistcomp.Gatherzones.add(zone); break; } case Work: { zonelistcomp.Workzones.add(zone); break; } case Terraform: { zonelistcomp.Terrazones.add(zone); break; } case Storage: { zonelistcomp.Storagezones.add(zone); break; } case OreonFarm: { zonelistcomp.OreonFarmzones.add(zone); break; } } zonelist.saveComponent(zonelistcomp); }