Skip to content

Commit

Permalink
Forge & Fabric 1.20.1 Backport (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
marlester-dev authored Oct 16, 2024
1 parent 6651a34 commit a5e5ff4
Show file tree
Hide file tree
Showing 74 changed files with 454 additions and 600 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.modrinth.minotaur:Minotaur:2.+'
classpath 'gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.7' // Required for NeoGradle
classpath 'gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.7'
classpath 'net.minecraftforge:gradleutils:2.2.0' // Required for changelog generation
}
}
Expand Down Expand Up @@ -80,9 +80,8 @@ subprojects {
processResources {
var expandProps = [
minecraft_version : minecraft_version,
forge_version : forge_version, forge_version_range: forge_version_range, forge_loader_version_range: forge_loader_version_range,
neoforge_version : neoforge_version, neoforge_version_range: neoforge_version_range, neoforge_loader_version_range: neoforge_loader_version_range,
glitchcore_version : glitchcore_version, serene_seasons_version: serene_seasons_version,
forge_version : forge_version, forge_version_range: forge_version_range, forge_loader_version_range: forge_loader_version_range,
mod_id : mod_id, mod_name: mod_name, mod_display_name: mod_display_name, mod_version: mod_version,
mod_authors : mod_authors, mod_description: mod_description,
mod_issues_url : mod_issues_url, mod_page_url: mod_page_url, mod_git_url: mod_git_url,
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/toughasnails/api/item/TANItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package toughasnails.api.item;

import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;

public class TANItems
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
******************************************************************************/
package toughasnails.block;

import com.mojang.serialization.MapCodec;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
Expand Down Expand Up @@ -33,21 +33,12 @@
import toughasnails.block.entity.TemperatureGaugeBlockEntity;
import toughasnails.temperature.TemperatureHelperImpl;

import javax.annotation.Nullable;

public class TemperatureGaugeBlock extends BaseEntityBlock
{
public static final MapCodec<TemperatureGaugeBlock> CODEC = simpleCodec(TemperatureGaugeBlock::new);
protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D);
public static final IntegerProperty POWER = BlockStateProperties.POWER;
public static final BooleanProperty INVERTED = BlockStateProperties.INVERTED;

@Override
public MapCodec<TemperatureGaugeBlock> codec()
{
return CODEC;
}

public TemperatureGaugeBlock(Properties properties)
{
super(properties);
Expand Down
25 changes: 15 additions & 10 deletions common/src/main/java/toughasnails/block/ThermoregulatorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
******************************************************************************/
package toughasnails.block;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand All @@ -30,12 +30,11 @@
import toughasnails.api.particle.TANParticles;
import toughasnails.block.entity.ThermoregulatorBlockEntity;

import javax.annotation.Nullable;
import java.util.function.ToIntFunction;
import javax.annotation.Nullable;

public class ThermoregulatorBlock extends BaseEntityBlock
{
public static final MapCodec<WaterPurifierBlock> CODEC = simpleCodec(WaterPurifierBlock::new);
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty COOLING = BooleanProperty.create("cooling");
public static final BooleanProperty HEATING = BooleanProperty.create("heating");
Expand All @@ -47,12 +46,6 @@ public ThermoregulatorBlock(Properties properties)
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(COOLING, false).setValue(HEATING, false).setValue(ENABLED, true));
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec()
{
return CODEC;
}

@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit)
{
Expand Down Expand Up @@ -120,10 +113,22 @@ public RenderShape getRenderShape(BlockState state)
@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean $$4)
{
Containers.dropContentsOnDestroy(state, newState, level, pos);
dropContentsOnDestroy(state, newState, level, pos);
super.onRemove(state, level, pos, newState, $$4);
}

public static void dropContentsOnDestroy(BlockState $$0, BlockState $$1, Level $$2, BlockPos $$3) {
if (!$$0.is($$1.getBlock())) {
BlockEntity $$4 = $$2.getBlockEntity($$3);
if ($$4 instanceof Container) {
Container $$5 = (Container)$$4;
Containers.dropContents($$2, $$3, $$5);
$$2.updateNeighbourForOutputSignal($$3, $$0.getBlock());
}

}
}

@Override
public void onPlace(BlockState state, Level level, BlockPos $$2, BlockState $$3, boolean $$4)
{
Expand Down
11 changes: 1 addition & 10 deletions common/src/main/java/toughasnails/block/WaterPurifierBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
******************************************************************************/
package toughasnails.block;

import com.mojang.serialization.MapCodec;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
Expand All @@ -30,11 +30,8 @@
import toughasnails.api.blockentity.TANBlockEntityTypes;
import toughasnails.block.entity.WaterPurifierBlockEntity;

import javax.annotation.Nullable;

public class WaterPurifierBlock extends BaseEntityBlock
{
public static final MapCodec<WaterPurifierBlock> CODEC = simpleCodec(WaterPurifierBlock::new);
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty PURIFYING = BooleanProperty.create("filtering");

Expand All @@ -44,12 +41,6 @@ public WaterPurifierBlock(Properties builderIn)
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(PURIFYING, Boolean.valueOf(false)));
}

@Override
protected MapCodec<? extends BaseEntityBlock> codec()
{
return CODEC;
}

@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import toughasnails.api.temperature.TemperatureHelper;
import toughasnails.block.ThermoregulatorBlock;
import toughasnails.container.ThermoregulatorContainer;
import toughasnails.core.ToughAsNails;
import toughasnails.init.ModTags;
import toughasnails.temperature.AreaFill;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
Expand All @@ -36,8 +35,8 @@
import toughasnails.container.WaterPurifierContainer;
import toughasnails.crafting.WaterPurifierRecipe;

import javax.annotation.Nullable;
import java.util.Iterator;
import javax.annotation.Nullable;

public class WaterPurifierBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer
{
Expand Down Expand Up @@ -148,11 +147,11 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Water
ItemStack filterStack = blockEntity.items.get(1);
boolean hasFilter = !filterStack.isEmpty();
if (blockEntity.isFiltering() || hasFilter && !blockEntity.items.get(0).isEmpty()) {
RecipeHolder<?> recipe = blockEntity.level.getRecipeManager().getRecipeFor((RecipeType<WaterPurifierRecipe>) TANRecipeTypes.WATER_PURIFYING, blockEntity, blockEntity.level).orElse(null);
var recipe = blockEntity.level.getRecipeManager().getRecipeFor((RecipeType<WaterPurifierRecipe>) TANRecipeTypes.WATER_PURIFYING, blockEntity, blockEntity.level).orElse(null);

if (recipe != null)
{
if (!blockEntity.isFiltering() && blockEntity.canFilter(recipe.value())) {
if (!blockEntity.isFiltering() && blockEntity.canFilter(recipe)) {
blockEntity.filterTimeRemaining = blockEntity.getFilterDuration(filterStack);
blockEntity.filterDuration = blockEntity.filterTimeRemaining;

Expand All @@ -173,13 +172,13 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Water
}
}

if (blockEntity.isFiltering() && blockEntity.canFilter(recipe.value())) {
if (blockEntity.isFiltering() && blockEntity.canFilter(recipe)) {
++blockEntity.purifyProgress;

if (blockEntity.purifyProgress == blockEntity.purifyTotalTime) {
blockEntity.purifyProgress = 0;
blockEntity.purifyTotalTime = blockEntity.getTotalPurifyTime();
blockEntity.filter(recipe.value());
blockEntity.filter(recipe);
changed = true;
}
} else {
Expand Down Expand Up @@ -367,7 +366,7 @@ protected boolean canFilter(@Nullable Recipe<?> recipe)
/** Get the time taken for an input item to be purified. */
protected int getTotalPurifyTime()
{
return this.level.getRecipeManager().getRecipeFor((RecipeType<WaterPurifierRecipe>) TANRecipeTypes.WATER_PURIFYING, this, this.level).map(r -> r.value().getPurifyTime()).orElse(200);
return this.level.getRecipeManager().getRecipeFor((RecipeType<WaterPurifierRecipe>) TANRecipeTypes.WATER_PURIFYING, this, this.level).map(r -> r.getPurifyTime()).orElse(200);
}

private void filter(@Nullable Recipe<?> recipe)
Expand Down Expand Up @@ -409,7 +408,7 @@ public static int getFilterDuration(ItemStack filter)
private static ImmutableMap<Item, Integer> getFilterDurations()
{
ImmutableMap.Builder<Item, Integer> builder = ImmutableMap.builder();
add(builder, Items.SHORT_GRASS, 100);
add(builder, Items.GRASS, 100);
add(builder, Items.PAPER, 200);
add(builder, Items.GRAVEL, 400);
add(builder, ItemTags.SAND, 800);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.world.entity.player.Inventory;
import toughasnails.api.TANAPI;
import toughasnails.container.ThermoregulatorContainer;
import toughasnails.container.WaterPurifierContainer;

public class ThermoregulatorScreen extends AbstractContainerScreen<ThermoregulatorContainer>
{
Expand All @@ -32,7 +31,7 @@ public void init()
@Override
public void render(GuiGraphics gui, int mouseX, int mouseY, float partialTicks)
{
this.renderBackground(gui, mouseX, mouseY, partialTicks);
this.renderBackground(gui);
super.render(gui, mouseX, mouseY, partialTicks);
this.renderTooltip(gui, mouseX, mouseY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void init()
@Override
public void render(GuiGraphics gui, int mouseX, int mouseY, float partialTicks)
{
this.renderBackground(gui, mouseX, mouseY, partialTicks);
this.renderBackground(gui);
super.render(gui, mouseX, mouseY, partialTicks);
this.renderTooltip(gui, mouseX, mouseY);
}
Expand Down
19 changes: 18 additions & 1 deletion common/src/main/java/toughasnails/client/handler/KeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import com.mojang.blaze3d.platform.InputConstants;
import glitchcore.event.client.InputEvent;
import javax.annotation.Nullable;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;

public class KeyHandler
{
Expand Down Expand Up @@ -62,6 +64,21 @@ private static void debugFeedbackComponent(Component $$0) {
}

private static void debugFeedbackTranslated(String $$0, Object... $$1) {
debugFeedbackComponent(Component.translatableEscape($$0, $$1));
debugFeedbackComponent(translatableEscape($$0, $$1));
}

private static MutableComponent translatableEscape(String $$0, Object... $$1) {
for(int $$2 = 0; $$2 < $$1.length; ++$$2) {
Object $$3 = $$1[$$2];
if (!isAllowedPrimitiveArgument($$3) && !($$3 instanceof Component)) {
$$1[$$2] = String.valueOf($$3);
}
}

return Component.translatable($$0, $$1);
}

private static boolean isAllowedPrimitiveArgument(@Nullable Object $$0) {
return $$0 instanceof Number || $$0 instanceof Boolean || $$0 instanceof String;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void onTooltip(ItemTooltipEvent event)
BlockState state = block.defaultBlockState();
RegistryAccess registryAccess = Minecraft.getInstance().getConnection().registryAccess();

Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, stack, true);
Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, stack);
Optional<Holder.Reference<TrimMaterial>> trimMaterial = TrimMaterials.getFromIngredient(registryAccess, stack);

// Heating/Cooling Blocks and Armor/Trimmed Armor
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/toughasnails/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public void load()
temperatureLeftOffset = addNumber("gui.temperature_left_offset", 0, Integer.MIN_VALUE, Integer.MAX_VALUE, "The offset of the left of the temperature overlay from its default position.");
temperatureTopOffset = addNumber("gui.temperature_top_offset", 0, Integer.MIN_VALUE, Integer.MAX_VALUE, "The offset of the top of the temperature overlay from its default position.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class TemperatureConfig extends Config
{
public boolean enableTemperature;

public int temperatureChangeDelay;
public int armorTemperatureChangeDelay;
public int handheldTemperatureChangeDelay;
Expand Down Expand Up @@ -100,4 +100,4 @@ public void load()
nightTemperatureChange = addNumber("time.night_temperature_change", -1, -4, 4, "Amount to change the temperature at night when the original temperature is not hot.");
nightHotTemperatureChange = addNumber("time.night_hot_temperature_change", -2, -4, 4, "Amount to change the temperature at night when the original temperature is hot.");
}
}
}
4 changes: 1 addition & 3 deletions common/src/main/java/toughasnails/config/ThirstConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import glitchcore.util.Environment;
import toughasnails.api.TANAPI;

import java.nio.file.Path;

public class ThirstConfig extends Config
{
public boolean enableThirst;
Expand Down Expand Up @@ -43,4 +41,4 @@ public void load()
handDrinkingThirst = addNumber("drink_options.hand_drinking_thirst", 1, 0, 20, "Thirst restored from drinking with hands.");
handDrinkingHydration = addNumber("drink_options.hand_drinking_hydration", 0.1D, 0.0D, Double.MAX_VALUE, "Hydration restored from drinking with hands.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
import net.minecraft.world.inventory.SimpleContainerData;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import toughasnails.api.container.TANContainerTypes;
import toughasnails.api.crafting.TANRecipeTypes;
import toughasnails.block.entity.ThermoregulatorBlockEntity;
import toughasnails.block.entity.WaterPurifierBlockEntity;
import toughasnails.crafting.WaterPurifierRecipe;

public class ThermoregulatorContainer extends AbstractContainerMenu
{
Expand Down
1 change: 0 additions & 1 deletion common/src/main/java/toughasnails/core/ToughAsNails.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import glitchcore.event.EventManager;
import glitchcore.util.Environment;
import glitchcore.util.RegistryHelper;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
Expand Down
Loading

0 comments on commit a5e5ff4

Please sign in to comment.