Skip to content

Commit

Permalink
1.19.2 cherrypick 1.0.20 (#699)
Browse files Browse the repository at this point in the history
* oh fuck I forgot to commit (#698)

* make tool's tooltip colorful (#695)

* Ru_ru lang for GTCEuM (#612)

* Incomplete Russian translation

Initial russian lang transfering from GTCEu 1.12.2 2.7.4-2.8
Done ~64%

* Update ru_ru.json

* Update ru_ru.json

73% Done

* Update ru_ru.json

81% done

* Update ru_ru.json

90%

* Update ru_ru.json (98% done)

Almost done

* Complete update ru_ru.json

100% done

* Update ru_ru.json

* Update ru_ru.json 

93% complition for new tooltip commit

* Update ru_ru.json

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: screret <[email protected]>
Co-authored-by: Arbor <[email protected]>
Co-authored-by: marisathewitch <[email protected]>
  • Loading branch information
4 people authored Jan 6, 2024
1 parent f137223 commit 50b9414
Show file tree
Hide file tree
Showing 34 changed files with 6,323 additions and 96 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ but you will need to craft the ones you're actively using again to regain functi
- add shape info to all machines using coils
- mark multiblock info blocks as inputs for the recipe viewer pattern preview
- add UHV+ electric motors
- add initial Russian translation

**Tool Rework:**
- revamps tools, bringing parity with 1.12 (except electric tools)
Expand Down Expand Up @@ -42,4 +43,4 @@ but you will need to craft the ones you're actively using again to regain functi

Notes for addon devs:
- GTItems.TOOL_ITEMS is now a table<Material, Type, Tool item> instead of the old <Tier, Type, Item>
- torch placing with pickaxes is currently disabled as none of us can find a fix for it deleting the tool.
- torch placing with pickaxes is currently disabled as none of us can find a fix for it deleting the tool.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @date 2023/2/22
* @implNote IRecipeRemainder
*/
@FunctionalInterface
public interface IRecipeRemainder extends IItemComponent {
ItemStack getRecipeRemained(ItemStack itemStack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public class GTToolType {
.toolTag(FORGE, TagUtil.createItemTag("tools/hammers", false))
.toolTag(FABRIC, TagUtil.createItemTag("hammers", false))
.harvestTag(FORGE, TagUtil.createBlockTag("mineable/hammer", false))
.harvestTag(FORGE, TagUtil.createBlockTag("mineable/pickaxe", true))
.harvestTag(FABRIC, TagUtil.createBlockTag("mineable/hammer", false))
.harvestTag(FABRIC, TagUtil.createBlockTag("mineable/pickaxe", true))
.toolStats(b -> b.blockBreaking().crafting().damagePerCraftingAction(2)
.attackDamage(1.0F).attackSpeed(-2.8F)
.behaviors(new EntityDamageBehavior(2.0F, IronGolem.class)))
Expand Down
147 changes: 114 additions & 33 deletions common/src/main/java/com/gregtechceu/gtceu/api/item/tool/ToolHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,42 @@

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Table;
import com.google.common.collect.Tables;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.IElectricItem;
import com.gregtechceu.gtceu.api.capability.recipe.*;
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.ToolProperty;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.item.IGTTool;
import com.gregtechceu.gtceu.api.item.tool.aoe.AoESymmetrical;
import com.gregtechceu.gtceu.api.machine.trait.NotifiableItemStackHandler;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.content.Content;
import com.gregtechceu.gtceu.api.recipe.ingredient.SizedIngredient;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.common.data.GTMachines;
import com.gregtechceu.gtceu.common.data.GTMaterials;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
import com.lowdragmc.lowdraglib.utils.RayTraceHelper;
import com.mojang.math.Vector3d;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.utils.DummyMachineBlockEntity;
import com.gregtechceu.gtceu.utils.InfiniteEnergyContainer;
import com.lowdragmc.lowdraglib.Platform;
import com.lowdragmc.lowdraglib.misc.ItemStackTransfer;
import com.simibubi.create.content.decoration.palettes.GlassPaneBlock;
import dev.architectury.injectables.annotations.ExpectPlatform;
import io.github.fabricators_of_create.porting_lib.extensions.IShearable;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stat;
Expand All @@ -30,10 +46,8 @@
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.enchantment.DigDurabilityEnchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
Expand All @@ -43,8 +57,11 @@
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -155,10 +172,7 @@ public static ItemStack get(GTToolType toolType, Material material) {
}

public static boolean is(ItemStack stack, GTToolType toolType) {
if (stack.getItem() instanceof GTToolItem item) {
return item.getToolType() == toolType;
}
return false;
return getToolTypes(stack).contains(toolType);
}

public static boolean canUse(ItemStack stack) {
Expand Down Expand Up @@ -260,7 +274,7 @@ public static boolean areaOfEffectBlockBreakRoutine(ItemStack stack, ServerPlaye
}

remainingUses--;
if (stack.getItem() instanceof IGTTool && !((IGTTool) stack.getItem()).isElectric() && remainingUses == 0) {
if (stack.getItem() instanceof IGTTool gtTool && !gtTool.isElectric() && remainingUses == 0) {
return true;
}
// If the tool is an electric tool, catch the tool breaking and cancel the remaining AOE
Expand Down Expand Up @@ -364,6 +378,53 @@ private static boolean isBlockAoEHarvestable(ItemStack stack, Level world, Playe
return stack.getItem().isCorrectToolForDrops(state);
}

/**
* Applies Forge Hammer recipes to block broken, used for hammers or tools with hard hammer enchant applied.
*/
public static void applyHammerDropConversion(ServerLevel world, BlockPos pos, ItemStack tool, BlockState state, List<ItemStack> drops, int fortune, float dropChance, RandomSource random) {
if (is(tool, GTToolType.HARD_HAMMER) || /*EnchantmentHelper.getEnchantmentLevel(EnchantmentHardHammer.INSTANCE, tool)*/ -1 > 0) {
List<ItemStack> silktouchDrops = getSilkTouchDrop(world, pos, state);
for (ItemStack silktouchDrop : silktouchDrops) {
if (silktouchDrop.isEmpty()) continue;
// Stack lists can be immutable going into Recipe#matches barring no rewrites
// Search for forge hammer recipes from all drops individually (only LV or under)

Table<IO, RecipeCapability<?>, List<IRecipeHandler<?>>> caps = Tables.newCustomTable(new EnumMap<>(IO.class), IdentityHashMap::new);
DummyMachineBlockEntity be = new DummyMachineBlockEntity(GTValues.LV, GTRecipeTypes.FORGE_HAMMER_RECIPES, GTMachines.defaultTankSizeFunction, caps);
caps.put(IO.IN, EURecipeCapability.CAP, List.of(new InfiniteEnergyContainer(be.getMetaMachine(), GTValues.V[GTValues.LV], GTValues.V[GTValues.LV], 1, GTValues.V[GTValues.LV], 1)));
caps.put(IO.IN, ItemRecipeCapability.CAP, List.of(new NotifiableItemStackHandler(be.getMetaMachine(), 1, IO.IN, IO.IN, (slots) -> new ItemStackTransfer(silktouchDrop))));
caps.put(IO.OUT, ItemRecipeCapability.CAP, List.of(new NotifiableItemStackHandler(be.getMetaMachine(), 2, IO.OUT)));
be.getMetaMachine().reinitializeCapabilities(caps);

List<GTRecipe> hammerRecipes = GTRecipeTypes.FORGE_HAMMER_RECIPES.searchRecipe(Platform.getMinecraftServer().getRecipeManager(), be.metaMachine);
GTRecipe hammerRecipe = hammerRecipes.isEmpty() ? null : hammerRecipes.get(0);
if (hammerRecipe != null && hammerRecipe.handleRecipeIO(IO.IN, be.metaMachine)) {
drops.clear();
TagPrefix prefix = ChemicalHelper.getPrefix(silktouchDrop.getItem());
if (prefix == null) {
for (Content output : hammerRecipe.getOutputContents(ItemRecipeCapability.CAP)) {
if (dropChance >= 1.0F || random.nextFloat() <= dropChance) {
drops.add(SizedIngredient.copy(ItemRecipeCapability.CAP.of(output.content)).getItems()[0]);
}
}
} else if (TagPrefix.ORES.containsKey(prefix)) {
for (Content content : hammerRecipe.getOutputContents(ItemRecipeCapability.CAP)) {
if (dropChance >= 1.0F || random.nextFloat() <= dropChance) {
ItemStack output = ItemRecipeCapability.CAP.of(content.content).getItems()[0];
// Only apply fortune on ore -> crushed forge hammer recipes
if (ChemicalHelper.getPrefix(output.getItem()) == TagPrefix.crushed) {
output = output.copy();
output.grow(random.nextInt(fortune));
drops.add(output);
}
}
}
}
}
}
}
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean breakBlockRoutine(ServerPlayer player, ItemStack tool, BlockPos pos) {
// This is *not* a vanilla/forge convention, Forge never added "shears" to ItemShear's tool classes.
Expand All @@ -374,34 +435,34 @@ public static boolean breakBlockRoutine(ServerPlayer player, ItemStack tool, Blo
boolean canBreak = onBlockBreakEvent(world, player.gameMode.getGameModeForPlayer(), player, pos);
if (!canBreak) {
return false;
}
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
BlockEntity tile = world.getBlockEntity(pos);
if (block instanceof GameMasterBlock && !player.canUseGameMasterBlocks()) {
world.sendBlockUpdated(pos, state, state, 3);
return false;
} else {
world.levelEvent(player, 2001, pos, Block.getId(state));
boolean successful;
if (player.isCreative()) {
successful = removeBlockRoutine(state, world, player, pos, false);
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
BlockEntity tile = world.getBlockEntity(pos);
if (block instanceof GameMasterBlock && !player.canUseGameMasterBlocks()) {
world.sendBlockUpdated(pos, state, state, 3);
return false;
} else if (player.blockActionRestricted(world, pos, player.gameMode.getGameModeForPlayer())) {
return false;
} else if (player.isCreative()) {
return removeBlockRoutine(state, world, player, pos);
} else {
ItemStack copiedTool = tool.isEmpty() ? ItemStack.EMPTY : tool.copy();
world.levelEvent(player, LevelEvent.PARTICLES_DESTROY_BLOCK, pos, Block.getId(state));
boolean successful = removeBlockRoutine(state, world, player, pos);

ItemStack copiedTool = tool.copy();
boolean canHarvest = player.hasCorrectToolForDrops(state);
if (!tool.isEmpty()) {
tool.mineBlock(world, state, pos, player);
if (tool.isEmpty()) {
onPlayerDestroyItem(player, copiedTool, InteractionHand.MAIN_HAND);
}
tool.mineBlock(world, state, pos, player);
if (tool.isEmpty() && !copiedTool.isEmpty()) {
onPlayerDestroyItem(player, copiedTool, InteractionHand.MAIN_HAND);
}

successful = removeBlockRoutine(null, world, player, pos, canHarvest);
if (successful && canHarvest) {
block.playerDestroy(world, player, pos, state, tile, copiedTool);
}

return successful;
}
return successful;
}
}

Expand All @@ -415,14 +476,17 @@ public static void onPlayerDestroyItem(Player player, ItemStack stack, Interacti
throw new AssertionError();
}

public static boolean removeBlockRoutine(@Nullable BlockState state, Level world, ServerPlayer player,
BlockPos pos, boolean canHarvest) {
@ExpectPlatform
public static boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
throw new AssertionError();
}

public static boolean removeBlockRoutine(@Nullable BlockState state, Level world, ServerPlayer player, BlockPos pos) {
state = state == null ? world.getBlockState(pos) : state;
state.getBlock().playerWillDestroy(world, pos, state, player);

boolean successful = world.destroyBlock(pos, canHarvest, player);
boolean successful = world.destroyBlock(pos, false);
if (successful) {
player.getMainHandItem().mineBlock(world, state, pos, player);
state.getBlock().destroy(world, pos, state);
}
return successful;
Expand Down Expand Up @@ -473,6 +537,9 @@ public static void onActionDone(@NotNull Player player, @NotNull Level world, @N

public static Set<GTToolType> getToolTypes(ItemStack tool) {
Set<GTToolType> types = new HashSet<>();
if (tool.getItem() instanceof IGTTool gtTool) {
return gtTool.getToolClasses(tool);
}
for (GTToolType toolType : GTToolType.getTypes().values()) {
if (toolType.itemTags.stream().anyMatch(tool::is)) types.add(toolType);
}
Expand Down Expand Up @@ -629,4 +696,18 @@ public static int shearBlockRoutine(ServerPlayer player, ItemStack tool, BlockPo
private static boolean isCorrectTierForDrops(BlockState state, int tier) {
throw new AssertionError();
}

/**
* @param state the BlockState of the block
* @return the silk touch drop
*/
@NotNull
public static List<ItemStack> getSilkTouchDrop(ServerLevel world, BlockPos origin, @NotNull BlockState state) {
ItemStack tool = GTItems.TOOL_ITEMS.get(GTMaterials.Neutronium, GTToolType.PICKAXE).get().get();
tool.enchant(Enchantments.SILK_TOUCH, 1);

return state.getDrops(new LootContext.Builder(world).withParameter(LootContextParams.BLOCK_STATE, state)
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(origin))
.withParameter(LootContextParams.TOOL, tool));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.data.tag.TagUtil;
import com.gregtechceu.gtceu.api.item.LaserPipeBlockItem;
Expand Down Expand Up @@ -264,17 +265,17 @@ private static void registerOreBlock(Material material) {
})
.transform(unificationBlock(oreTag, material))
.addLayer(() -> RenderType::cutoutMipped)
.blockstate(NonNullBiConsumer.noop())
.setData(ProviderType.LANG, NonNullBiConsumer.noop())
.setData(ProviderType.LOOT, NonNullBiConsumer.noop())
.color(() -> MaterialBlock::tintedColor)
.item(MaterialBlockItem::create)
.onRegister(MaterialBlockItem::onRegister)
.model(NonNullBiConsumer.noop())
.color(() -> MaterialBlockItem::tintColor)
.onRegister(compassNodeExist(GTCompassSections.GENERATIONS, oreTag.name, GTCompassNodes.ORE))
.build()
.register();
.blockstate(NonNullBiConsumer.noop())
.setData(ProviderType.LANG, NonNullBiConsumer.noop())
.setData(ProviderType.LOOT, NonNullBiConsumer.noop())
.color(() -> MaterialBlock::tintedColor)
.item(MaterialBlockItem::create)
.onRegister(MaterialBlockItem::onRegister)
.model(NonNullBiConsumer.noop())
.color(() -> MaterialBlockItem::tintColor)
.onRegister(compassNodeExist(GTCompassSections.GENERATIONS, oreTag.name, GTCompassNodes.ORE))
.build()
.register();
MATERIAL_BLOCKS_BUILDER.put(oreTag, material, entry);
}
}
Expand Down Expand Up @@ -979,7 +980,11 @@ public static ItemColor leavesItemColor() {

public static <P, T extends Block, S2 extends BlockBuilder<T, P>> NonNullFunction<S2, S2> unificationBlock(@Nonnull TagPrefix tagPrefix, @Nonnull Material mat) {
return builder -> {
builder.onRegister(block -> ChemicalHelper.registerUnificationItems(tagPrefix, mat, block));
builder.onRegister(block -> {
UnificationEntry entry = new UnificationEntry(tagPrefix, mat);
GTItems.toUnify.put(entry, block);
ChemicalHelper.registerUnificationItems(entry, block);
});
return builder;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public static void generateTools() {
.onRegister(compassNode(GTCompassSections.MISC)).register();
public static ItemEntry<ComponentItem> WOODEN_FORM_BRICK = REGISTRATE.item("brick_wooden_form", ComponentItem::create)
.lang("Brick Wooden Form")
.properties(p -> p.craftRemainder(Items.AIR))
.properties(p -> p.craftRemainder(Items.AIR).stacksTo(1))
.onRegister(compassNode(GTCompassSections.MISC))
.onRegister(attach((IRecipeRemainder) ItemStack::copy)).register();
.onRegister(attach((IRecipeRemainder) stack -> stack)).register();

public static ItemEntry<Item> SHAPE_EMPTY = REGISTRATE.item("empty_mold", Item::new)
.lang("Empty Mold")
Expand Down
Loading

0 comments on commit 50b9414

Please sign in to comment.