Skip to content

Commit

Permalink
Initial 1.20.1 port
Browse files Browse the repository at this point in the history
TODO: Figure out a better way to manage integration with other add-ons so as not to require just commenting shit out
  • Loading branch information
62832 committed Jul 19, 2023
1 parent 989e568 commit 31380f9
Show file tree
Hide file tree
Showing 35 changed files with 395 additions and 393 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ subprojects {
url = uri("https://modmaven.dev/")
content {
includeGroup("appeng")
includeGroup("mezz.jei")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,39 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;

import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IManagedGridNode;
import appeng.api.util.IOrientable;
import appeng.block.AEBaseBlockItem;
import appeng.block.AEBaseEntityBlock;
import appeng.block.crafting.PushDirection;
import appeng.core.definitions.AEItems;
import appeng.helpers.iface.PatternProviderLogic;
import appeng.helpers.iface.PatternProviderLogicHost;
import appeng.core.localization.Tooltips;
import appeng.helpers.patternprovider.PatternProviderLogic;
import appeng.helpers.patternprovider.PatternProviderLogicHost;
import appeng.menu.implementations.MenuTypeBuilder;
import appeng.menu.implementations.PatternProviderMenu;
import appeng.menu.locator.MenuLocators;
import appeng.util.InteractionUtil;
import appeng.util.Platform;
import appeng.util.inv.AppEngInternalInventory;
import appeng.util.inv.filter.AEItemDefinitionFilter;

import gripe._90.megacells.block.entity.MEGAPatternProviderBlockEntity;
import gripe._90.megacells.definition.MEGATranslations;

public class MEGAPatternProviderBlock extends AEBaseEntityBlock<MEGAPatternProviderBlockEntity> {
public static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.create("omnidirectional");
public static final EnumProperty<PushDirection> PUSH_DIRECTION = EnumProperty.create("push_direction",
PushDirection.class);

public static final MenuType<Menu> MENU = MenuTypeBuilder
.create(Menu::new, PatternProviderLogicHost.class)
.requirePermission(SecurityPermissions.BUILD)
.build("mega_pattern_provider");

public MEGAPatternProviderBlock(Properties props) {
super(props);
registerDefaultState(defaultBlockState().setValue(OMNIDIRECTIONAL, true));
registerDefaultState(defaultBlockState().setValue(PUSH_DIRECTION, PushDirection.ALL));
}

public static PatternProviderLogic createLogic(IManagedGridNode mainNode, PatternProviderLogicHost host) {
Expand All @@ -61,12 +63,7 @@ public static PatternProviderLogic createLogic(IManagedGridNode mainNode, Patter
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(OMNIDIRECTIONAL);
}

@Override
protected BlockState updateBlockStateFromBlockEntity(BlockState currentState, MEGAPatternProviderBlockEntity be) {
return currentState.setValue(OMNIDIRECTIONAL, be.isOmniDirectional());
builder.add(PUSH_DIRECTION);
}

@Override
Expand All @@ -86,6 +83,11 @@ public InteractionResult onActivated(Level level, BlockPos pos, Player p,
return InteractionResult.PASS;
}

if (heldItem != null && InteractionUtil.canWrenchRotate(heldItem)) {
setSide(level, pos, hit.getDirection());
return InteractionResult.sidedSuccess(level.isClientSide());
}

var be = this.getBlockEntity(level, pos);

if (be != null) {
Expand All @@ -99,16 +101,22 @@ public InteractionResult onActivated(Level level, BlockPos pos, Player p,
return InteractionResult.PASS;
}

@Override
protected boolean hasCustomRotation() {
return true;
}

@Override
protected void customRotateBlock(IOrientable rotatable, Direction axis) {
if (rotatable instanceof MEGAPatternProviderBlockEntity patternProvider) {
patternProvider.setSide(axis);
public void setSide(Level level, BlockPos pos, Direction facing) {
var currentState = level.getBlockState(pos);
var pushSide = currentState.getValue(PUSH_DIRECTION).getDirection();

PushDirection newPushDirection;
if (pushSide == facing.getOpposite()) {
newPushDirection = PushDirection.fromDirection(facing);
} else if (pushSide == facing) {
newPushDirection = PushDirection.ALL;
} else if (pushSide == null) {
newPushDirection = PushDirection.fromDirection(facing.getOpposite());
} else {
newPushDirection = PushDirection.fromDirection(Platform.rotateAround(pushSide, facing));
}

level.setBlockAndUpdate(pos, currentState.setValue(PUSH_DIRECTION, newPushDirection));
}

public static class Item extends AEBaseBlockItem {
Expand All @@ -117,8 +125,8 @@ public Item(Block id, Properties props) {
}

@Override
public void addCheckedInformation(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(MEGATranslations.ProcessingOnly.text());
public void addCheckedInformation(ItemStack stack, Level level, List<Component> lines, TooltipFlag flag) {
lines.add(Tooltips.of(MEGATranslations.ProcessingOnly.text()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import appeng.api.stacks.AEItemKey;
import appeng.blockentity.crafting.PatternProviderBlockEntity;
import appeng.helpers.iface.PatternProviderLogic;
import appeng.helpers.patternprovider.PatternProviderLogic;
import appeng.menu.ISubMenu;
import appeng.menu.MenuOpener;
import appeng.menu.locator.MenuLocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import java.util.Objects;

import net.minecraft.core.NonNullList;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import appeng.api.crafting.IPatternDetails;
Expand Down Expand Up @@ -85,10 +82,5 @@ public static class Item extends AEBaseItem {
public Item(Properties properties) {
super(properties);
}

@Override
public void fillItemCategory(CreativeModeTab tab, NonNullList<ItemStack> list) {
// Don't show in creative mode, this isn't meant to be used as an item anyway
}
}
}
26 changes: 14 additions & 12 deletions common/src/main/java/gripe/_90/megacells/definition/MEGABlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MapColor;

import appeng.block.AEBaseBlock;
import appeng.block.AEBaseBlockItem;
Expand Down Expand Up @@ -41,21 +41,23 @@ public static List<BlockDefinition<?>> getBlocks() {
return Collections.unmodifiableList(BLOCKS);
}

private static final BlockBehaviour.Properties props = BlockBehaviour.Properties.of(Material.METAL)
private static final BlockBehaviour.Properties props = BlockBehaviour.Properties.of()
.strength(2.2f, 11.0f)
.sound(SoundType.METAL);
.mapColor(MapColor.METAL)
.sound(SoundType.METAL)
.forceSolidOn();

// spotless:off
public static final BlockDefinition<EnergyCellBlock> MEGA_ENERGY_CELL = block("Superdense Energy Cell", "mega_energy_cell", () -> new EnergyCellBlock(12800000, 3200, 12800), EnergyCellBlockItem::new);

public static final BlockDefinition<CraftingUnitBlock> MEGA_CRAFTING_UNIT = block("MEGA Crafting Unit", "mega_crafting_unit", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.UNIT), null);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_ACCELERATOR = craftingBlock("MEGA Crafting Co-Processing Unit", "mega_crafting_accelerator", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.ACCELERATOR), () -> AEItems.ENGINEERING_PROCESSOR);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_1M = craftingBlock("1M MEGA Crafting Storage", "1m_crafting_storage", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.STORAGE_1M), () -> MEGAItems.CELL_COMPONENT_1M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_4M = craftingBlock("4M MEGA Crafting Storage", "4m_crafting_storage", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.STORAGE_4M), () -> MEGAItems.CELL_COMPONENT_4M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_16M = craftingBlock("16M MEGA Crafting Storage", "16m_crafting_storage", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.STORAGE_16M), () -> MEGAItems.CELL_COMPONENT_16M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_64M = craftingBlock("64M MEGA Crafting Storage", "64m_crafting_storage", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.STORAGE_64M), () -> MEGAItems.CELL_COMPONENT_64M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_256M = craftingBlock("256M MEGA Crafting Storage", "256m_crafting_storage", () -> new CraftingUnitBlock(props, MEGACraftingUnitType.STORAGE_256M), () -> MEGAItems.CELL_COMPONENT_256M);
public static final BlockDefinition<CraftingMonitorBlock> CRAFTING_MONITOR = craftingBlock("MEGA Crafting Monitor", "mega_crafting_monitor", () -> new CraftingMonitorBlock(props, MEGACraftingUnitType.MONITOR), () -> AEParts.STORAGE_MONITOR);
public static final BlockDefinition<CraftingUnitBlock> MEGA_CRAFTING_UNIT = block("MEGA Crafting Unit", "mega_crafting_unit", () -> new CraftingUnitBlock(MEGACraftingUnitType.UNIT), null);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_ACCELERATOR = craftingBlock("MEGA Crafting Co-Processing Unit", "mega_crafting_accelerator", () -> new CraftingUnitBlock(MEGACraftingUnitType.ACCELERATOR), () -> AEItems.ENGINEERING_PROCESSOR);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_1M = craftingBlock("1M MEGA Crafting Storage", "1m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_1M), () -> MEGAItems.CELL_COMPONENT_1M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_4M = craftingBlock("4M MEGA Crafting Storage", "4m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_4M), () -> MEGAItems.CELL_COMPONENT_4M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_16M = craftingBlock("16M MEGA Crafting Storage", "16m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_16M), () -> MEGAItems.CELL_COMPONENT_16M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_64M = craftingBlock("64M MEGA Crafting Storage", "64m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_64M), () -> MEGAItems.CELL_COMPONENT_64M);
public static final BlockDefinition<CraftingUnitBlock> CRAFTING_STORAGE_256M = craftingBlock("256M MEGA Crafting Storage", "256m_crafting_storage", () -> new CraftingUnitBlock(MEGACraftingUnitType.STORAGE_256M), () -> MEGAItems.CELL_COMPONENT_256M);
public static final BlockDefinition<CraftingMonitorBlock> CRAFTING_MONITOR = craftingBlock("MEGA Crafting Monitor", "mega_crafting_monitor", () -> new CraftingMonitorBlock(MEGACraftingUnitType.MONITOR), () -> AEParts.STORAGE_MONITOR);

public static final BlockDefinition<MEGAPatternProviderBlock> MEGA_PATTERN_PROVIDER = block("MEGA Pattern Provider", "mega_pattern_provider", () -> new MEGAPatternProviderBlock(props), MEGAPatternProviderBlock.Item::new);
// spotless:on
Expand All @@ -73,7 +75,7 @@ private static <T extends Block> BlockDefinition<T> block(String englishName, St
// Create block and matching item
T block = blockSupplier.get();

Item.Properties itemProperties = new Item.Properties().tab(MEGAItems.CREATIVE_TAB);
var itemProperties = new Item.Properties();

BlockItem item;
if (itemFactory != null) {
Expand Down
14 changes: 10 additions & 4 deletions common/src/main/java/gripe/_90/megacells/definition/MEGAItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;
import java.util.function.Function;

import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;

Expand Down Expand Up @@ -35,9 +38,11 @@ public static List<ItemDefinition<?>> getItems() {
return Collections.unmodifiableList(ITEMS);
}

// spotless:off
public static final CreativeModeTab CREATIVE_TAB = Utils.PLATFORM.getCreativeTab();
public static final ResourceLocation CREATIVE_TAB_ID = Utils.makeId("tab");
public static final ResourceKey<CreativeModeTab> CREATIVE_TAB_KEY = ResourceKey.create(Registries.CREATIVE_MODE_TAB, CREATIVE_TAB_ID);

// spotless:off
public static final ItemDefinition<MaterialItem> MEGA_ITEM_CELL_HOUSING = item("MEGA Item Cell Housing", "mega_item_cell_housing", MaterialItem::new);
public static final ItemDefinition<MaterialItem> MEGA_FLUID_CELL_HOUSING = item("MEGA Fluid Cell Housing", "mega_fluid_cell_housing", MaterialItem::new);

Expand Down Expand Up @@ -130,18 +135,19 @@ public static ItemDefinition<BasicStorageCell> fluidCell(StorageTier tier) {

public static ItemDefinition<MEGAPortableCell> itemPortable(StorageTier tier) {
return item(tier.namePrefix().toUpperCase() + " Portable Item Cell", "portable_item_cell_" + tier.namePrefix(),
p -> new MEGAPortableCell(p, tier, AEKeyType.items(), MEStorageMenu.PORTABLE_ITEM_CELL_TYPE));
p -> new MEGAPortableCell(p, tier, AEKeyType.items(), MEStorageMenu.PORTABLE_ITEM_CELL_TYPE, 0x353535));
}

public static ItemDefinition<MEGAPortableCell> fluidPortable(StorageTier tier) {
return item(tier.namePrefix().toUpperCase() + " Portable Fluid Cell",
"portable_fluid_cell_" + tier.namePrefix(),
p -> new MEGAPortableCell(p, tier, AEKeyType.fluids(), MEStorageMenu.PORTABLE_FLUID_CELL_TYPE));
p -> new MEGAPortableCell(p, tier, AEKeyType.fluids(), MEStorageMenu.PORTABLE_FLUID_CELL_TYPE,
0x00F1C5));
}

public static <T extends Item> ItemDefinition<T> item(String englishName, String id,
Function<Item.Properties, T> factory) {
Item.Properties p = new Item.Properties().tab(CREATIVE_TAB);
Item.Properties p = new Item.Properties();
T item = factory.apply(p);

ItemDefinition<T> definition = new ItemDefinition<>(englishName, Utils.makeId(id), item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gripe._90.megacells.definition;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
Expand All @@ -9,6 +9,6 @@ public final class MEGATags {
public static final TagKey<Item> MEGA_PATTERN_PROVIDER = itemTag("megacells:mega_pattern_provider");

private static TagKey<Item> itemTag(String name) {
return TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(name));
return TagKey.create(Registries.ITEM, new ResourceLocation(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum MEGATranslations implements LocalizationEnum {
ALot("A lot.", Type.TOOLTIP),
Compression("Compression: %s", Type.TOOLTIP),
Contains("Contains: %s", Type.TOOLTIP),
CreativeTab("MEGA Cells", Type.GUI),
Disabled("Disabled", Type.TOOLTIP),
Empty("Empty", Type.TOOLTIP),
Enabled("Enabled", Type.TOOLTIP),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import appeng.api.storage.StorageCells;

import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.appbot.AppBotItems;
import gripe._90.megacells.item.MEGABulkCell;
import gripe._90.megacells.util.Utils;

Expand All @@ -21,9 +20,10 @@ public static void init() {
StorageCells.addCellHandler(MEGABulkCell.HANDLER);
StorageCellModels.registerModel(MEGAItems.BULK_ITEM_CELL, Utils.makeId("block/drive/cells/bulk_item_cell"));

if (Utils.PLATFORM.isModLoaded("appbot")) {
Stream.of(AppBotItems.getCells(), AppBotItems.getPortables()).flatMap(Collection::stream)
.forEach(c -> StorageCellModels.registerModel(c, Utils.makeId("block/drive/cells/mega_mana_cell")));
}
/*
* if (Utils.PLATFORM.isModLoaded("appbot")) { Stream.of(AppBotItems.getCells(),
* AppBotItems.getPortables()).flatMap(Collection::stream) .forEach(c -> StorageCellModels.registerModel(c,
* Utils.makeId("block/drive/cells/mega_mana_cell"))); }
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.integration.ae2wt.AE2WTIntegration;
import gripe._90.megacells.integration.appbot.AppBotIntegration;
import gripe._90.megacells.util.Utils;

public class InitUpgrades {
Expand Down Expand Up @@ -64,8 +63,8 @@ public static void init() {
AE2WTIntegration.initUpgrades();
}

if (Utils.PLATFORM.isModLoaded("appbot")) {
AppBotIntegration.initUpgrades();
}
/*
* if (Utils.PLATFORM.isModLoaded("appbot")) { AppBotIntegration.initUpgrades(); }
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
public class MEGAPortableCell extends PortableCellItem {
private final StorageTier tier;

public MEGAPortableCell(Properties props, StorageTier tier, AEKeyType keyType, MenuType<MEStorageMenu> menu) {
super(keyType, menu, tier, props.stacksTo(1));
public MEGAPortableCell(Properties props, StorageTier tier, AEKeyType keyType, MenuType<MEStorageMenu> menu,
int defaultColour) {
super(keyType, 18 + tier.index() * 9, menu, tier, props.stacksTo(1), defaultColour);
this.tier = tier;
}

@Override
public int getTotalTypes(ItemStack cellItem) {
return 18 + this.tier.index() * 9;
}

@Override
public double getIdleDrain() {
return 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.core.localization.Tooltips;
import appeng.helpers.iface.PatternProviderLogic;
import appeng.helpers.patternprovider.PatternProviderLogic;
import appeng.items.parts.PartItem;
import appeng.items.parts.PartModels;
import appeng.menu.ISubMenu;
Expand All @@ -24,6 +24,7 @@

import gripe._90.megacells.block.MEGAPatternProviderBlock;
import gripe._90.megacells.definition.MEGAParts;
import gripe._90.megacells.definition.MEGATranslations;
import gripe._90.megacells.util.Utils;

public class MEGAPatternProviderPart extends PatternProviderPart {
Expand Down Expand Up @@ -81,9 +82,9 @@ public Item(Properties properties) {
}

@Override
public void appendHoverText(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, level, tooltip, flag);
tooltip.add(Tooltips.of("Supports processing patterns only."));
public void appendHoverText(ItemStack stack, Level level, List<Component> lines, TooltipFlag flag) {
super.appendHoverText(stack, level, lines, flag);
lines.add(Tooltips.of(MEGATranslations.ProcessingOnly.text()));
}
}
}
Loading

0 comments on commit 31380f9

Please sign in to comment.