Skip to content

Commit

Permalink
Ported to 1.16.2
Browse files Browse the repository at this point in the history
Refactored everything from CCA to custom elements.
  • Loading branch information
Redblueflame committed Aug 21, 2020
1 parent 9bbf6cb commit 5dd45de
Show file tree
Hide file tree
Showing 34 changed files with 328 additions and 154 deletions.
28 changes: 21 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,34 @@ dependencies {
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
testImplementation 'com.google.code.findbugs:jsr305:3.0.2'
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modCompile "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:2.4.0"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:2.4.0"

modCompile "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:2.5.1"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:2.5.1"
// Adds an implementation dependency on the entity module

/*
modCompile "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:2.4.0"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:2.4.0"
modCompile "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-item:2.4.0"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-item:2.4.0"
modCompile "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-block:2.4.0"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-block:2.4.0"
modCompile "com.github.vini2003:spinnery:${project.spinnery_version}"
include "com.github.vini2003:spinnery:${project.spinnery_version}"
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
include "io.github.prospector:modmenu:${project.modmenu_version}"
modImplementation "vazkii.patchouli:Patchouli_1.16-fabric:${project.patchouli_version}"
*/
modCompile("com.github.vini2003:spinnery:${project.spinnery_version}"){
exclude module:"fabric-api"
}
include("com.github.vini2003:spinnery:${project.spinnery_version}"){
exclude module:"fabric-api"
}
modImplementation("io.github.prospector:modmenu:${project.modmenu_version}"){
exclude module:"fabric-api"
}
include("io.github.prospector:modmenu:${project.modmenu_version}"){
exclude module:"fabric-api"
}
modImplementation("vazkii.patchouli:Patchouli:${project.patchouli_version}"){
exclude module:"fabric-api"
}
//modRuntime ("com.github.Chocohead:Data-Breaker-Lower:24be1a2")

/* this will expose the dependency to anyone building against your mod. You might
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.1
yarn_mappings=1.16.1+build.5
loader_version=0.8.8+build.202
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.21
loader_version=0.9.2+build.206
# Mod Properties
mod_version=1.0-SNAPSHOT
maven_group=com.redblueflame
archives_base_name=herbocraft
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.13.1+build.370-1.16
spinnery_version=3.0.39+fabric-1.16.x
modmenu_version = 1.12.1+build.15
patchouli_version = 1.16-37.15-FABRIC
fabric_version=0.19.0+build.398-1.16
spinnery_version=3.1.15+fabric-1.16.x
modmenu_version = 1.14.6+build.31
patchouli_version = 1.16-40-FABRIC
30 changes: 10 additions & 20 deletions src/main/java/com/redblueflame/herbocraft/HerboCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.gson.JsonSyntaxException;
import com.redblueflame.herbocraft.blocks.*;
import com.redblueflame.herbocraft.components.LevelComponent;
import com.redblueflame.herbocraft.components.TurretLevelComponent;
import com.redblueflame.herbocraft.entities.BulletEntity;
import com.redblueflame.herbocraft.entities.SnowTurretEntity;
import com.redblueflame.herbocraft.entities.TurretBaseEntity;
Expand All @@ -18,17 +17,15 @@
import io.netty.buffer.Unpooled;
import nerdhub.cardinal.components.api.ComponentRegistry;
import nerdhub.cardinal.components.api.ComponentType;
import nerdhub.cardinal.components.api.event.EntityComponentCallback;
import nerdhub.cardinal.components.api.event.ItemComponentCallback;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.fabric.api.server.PlayerStream;
import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.block.*;
Expand All @@ -39,8 +36,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -137,6 +132,7 @@ public class HerboCraft implements ModInitializer {
//endregion

//region Components
@Deprecated
public static final ComponentType<LevelComponent> LEVELLING =
ComponentRegistry.INSTANCE.registerIfAbsent(new Identifier(name, "levelling"), LevelComponent.class);
//endregion
Expand Down Expand Up @@ -217,14 +213,14 @@ public void onInitialize() {
UPGRADER_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(name, "upgrader"), BlockEntityType.Builder.create(UpgraderBlockEntity::new, UPGRADER).build(null));

// Register containers
ContainerProviderRegistry.INSTANCE.registerFactory(STERILIZER_CONTAINER,
(syncId, id, player, buf) -> new SterilizerBlockContainer(syncId, buf.readText(), player.inventory, buf.readBlockPos(), player.world));
ContainerProviderRegistry.INSTANCE.registerFactory(GROWTH_CONTROLLER_CONTAINER,
(syncId, id, player, buf) -> new GrowthControllerContainer(syncId, buf.readText(), player.inventory, buf.readBlockPos(), player.world));
ContainerProviderRegistry.INSTANCE.registerFactory(REPRODUCER_CONTAINER,
(syncId, id, player, buf) -> new ReproducerBlockContainer(syncId, buf.readText(), player.inventory, buf.readBlockPos(), player.world));
ContainerProviderRegistry.INSTANCE.registerFactory(UPGRADER_CONTAINER,
(syncId, id, player, buf) -> new UpgraderBlockContainer(syncId, buf.readText(), player.inventory, buf.readBlockPos(), player.world));
ScreenHandlerRegistry.registerExtended(STERILIZER_CONTAINER,
(id, inv, buf) -> new SterilizerBlockContainer(id, buf.readText(), inv, buf.readBlockPos(), inv.player.world));
ScreenHandlerRegistry.registerExtended(GROWTH_CONTROLLER_CONTAINER,
(syncId, inv, buf) -> new GrowthControllerContainer(syncId, buf.readText(), inv, buf.readBlockPos(), inv.player.world));
ScreenHandlerRegistry.registerExtended(REPRODUCER_CONTAINER,
(syncId, inv, buf) -> new ReproducerBlockContainer(syncId, buf.readText(), inv, buf.readBlockPos(), inv.player.world));
ScreenHandlerRegistry.registerExtended(UPGRADER_CONTAINER,
(syncId, inv, buf) -> new UpgraderBlockContainer(syncId, buf.readText(), inv, buf.readBlockPos(), inv.player.world));
// Register recipes
Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(name, "patchouli_book"), new PatchouliBookRecipe.Serializer());

Expand Down Expand Up @@ -258,12 +254,6 @@ public void onInitialize() {
});
});
//endregion
// Register turret Levelling system
EntityComponentCallback.event(TurretBaseEntity.class).register(TurretBaseEntity::initComponents);

ItemComponentCallback.event(TURRET_SEED).register((stack, components) -> components.put(LEVELLING, TurretLevelComponent.getRandomStats((short) 5)));
ItemComponentCallback.event(WITHER_SEED).register((stack, components) -> components.put(LEVELLING, TurretLevelComponent.getRandomStats((short) 5)));
ItemComponentCallback.event(SNOW_SEED).register((stack, components) -> components.put(LEVELLING, TurretLevelComponent.getRandomStats((short) 5)));
// Load JSON config files
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new IdentifiableResourceReloadListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ public CompoundTag toTag(CompoundTag tag) {
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
inventory = InventoryUtilities.read(tag);
if (inventory == null) {
inventory = new BaseInventory(10);
}
currentItem = inventory.getStack(0).getItem();
if (inventory != null)
currentItem = inventory.getStack(0).getItem();
}

// region Quality types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import spinnery.common.container.BaseContainer;
import spinnery.common.handler.BaseScreenHandler;
import spinnery.common.inventory.BaseInventory;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;

import java.util.Collection;

public class GrowthControllerContainer extends BaseContainer {
public class GrowthControllerContainer extends BaseScreenHandler {
public GrowthControllerBlockEntity entity;
public static final int GROWTH_CONTROLLER_INVENTORY = 1;
public Text name;
Expand All @@ -30,6 +30,9 @@ public GrowthControllerContainer(int synchronizationID, Text name, PlayerInvento

private void initInventory() {
WInterface mainInterface = getInterface();
if (entity.inventory == null) {
entity.inventory = new BaseInventory(10);
}
getInventories().put(GROWTH_CONTROLLER_INVENTORY, entity.inventory);
mainInterface.createChild(WSlot::new);
Collection<WSlot> input = WSlot.addHeadlessArray(mainInterface, 0, GROWTH_CONTROLLER_INVENTORY, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import spinnery.common.container.BaseContainer;
import spinnery.common.handler.BaseScreenHandler;
import spinnery.common.inventory.BaseInventory;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;

import java.util.Collection;

public class ReproducerBlockContainer extends BaseContainer {
public class ReproducerBlockContainer extends BaseScreenHandler {
public ReproducerBlockEntity entity;
public static final int GROWTH_CONTROLLER_INVENTORY = 1;
public Text name;
Expand All @@ -30,6 +30,9 @@ public ReproducerBlockContainer(int synchronizationID, Text name, PlayerInventor

private void initInventory() {
WInterface mainInterface = getInterface();
if (entity.inventory == null) {
entity.inventory = new BaseInventory(11);
}
getInventories().put(GROWTH_CONTROLLER_INVENTORY, entity.inventory);
mainInterface.createChild(WSlot::new);
Collection<WSlot> input = WSlot.addHeadlessArray(mainInterface, 0, GROWTH_CONTROLLER_INVENTORY, 2, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public boolean checkWork() {
@Override
public void finishWork() {
ItemStack item = new ItemStack(currentItem1.getItem(), 1);
LevelComponent item1 = ComponentsHandler.getItemComponent(inventory.getStack(0));
LevelComponent item2 = ComponentsHandler.getItemComponent(inventory.getStack(1));
LevelComponent target = ComponentsHandler.getItemComponent(item);
LevelComponent item1 = ComponentsHandler.getItemComponent(inventory.getStack(0), true);
LevelComponent item2 = ComponentsHandler.getItemComponent(inventory.getStack(1), true);
LevelComponent target = ComponentsHandler.createItemComponent(item);
item1.reproduceWith(item2, target, new Random());
int slot = getFirstAvailableSlot();
if (slot == -1) {
Expand Down Expand Up @@ -92,11 +92,10 @@ public CompoundTag toTag(CompoundTag tag) {
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
inventory = InventoryUtilities.read(tag);
if (inventory == null) {
inventory = new BaseInventory(11);
if (inventory != null) {
currentItem1 = inventory.getStack(0);
currentItem2 = inventory.getStack(1);
}
currentItem1 = inventory.getStack(0);
currentItem2 = inventory.getStack(1);
}

// region Quality types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ public SnowTurretSeedBlock(Settings settings) {
public Entity getEntity(World world, LevelComponent itemComp) {
SnowTurretEntity entity = new SnowTurretEntity(HerboCraft.SNOW_TURRET, world);
// Set the Level Component
Optional<LevelComponent> opt_comp = HerboCraft.LEVELLING.maybeGet(entity);
if (!opt_comp.isPresent()) {
throw new RuntimeException("Seems like the entity isn't compatible with the custom tags. Please check your entry.");
}
LevelComponent entityComp = opt_comp.get();
entityComp.copyFrom(itemComp);
entity.setAttributes(entityComp);
entity.setComponent(itemComp);
entity.setAttributes();
return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import spinnery.common.container.BaseContainer;

import spinnery.common.handler.BaseScreenHandler;
import spinnery.common.inventory.BaseInventory;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;

import java.util.Collection;

public class SterilizerBlockContainer extends BaseContainer {
public class SterilizerBlockContainer extends BaseScreenHandler {
public SterilizerBlockEntity entity;
public static final int STERILIZER_INVENTORY = 1;
public Text name;
Expand All @@ -27,7 +28,9 @@ public SterilizerBlockContainer(int synchronizationID, Text name, PlayerInventor
}
private void initInventory() {
WInterface mainInterface = getInterface();

if (entity.inventory == null) {
entity.inventory = new BaseInventory(1);
}
getInventories().put(STERILIZER_INVENTORY, entity.inventory);
mainInterface.createChild(WSlot::new);
Collection<WSlot> items = WSlot.addHeadlessArray(mainInterface, 0, STERILIZER_INVENTORY, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public boolean checkWork() {
public void finishWork() {
LevelComponent comp = ComponentsHandler.getItemComponent(inventory.getStack(0));
comp.setSterile(true);
ComponentsHandler.saveItemComponent(inventory.getStack(0), comp);
}

@Override
Expand Down Expand Up @@ -83,9 +84,7 @@ public CompoundTag toTag(CompoundTag tag) {
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
inventory = InventoryUtilities.read(tag);
if (inventory == null) {
inventory = new BaseInventory(1);
}
currentItem = inventory.getStack(0);
if (inventory != null)
currentItem = inventory.getStack(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ public TurretSeedBlock(Settings settings) {

public Entity getEntity(World world, LevelComponent itemComp) {
TurretBaseEntity entity = new TurretBaseEntity(HerboCraft.TURRET_BASE, world);
// Set the Level Component
Optional<LevelComponent> opt_comp = HerboCraft.LEVELLING.maybeGet(entity);
if (!opt_comp.isPresent()) {
throw new RuntimeException("Seems like the entity isn't compatible with the custom tags. Please check your entry.");
}
LevelComponent entityComp = opt_comp.get();
entityComp.copyFrom(itemComp);
entity.setAttributes(entityComp);

entity.setComponent(itemComp);
entity.setAttributes();
return entity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TurretSeedBlockEntity extends BlockEntity {
private LevelComponent component;
public TurretSeedBlockEntity() {
super(HerboCraft.TURRET_SEED_BLOCK_ENTITY);
component = new TurretLevelComponent();
component = null;
}
public LevelComponent getComponent() {
return component;
Expand All @@ -30,7 +30,9 @@ public void fromTag(BlockState state, CompoundTag tag) {
@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
component.toTag(tag);
if (component != null) {
component.toTag(tag);
}
return tag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import spinnery.common.container.BaseContainer;
import spinnery.common.handler.BaseScreenHandler;
import spinnery.common.inventory.BaseInventory;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;

import java.util.Collection;

public class UpgraderBlockContainer extends BaseContainer {
public class UpgraderBlockContainer extends BaseScreenHandler {
public UpgraderBlockEntity entity;
public static final int GROWTH_CONTROLLER_INVENTORY = 1;
public Text name;
Expand All @@ -30,7 +30,9 @@ public UpgraderBlockContainer(int synchronizationID, Text name, PlayerInventory

private void initInventory() {
WInterface mainInterface = getInterface();

if (entity.inventory == null) {
entity.inventory = new BaseInventory(20);
}
getInventories().put(GROWTH_CONTROLLER_INVENTORY, entity.inventory);
mainInterface.createChild(WSlot::new);
Collection<WSlot> input = WSlot.addHeadlessArray(mainInterface, 0, GROWTH_CONTROLLER_INVENTORY, 3, 3);
Expand Down
Loading

0 comments on commit 5dd45de

Please sign in to comment.