Port To 1.16.1

This commit is contained in:
TheBrokenRail 2020-06-28 12:38:49 -04:00
parent 5167a1319d
commit 462bd85adb
41 changed files with 378 additions and 449 deletions

View File

@ -1,7 +1,6 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id "com.github.johnrengelman.shadow" version "5.2.0"
}
compileJava {
@ -19,6 +18,16 @@ minecraft {
repositories {
jcenter()
maven {
name = 'Earthcomputer Mods'
url = 'https://dl.bintray.com/earthcomputer/mods'
}
}
configurations {
includeTransitive {
transitive = true
}
}
dependencies {
@ -27,37 +36,31 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
modImplementation "io.github.prospector:modmenu:${project.mod_menu_version}"
implementation "com.squareup.moshi:moshi:${project.moshi_version}"
shadow "com.squareup.moshi:moshi:${project.moshi_version}"
includeTransitive "com.squareup.moshi:moshi:${project.moshi_version}"
modImplementation "net.earthcomputer:libstructure:${project.libstructure_version}"
include "net.earthcomputer:libstructure:${project.libstructure_version}"
}
shadowJar {
configurations = [project.configurations.shadow]
classifier 'shadow-dev'
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
task relocateShadowJar(type: ConfigureShadowRelocation) {
target = tasks.shadowJar
prefix = "${project.group}.${project.archivesBaseName}.shadow"
}
tasks.shadowJar.dependsOn tasks.relocateShadowJar
remapJar {
dependsOn shadowJar
input.set shadowJar.archiveFile.get()
project.afterEvaluate {
configurations.includeTransitive.incoming.resolutionResult.allComponents {
if (it.id instanceof ModuleComponentIdentifier) {
def that = it
dependencies {
include group: that.id.getGroup(), name: that.id.getModule(), version: that.id.getVersion()
}
}
}
}
processResources {
inputs.property 'version', mod_version
inputs.property 'version', project.version
inputs.property 'name', rootProject.name
from(sourceSets.main.resources.srcDirs) {
include 'fabric.mod.json'
expand 'version': mod_version, 'name': rootProject.name
expand 'version': project.version, 'name': rootProject.name
}
from(sourceSets.main.resources.srcDirs) {

View File

@ -3,19 +3,19 @@ org.gradle.jvmargs = -Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version = 1.15.2
minecraft_version = 1.16.1
curseforge_id = 373074
simple_minecraft_version = 1.15.2
yarn_build = 15
fabric_loader_version = 0.7.10+build.191
simple_minecraft_version = 1.16.1
yarn_build = 16
fabric_loader_version = 0.8.8+build.202
# Mod Properties
mod_version = 1.0.26
mod_version = 1.0.27
maven_group = com.thebrokenrail
archives_base_name = reliccraft
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version = 0.5.1+build.294-1.15
mod_menu_version = 1.10.2+build.32
fabric_api_version = 0.14.0+build.371-1.16
moshi_version = 1.9.2
libstructure_version = 1.3

View File

@ -22,17 +22,16 @@ import com.thebrokenrail.reliccraft.recipe.RevealRelicRecipe;
import com.thebrokenrail.reliccraft.recipe.TimeDilaterRecipe;
import com.thebrokenrail.reliccraft.structure.TimeTempleFeature;
import com.thebrokenrail.reliccraft.structure.TimeTempleGenerator;
import net.earthcomputer.libstructure.LibStructure;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
@ -40,7 +39,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.loot.BinomialLootTableRange;
import net.minecraft.loot.LootTables;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.LootFunctions;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.recipe.SpecialRecipeSerializer;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
@ -52,17 +51,11 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.DecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.chunk.StructureConfig;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import java.util.Locale;
public class RelicCraft implements ModInitializer {
public static final String NAMESPACE = "reliccraft";
@ -124,12 +117,13 @@ public class RelicCraft implements ModInitializer {
world.playSound(null, pos, INTERACT_TELEPORT_RESTRICTOR_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f);
}
public static StructureFeature<DefaultFeatureConfig> TIME_TEMPLE_STRUCTURE_FEATURE = new TimeTempleFeature(DefaultFeatureConfig::deserialize);
public static StructureFeature<DefaultFeatureConfig> TIME_TEMPLE_STRUCTURE_FEATURE = new TimeTempleFeature(DefaultFeatureConfig.CODEC);
public static StructurePieceType TIME_TEMPLE_STRUCTURE_PIECE = TimeTempleGenerator.Piece::new;
public static final String TIME_TEMPLE_ID = "RelicCraft Time Temple";
public static ItemGroup ITEM_GROUP;
public final static Identifier TIME_TEMPLE_ID = new Identifier(NAMESPACE, "time_temple");
@Override
public void onInitialize() {
ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(NAMESPACE, "item_group"), () -> new ItemStack(TIME_DILATER_ITEM));
@ -140,20 +134,21 @@ public class RelicCraft implements ModInitializer {
TARGETED_ENDER_PEARL_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "targeted_ender_pearl"), new TargetedEnderPearlItem());
GENERATE_RELIC_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "generate_relic"), new GenerateRelicItem());
RELIC_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory<RelicEntity>) RelicEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
Identifier entityID = new Identifier(NAMESPACE, "relic_entity");
RELIC_ENTITY = Registry.register(Registry.ENTITY_TYPE, entityID, EntityType.Builder.create((EntityType.EntityFactory<RelicEntity>) RelicEntity::new, SpawnGroup.MISC).setDimensions(0.25f, 0.25f).build(entityID.toString()));
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (isSelectedLootTable(id)) {
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
.withRolls(new BinomialLootTableRange(2, 0.5f))
.withEntry(ItemEntry.builder(ORB_ITEM))
.withEntry(ItemEntry.builder(STAFF_ITEM))
.withFunction(new RelicLootTableFunction.Builder());
.rolls(new BinomialLootTableRange(2, 0.5f))
.withEntry(ItemEntry.builder(ORB_ITEM).build())
.withEntry(ItemEntry.builder(STAFF_ITEM).build())
.withFunction(new RelicLootTableFunction.Builder().build());
supplier.withPool(poolBuilder);
supplier.withPool(poolBuilder.build());
}
});
LootFunctions.register(new RelicLootTableFunction.Factory());
Registry.register(Registry.LOOT_FUNCTION_TYPE, new Identifier(NAMESPACE, "randomize_relic"), new LootFunctionType(new RelicLootTableFunction.Serializer()));
REVEAL_RELIC_RECIPE = Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(NAMESPACE, "reveal_relic"), new SpecialRecipeSerializer<>(RevealRelicRecipe::new));
TIME_DILATER_RECIPE = Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(NAMESPACE, "time_dilater"), new SpecialRecipeSerializer<>(TimeDilaterRecipe::new));
@ -179,25 +174,11 @@ public class RelicCraft implements ModInitializer {
TagRegistry.item(new Identifier(NAMESPACE, "advancement_trigger_items"));
Registry.register(Registry.STRUCTURE_PIECE, new Identifier(NAMESPACE, "time_temple"), TIME_TEMPLE_STRUCTURE_PIECE);
Registry.register(Registry.FEATURE, new Identifier(NAMESPACE, "time_temple"), TIME_TEMPLE_STRUCTURE_FEATURE);
Registry.register(Registry.STRUCTURE_FEATURE, new Identifier(NAMESPACE, "time_temple"), TIME_TEMPLE_STRUCTURE_FEATURE);
Feature.STRUCTURES.put(TIME_TEMPLE_ID.toLowerCase(Locale.ROOT), TIME_TEMPLE_STRUCTURE_FEATURE);
ConfiguredFeature<?, ?> configuredFeature = getConfiguredFeature(TIME_TEMPLE_STRUCTURE_FEATURE);
for (Biome biome : Registry.BIOME) {
if (biome.getCategory() == Biome.Category.PLAINS) {
biome.addStructureFeature(TIME_TEMPLE_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
}
}
FlatChunkGeneratorConfig.FEATURE_TO_GENERATION_STEP.put(configuredFeature, GenerationStep.Feature.SURFACE_STRUCTURES);
FlatChunkGeneratorConfig.FEATURE_TO_FEATURE_CONFIG.put(configuredFeature, FeatureConfig.DEFAULT);
FlatChunkGeneratorConfig.STRUCTURE_TO_FEATURES.put(NAMESPACE + "_time_temple", new ConfiguredFeature[]{configuredFeature});
}
public static ConfiguredFeature<?, ?> getConfiguredFeature(StructureFeature<DefaultFeatureConfig> feature) {
return feature.configure(FeatureConfig.DEFAULT).createDecoratedFeature(Decorator.NOPE.configure(DecoratorConfig.DEFAULT));
LibStructure.registerStructure(TIME_TEMPLE_ID, TIME_TEMPLE_STRUCTURE_FEATURE, GenerationStep.Feature.SURFACE_STRUCTURES, new StructureConfig(32, 8, 14357618), TIME_TEMPLE_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
}
}

View File

@ -1,14 +1,15 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class ActivateTeleportationBeaconCriterion extends AbstractCriterion<ActivateTeleportationBeaconCriterion.Conditions> {
public class ActivateTeleportationBeaconCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "activate_teleportation_beacon");
public ActivateTeleportationBeaconCriterion() {
@ -20,17 +21,11 @@ public class ActivateTeleportationBeaconCriterion extends AbstractCriterion<Acti
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -1,36 +1,31 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class ActivateTeleportationRestrictorCriterion extends AbstractCriterion<ActivateTeleportationRestrictorCriterion.Conditions> {
public class ActivateTeleportationRestrictorCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "activate_teleportation_restrictor");
public ActivateTeleportationRestrictorCriterion() {
}
@Override
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
@Override
public Identifier getId() {
return ID;
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -1,14 +1,15 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class DilateTimeCriterion extends AbstractCriterion<DilateTimeCriterion.Conditions> {
public class DilateTimeCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "dilate_time");
public DilateTimeCriterion() {
@ -20,17 +21,11 @@ public class DilateTimeCriterion extends AbstractCriterion<DilateTimeCriterion.C
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -1,14 +1,15 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class DuplicateTimeDilaterCriterion extends AbstractCriterion<DuplicateTimeDilaterCriterion.Conditions> {
public class DuplicateTimeDilaterCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "duplicate_time_dilater");
public DuplicateTimeDilaterCriterion() {
@ -20,17 +21,11 @@ public class DuplicateTimeDilaterCriterion extends AbstractCriterion<DuplicateTi
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -1,14 +1,15 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class RevealRelicCriterion extends AbstractCriterion<RevealRelicCriterion.Conditions> {
public class RevealRelicCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "reveal_relic");
public RevealRelicCriterion() {
@ -20,17 +21,11 @@ public class RevealRelicCriterion extends AbstractCriterion<RevealRelicCriterion
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -5,10 +5,12 @@ import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class UseTargetedEnderPearlCriterion extends AbstractCriterion<UseTargetedEnderPearlCriterion.Conditions> {
public class UseTargetedEnderPearlCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "use_targeted_ender_pearl");
public UseTargetedEnderPearlCriterion() {
@ -20,17 +22,11 @@ public class UseTargetedEnderPearlCriterion extends AbstractCriterion<UseTargete
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -1,14 +1,15 @@
package com.thebrokenrail.reliccraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class UseTeleportationBeaconCriterion extends AbstractCriterion<UseTeleportationBeaconCriterion.Conditions> {
public class UseTeleportationBeaconCriterion extends AbstractCriterion<AbstractCriterionConditions> {
private static final Identifier ID = new Identifier(RelicCraft.NAMESPACE, "use_teleportation_beacon");
public UseTeleportationBeaconCriterion() {
@ -20,17 +21,11 @@ public class UseTeleportationBeaconCriterion extends AbstractCriterion<UseTelepo
}
@Override
public Conditions conditionsFromJson(JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) {
return new Conditions();
protected AbstractCriterionConditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new AbstractCriterionConditions(ID, playerPredicate) {};
}
public void trigger(ServerPlayerEntity player) {
test(player.getAdvancementTracker(), conditions -> true);
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions() {
super(ID);
}
test(player, conditions -> true);
}
}

View File

@ -6,11 +6,11 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
@ -30,15 +30,10 @@ public abstract class AbstractDragonEggHolderBlock extends Block implements Bloc
public static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public AbstractDragonEggHolderBlock(Settings settings) {
super(settings);
super(settings.lightLevel(state -> state.get(ACTIVE) ? 7 : 0));
setDefaultState(getStateManager().getDefaultState().with(ACTIVE, false));
}
@Override
public int getLuminance(BlockState state) {
return state.get(ACTIVE) ? 7 : 0;
}
@Override
public BlockEntity createBlockEntity(BlockView view) {
return new DragonEggHolderBlockEntity();
@ -52,18 +47,18 @@ public abstract class AbstractDragonEggHolderBlock extends Block implements Bloc
Inventory inventory = (Inventory) blockEntity;
ItemStack stack = user.getStackInHand(hand);
if (inventory.isValidInvStack(0, stack) && inventory.getInvStack(0).isEmpty()) {
inventory.setInvStack(0, stack.split(1));
if (inventory.isValid(0, stack) && inventory.getStack(0).isEmpty()) {
inventory.setStack(0, stack.split(1));
if (!world.isClient()) {
grantAdvancement(user);
}
return ActionResult.SUCCESS;
} else if (stack.isEmpty()) {
if (!inventory.getInvStack(0).isEmpty()) {
user.inventory.offerOrDrop(world, inventory.getInvStack(0));
if (!inventory.getStack(0).isEmpty()) {
user.inventory.offerOrDrop(world, inventory.getStack(0));
inventory.removeInvStack(0);
inventory.removeStack(0);
return ActionResult.SUCCESS;
} else {
return ActionResult.PASS;
@ -98,14 +93,14 @@ public abstract class AbstractDragonEggHolderBlock extends Block implements Bloc
}
@Override
public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof Inventory) {
ItemScatterer.spawn(world, pos, (Inventory) blockEntity);
}
super.onBlockRemoved(state, world, pos, newState, moved);
super.onStateReplaced(state, world, pos, newState, moved);
}
}
@ -121,7 +116,7 @@ public abstract class AbstractDragonEggHolderBlock extends Block implements Bloc
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return Container.calculateComparatorOutput(world.getBlockEntity(pos));
return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos));
}
public abstract void tick(World world, BlockPos pos);

View File

@ -1,7 +1,6 @@
package com.thebrokenrail.reliccraft.block;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
@ -11,9 +10,8 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Tickable;
import net.minecraft.util.collection.DefaultedList;
import java.util.Objects;
public class DragonEggHolderBlockEntity extends BlockEntity implements Inventory, Tickable {
@ -22,16 +20,16 @@ public class DragonEggHolderBlockEntity extends BlockEntity implements Inventory
}
@Override
public void fromTag(CompoundTag tag) {
super.fromTag(tag);
DefaultedList<ItemStack> list = DefaultedList.ofSize(getInvSize(), ItemStack.EMPTY);
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
DefaultedList<ItemStack> list = DefaultedList.ofSize(size(), ItemStack.EMPTY);
Inventories.fromTag(tag, list);
stack = list.get(0);
}
@Override
public CompoundTag toTag(CompoundTag tag) {
DefaultedList<ItemStack> list = DefaultedList.ofSize(getInvSize(), ItemStack.EMPTY);
DefaultedList<ItemStack> list = DefaultedList.ofSize(size(), ItemStack.EMPTY);
list.set(0, stack);
Inventories.toTag(tag, list);
return super.toTag(tag);
@ -40,56 +38,56 @@ public class DragonEggHolderBlockEntity extends BlockEntity implements Inventory
private ItemStack stack = ItemStack.EMPTY;
@Override
public int getInvSize() {
public int size() {
return 1;
}
@Override
public int getInvMaxStackAmount() {
public int getMaxCountPerStack() {
return 1;
}
@Override
public boolean isInvEmpty() {
public boolean isEmpty() {
return stack.isEmpty();
}
@Override
public ItemStack getInvStack(int slot) {
public ItemStack getStack(int slot) {
return stack;
}
@Override
public ItemStack takeInvStack(int slot, int amount) {
ItemStack newStack = getInvStack(0).split(amount);
public ItemStack removeStack(int slot, int amount) {
ItemStack newStack = getStack(0).split(amount);
markDirty();
return newStack;
}
@Override
public ItemStack removeInvStack(int slot) {
ItemStack newStack = getInvStack(0).copy();
setInvStack(0, ItemStack.EMPTY);
public ItemStack removeStack(int slot) {
ItemStack newStack = getStack(0).copy();
setStack(0, ItemStack.EMPTY);
return newStack;
}
@Override
public void setInvStack(int slot, ItemStack stack) {
public void setStack(int slot, ItemStack stack) {
this.stack = stack;
if (stack.getCount() > getInvMaxStackAmount()) {
stack.setCount(getInvMaxStackAmount());
if (stack.getCount() > getMaxCountPerStack()) {
stack.setCount(getMaxCountPerStack());
}
markDirty();
}
@Override
public boolean canPlayerUseInv(PlayerEntity player) {
public boolean canPlayerUse(PlayerEntity player) {
return true;
}
@Override
public void clear() {
setInvStack(0, ItemStack.EMPTY);
setStack(0, ItemStack.EMPTY);
}
@Override
@ -104,7 +102,7 @@ public class DragonEggHolderBlockEntity extends BlockEntity implements Inventory
}
@Override
public boolean isValidInvStack(int slot, ItemStack stack) {
public boolean isValid(int slot, ItemStack stack) {
return stack.getItem() == Items.DRAGON_EGG;
}
@ -120,7 +118,7 @@ public class DragonEggHolderBlockEntity extends BlockEntity implements Inventory
if (hasWorld()) {
assert getWorld() != null;
BlockState state = getWorld().getBlockState(pos);
boolean active = !getInvStack(0).isEmpty();
boolean active = !getStack(0).isEmpty();
if (state.get(TeleportationRestrictorBlock.ACTIVE) != active) {
getWorld().setBlockState(getPos(), state.with(TeleportationRestrictorBlock.ACTIVE, active));
RelicCraft.playInteractTeleportRestrictorSound(getWorld(), getPos());

View File

@ -1,19 +1,18 @@
package com.thebrokenrail.reliccraft.data;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface Action {
void execute(World world, LivingEntity attacker, Entity target);
void execute(World world, Entity attacker, Entity target);
void execute(World world, LivingEntity attacker, BlockPos pos);
void execute(World world, Entity attacker, BlockPos pos);
int getCost();
default PlayerEntity convertToPlayer(LivingEntity entity) {
default PlayerEntity convertToPlayer(Entity entity) {
if (entity instanceof PlayerEntity) {
return (PlayerEntity) entity;
} else {

View File

@ -6,19 +6,19 @@ import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.thrown.ThrownPotionEntity;
import net.minecraft.entity.projectile.thrown.PotionEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import java.util.ArrayList;
import java.util.HashMap;
@ -73,28 +73,28 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (target instanceof LivingEntity) {
((LivingEntity) target).setHealth(1f);
}
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
ThrownPotionEntity entity = new ThrownPotionEntity(world, pos.getX(), pos.getY(), pos.getZ());
entity.setItemStack(PotionUtil.setPotion(new ItemStack(Items.LINGERING_POTION), Potions.STRONG_HARMING));
public void execute(World world, Entity attacker, BlockPos pos) {
PotionEntity entity = new PotionEntity(world, pos.getX(), pos.getY(), pos.getZ());
entity.setItem(PotionUtil.setPotion(new ItemStack(Items.LINGERING_POTION), Potions.STRONG_HARMING));
world.spawnEntity(entity);
}
}
public static class SwapBlockAction implements Action {
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
execute(world, attacker, target.getBlockPos().down());
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos) && world.canPlayerModifyAt((PlayerEntity) attacker, attacker.getBlockPos().down())) {
BlockState state1 = world.getBlockState(attacker.getBlockPos().down());
BlockState state2 = world.getBlockState(pos);
@ -116,7 +116,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, target.getBlockPos())) {
target.remove();
target.kill();
@ -125,7 +125,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos)) {
world.setBlockState(pos, Blocks.DIRT.getDefaultState());
}
@ -139,16 +139,16 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
BlockPos pos = target.getBlockPos();
BlockState state = world.getBlockState(pos);
world.setBlockState(pos, Blocks.NETHER_PORTAL.getDefaultState());
target.changeDimension(world.dimension.getType() == DimensionType.THE_NETHER ? DimensionType.OVERWORLD : DimensionType.THE_NETHER);
target.changeDimension(((ServerWorld) world).getServer().getWorld(world.getRegistryKey() == World.NETHER ? World.OVERWORLD : World.NETHER));
world.setBlockState(pos, state);
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos)) {
world.setBlockState(pos, Blocks.LAVA.getDefaultState());
}
@ -162,12 +162,12 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
target.changeDimension(world.dimension.getType() == DimensionType.THE_END ? DimensionType.OVERWORLD : DimensionType.THE_END);
public void execute(World world, Entity attacker, Entity target) {
target.changeDimension(((ServerWorld) world).getServer().getWorld(world.getRegistryKey() == World.END ? World.OVERWORLD : World.END));
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos)) {
world.setBlockState(pos, Blocks.END_STONE.getDefaultState());
}
@ -214,20 +214,20 @@ public class Actions {
public abstract Block getConvertedBlock();
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (target instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) target;
for (int i = 0; i < player.inventory.getInvSize(); i++) {
ItemStack stack = player.inventory.getInvStack(i);
for (int i = 0; i < player.inventory.size(); i++) {
ItemStack stack = player.inventory.getStack(i);
if (stack.getItem() == getTargetItem()) {
player.inventory.setInvStack(i, new ItemStack(getConvertedItem(), stack.getCount()));
player.inventory.setStack(i, new ItemStack(getConvertedItem(), stack.getCount()));
}
}
}
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos) && world.getBlockState(pos).getBlock() == getTargetBlock()) {
world.setBlockState(pos, getConvertedBlock().getDefaultState());
}
@ -268,7 +268,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, attacker.getBlockPos())) {
target.remove();
target.kill();
@ -277,7 +277,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos)) {
world.setBlockState(pos, Blocks.BEDROCK.getDefaultState());
}
@ -291,23 +291,23 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (target instanceof LivingEntity) {
((LivingEntity) target).heal(Float.MAX_VALUE);
}
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
ThrownPotionEntity entity = new ThrownPotionEntity(world, pos.getX(), pos.getY(), pos.getZ());
entity.setItemStack(PotionUtil.setPotion(new ItemStack(Items.LINGERING_POTION), Potions.STRONG_HEALING));
public void execute(World world, Entity attacker, BlockPos pos) {
PotionEntity entity = new PotionEntity(world, pos.getX(), pos.getY(), pos.getZ());
entity.setItem(PotionUtil.setPotion(new ItemStack(Items.LINGERING_POTION), Potions.STRONG_HEALING));
world.spawnEntity(entity);
}
}
public static class ZombifyAction implements Action {
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
ZombieEntity zombie = new ZombieEntity(world);
zombie.updatePosition(target.getX(), target.getY(), target.getZ());
world.spawnEntity(zombie);
@ -316,7 +316,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
ZombieEntity zombie = new ZombieEntity(world);
zombie.updatePosition(attacker.getX(), attacker.getY(), attacker.getZ());
world.spawnEntity(zombie);
@ -332,7 +332,7 @@ public class Actions {
public static class RandomAction implements Action {
@Override
public void execute(World world, LivingEntity attacker, Entity target) {
public void execute(World world, Entity attacker, Entity target) {
if (!target.removed) {
target.remove();
target.kill();
@ -340,7 +340,7 @@ public class Actions {
int entityID = new Random().nextInt(Registry.ENTITY_TYPE.getIds().size());
EntityType<?> entityType = Registry.ENTITY_TYPE.get(entityID);
if (entityType.isSummonable()) {
Entity entity = entityType.spawn(world, null, null, convertToPlayer(attacker), target.getBlockPos(), SpawnType.CONVERSION, false, false);
Entity entity = entityType.spawn(world, null, null, convertToPlayer(attacker), target.getBlockPos(), SpawnReason.CONVERSION, false, false);
if (entity != null) {
entity.updatePosition(target.getX(), target.getY(), target.getZ());
} else {
@ -352,7 +352,7 @@ public class Actions {
}
@Override
public void execute(World world, LivingEntity attacker, BlockPos pos) {
public void execute(World world, Entity attacker, BlockPos pos) {
if (attacker instanceof PlayerEntity && world.canPlayerModifyAt((PlayerEntity) attacker, pos)) {
int blockID = new Random().nextInt(Registry.BLOCK.getIds().size());
Block block = Registry.BLOCK.get(blockID);

View File

@ -7,7 +7,7 @@ import com.thebrokenrail.reliccraft.item.RelicItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.thrown.ThrownItemEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.item.Item;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;

View File

@ -1,19 +1,20 @@
package com.thebrokenrail.reliccraft.item;
import com.thebrokenrail.reliccraft.RelicCraft;
import com.thebrokenrail.reliccraft.mixin.ModelPredicateProviderRegistryHook;
import net.minecraft.block.Block;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.collection.DefaultedList;
public class DragonEggHolderBlockItem extends BlockItem {
public DragonEggHolderBlockItem(Block block) {
super(block, new Settings().rarity(Rarity.UNCOMMON).group(RelicCraft.ITEM_GROUP));
addPropertyGetter(new Identifier(RelicCraft.NAMESPACE, "active"), (stack, world, entity) -> {
ModelPredicateProviderRegistryHook.callRegister(this, new Identifier(RelicCraft.NAMESPACE, "active"), (stack, world, entity) -> {
CompoundTag tag = stack.getSubTag("BlockEntityTag");
if (tag != null) {
DefaultedList<ItemStack> list = DefaultedList.ofSize(1, ItemStack.EMPTY);

View File

@ -66,7 +66,7 @@ public class GenerateRelicItem extends Item {
}
@Override
public boolean hasEnchantmentGlint(ItemStack stack) {
public boolean hasGlint(ItemStack stack) {
return true;
}
}

View File

@ -24,11 +24,11 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -70,9 +70,9 @@ public class RelicItem extends Item {
}
@Override
public boolean hasEnchantmentGlint(ItemStack stack) {
public boolean hasGlint(ItemStack stack) {
RelicData data = getData(stack);
return super.hasEnchantmentGlint(stack) || data.enchantmentGlint;
return super.hasGlint(stack) || data.enchantmentGlint;
}
@Override
@ -134,7 +134,7 @@ public class RelicItem extends Item {
}
@Override
public boolean useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
RelicData data = getData(stack);
if (data.use.mode == RelicData.UseData.Mode.TARGET) {
if (!user.getEntityWorld().isClient()) {
@ -144,9 +144,9 @@ public class RelicItem extends Item {
}
damage(stack, user, hand);
return true;
return ActionResult.SUCCESS;
} else {
return false;
return ActionResult.PASS;
}
}

View File

@ -6,6 +6,7 @@ import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.datafixer.NbtOps;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
@ -16,6 +17,7 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
@ -27,10 +29,11 @@ import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import java.util.List;
import java.util.UUID;
public class TargetedEnderPearlItem extends Item {
public TargetedEnderPearlItem() {
@ -38,7 +41,7 @@ public class TargetedEnderPearlItem extends Item {
}
@Override
public boolean hasEnchantmentGlint(ItemStack stack) {
public boolean hasGlint(ItemStack stack) {
return true;
}
@ -58,16 +61,16 @@ public class TargetedEnderPearlItem extends Item {
BlockPos target = new BlockPos(tag.getInt("TargetX"), tag.getInt("TargetY"), tag.getInt("TargetZ"));
Vec3d teleportTarget = new Vec3d(target.getX() + 0.5d, target.getY() + 1.0d, target.getZ() + 0.5d);
DimensionType dimension = DimensionType.byId(new Identifier(tag.getString("TargetDimension")));
RegistryKey<World> dimension = World.CODEC.parse(NbtOps.INSTANCE, tag.get("TargetDimension")).result().orElse(World.OVERWORLD);
if (user.dimension != dimension || dimension == null) {
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_in_different_dimension"));
if (user.getEntityWorld().getRegistryKey() != dimension || dimension == null) {
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_in_different_dimension"), false);
return new TypedActionResult<>(ActionResult.FAIL, stack);
} else if (((TeleportationRestrictorBlock.TeleportingEntity) user).cannotTeleport()) {
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_restricted"));
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_restricted"), false);
return new TypedActionResult<>(ActionResult.FAIL, stack);
} else if (world.getBlockState(target).getBlock() != RelicCraft.TELEPORTATION_BEACON_BLOCK || !world.getBlockState(target).get(AbstractDragonEggHolderBlock.ACTIVE)) {
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".missing_teleportation_beacon"));
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".missing_teleportation_beacon"), false);
return new TypedActionResult<>(ActionResult.FAIL, stack);
} else {
Vec3d oldPos = user.getPos();
@ -85,7 +88,7 @@ public class TargetedEnderPearlItem extends Item {
stack.decrement(1);
}
} else {
user.sendMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_obstructed"));
user.sendSystemMessage(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".teleportation_beacon_obstructed"), UUID.randomUUID());
return new TypedActionResult<>(ActionResult.FAIL, stack);
}
}
@ -110,7 +113,7 @@ public class TargetedEnderPearlItem extends Item {
Identifier id = new Identifier(tag.getString("TargetDimension"));
String key = "text." + RelicCraft.NAMESPACE + ".dimension." + id.getNamespace() + '.' + id.getPath();
Text dimensionText;
MutableText dimensionText;
if (Language.getInstance().hasTranslation(key)) {
dimensionText = new TranslatableText(key);
} else {

View File

@ -9,16 +9,15 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.MessageType;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.*;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import java.util.List;
@ -30,6 +29,36 @@ public class TimeDilaterItem extends Item {
VERY_FAST
}
public static final String TIME_SPEED_KEY = new Identifier(RelicCraft.NAMESPACE, "time_speed").toString();
public static class TimeSpeedState extends PersistentState {
private TimeSpeed timeSpeed = TimeSpeed.NORMAL;
public TimeSpeedState() {
super(TIME_SPEED_KEY);
}
public void setTimeSpeed(TimeSpeed timeSpeed) {
this.timeSpeed = timeSpeed;
markDirty();
}
public TimeSpeed getTimeSpeed() {
return timeSpeed;
}
@Override
public void fromTag(CompoundTag tag) {
timeSpeed = TimeSpeed.valueOf(tag.getString("TimeSpeed"));
}
@Override
public CompoundTag toTag(CompoundTag tag) {
tag.putString("TimeSpeed", timeSpeed.name());
return tag;
}
}
public interface DilatedWorld {
void setTimeSpeed(TimeSpeed speed);
TimeSpeed getTimeSpeed();
@ -62,7 +91,7 @@ public class TimeDilaterItem extends Item {
}
}
assert world.getServer() != null;
world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".announce_time_speed_change", user.getDisplayName(), new LiteralText("[").append(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".announce_time_speed_change." + dilatedWorld.getTimeSpeed().name().toLowerCase())).append("]").formatted(Formatting.YELLOW)));
world.getServer().getPlayerManager().sendToAll(new GameMessageS2CPacket(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".announce_time_speed_change", user.getDisplayName(), new LiteralText("[").append(new TranslatableText("chat." + RelicCraft.NAMESPACE + ".announce_time_speed_change." + dilatedWorld.getTimeSpeed().name().toLowerCase())).append("]").formatted(Formatting.YELLOW)), MessageType.CHAT, Util.NIL_UUID));
RelicCraft.DILATE_TIME_CRITERION.trigger((ServerPlayerEntity) user);
}

View File

@ -11,11 +11,13 @@ import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.function.ConditionalLootFunction;
import net.minecraft.loot.function.LootFunction;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class RelicLootTableFunction extends ConditionalLootFunction {
private RelicLootTableFunction(LootCondition[] conditions) {
protected RelicLootTableFunction(LootCondition[] conditions) {
super(conditions);
}
@ -32,9 +34,14 @@ public class RelicLootTableFunction extends ConditionalLootFunction {
return stack;
}
public static class Factory extends ConditionalLootFunction.Factory<RelicLootTableFunction> {
public Factory() {
super(new Identifier(RelicCraft.NAMESPACE, "randomize_relic"), RelicLootTableFunction.class);
@Override
public LootFunctionType getType() {
return Registry.LOOT_FUNCTION_TYPE.get(new Identifier(RelicCraft.NAMESPACE, "randomize_relic"));
}
public static class Serializer extends ConditionalLootFunction.Serializer<RelicLootTableFunction> {
public Serializer() {
super();
}
@Override

View File

@ -1,11 +1,11 @@
package com.thebrokenrail.reliccraft.mixin;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.advancement.criterion.Criterion;
import net.minecraft.advancement.criterion.Criterions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Criterions.class)
@Mixin(Criteria.class)
public interface CriteriaRegistryHook {
@Invoker("register")
static <T extends Criterion<?>> T callRegister(T criterion) {

View File

@ -0,0 +1,15 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.item.TimeDilaterItem;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(ClientWorld.class)
public abstract class MixinClientWorld extends MixinWorld {
@ModifyConstant(constant = @Constant(longValue = 1L), method = "tickTime")
public long tickTime(long value) {
return value * TimeDilaterItem.getTimeDilationFactor(getTimeSpeed());
}
}

View File

@ -1,19 +0,0 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.DefaultBiomeFeatures;
import net.minecraft.world.gen.GenerationStep;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused")
@Mixin(DefaultBiomeFeatures.class)
public class MixinDefaultBiomeFeatures {
@Inject(at = @At("RETURN"), method = "addDefaultStructures")
private static void addDefaultStructures(Biome biome, CallbackInfo info) {
biome.addFeature(GenerationStep.Feature.SURFACE_STRUCTURES, RelicCraft.getConfiguredFeature(RelicCraft.TIME_TEMPLE_STRUCTURE_FEATURE));
}
}

View File

@ -29,7 +29,7 @@ public class MixinEnderPearlItem extends Item {
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
String dimension = Objects.requireNonNull(DimensionType.getId(world.getDimension().getType())).toString();
String dimension = world.getRegistryKey().toString();
BlockState state = world.getBlockState(pos);
PlayerEntity user = context.getPlayer();

View File

@ -1,11 +1,13 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
import net.minecraft.world.gen.feature.LakeFeature;
import net.minecraft.world.gen.feature.SingleStateFeatureConfig;
import org.spongepowered.asm.mixin.Mixin;
@ -21,7 +23,7 @@ import java.util.Random;
@Mixin(LakeFeature.class)
public class MixinLakeFeature {
@Inject(at = @At("HEAD"), method = "generate", cancellable = true)
public void fixTimeTemple(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, SingleStateFeatureConfig singleStateFeatureConfig, CallbackInfoReturnable<Boolean> info) {
public void fixTimeTemple(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, SingleStateFeatureConfig singleStateFeatureConfig, CallbackInfoReturnable<Boolean> info) {
List<Chunk> chunksToScan = new ArrayList<>();
chunksToScan.add(world.getChunk(blockPos));
chunksToScan.add(world.getChunk(blockPos.add(16, 0, 16)));
@ -34,7 +36,7 @@ public class MixinLakeFeature {
chunksToScan.add(world.getChunk(blockPos.add(-16, 0, 16)));
for (Chunk chunk : chunksToScan) {
if (!chunk.getStructureReferences(RelicCraft.TIME_TEMPLE_ID).isEmpty()) {
if (!chunk.getStructureReferences(RelicCraft.TIME_TEMPLE_STRUCTURE_FEATURE).isEmpty()) {
info.setReturnValue(false);
break;
}

View File

@ -1,41 +0,0 @@
package com.thebrokenrail.reliccraft.mixin;
import com.mojang.datafixers.DataFixer;
import com.thebrokenrail.reliccraft.item.TimeDilaterItem;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.LevelProperties;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused")
@Mixin(LevelProperties.class)
public class MixinLevelProperties implements TimeDilaterItem.DilatedWorld {
@Unique
private TimeDilaterItem.TimeSpeed timeSpeed = TimeDilaterItem.TimeSpeed.NORMAL;
@Inject(at = @At("RETURN"), method = "<init>(Lnet/minecraft/nbt/CompoundTag;Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;)V")
public void init(CompoundTag compoundTag, DataFixer dataFixer, int i, CompoundTag compoundTag2, CallbackInfo info) {
try {
timeSpeed = TimeDilaterItem.TimeSpeed.valueOf(compoundTag.getString("RelicCraftTimeSpeed"));
} catch (IllegalArgumentException ignored) {
}
}
@Inject(at = @At("RETURN"), method = "updateProperties")
public void updateProperties(CompoundTag levelTag, CompoundTag playerTag, CallbackInfo ci) {
levelTag.putString("RelicCraftTimeSpeed", timeSpeed.name());
}
@Override
public TimeDilaterItem.TimeSpeed getTimeSpeed() {
return timeSpeed;
}
@Override
public void setTimeSpeed(TimeDilaterItem.TimeSpeed timeSpeed) {
this.timeSpeed = timeSpeed;
}
}

View File

@ -1,27 +0,0 @@
package com.thebrokenrail.reliccraft.mixin;
import com.mojang.brigadier.CommandDispatcher;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.LocateCommand;
import net.minecraft.server.command.ServerCommandSource;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused")
@Mixin(LocateCommand.class)
public abstract class MixinLocateCommand {
@Shadow
private static int execute(ServerCommandSource source, String structure) {
throw new UnsupportedOperationException();
}
@Inject(method = "register", at = @At(value = "RETURN"))
private static void onRegister(CommandDispatcher<ServerCommandSource> dispatcher, CallbackInfo info) {
dispatcher.register(CommandManager.literal("locate").requires(source -> source.hasPermissionLevel(2))
.then(CommandManager.literal("RelicCraft_Time_Temple").executes(ctx -> execute(ctx.getSource(), RelicCraft.TIME_TEMPLE_ID))));
}
}

View File

@ -15,8 +15,8 @@ public abstract class MixinServerChunkManager {
@Shadow
public abstract World getWorld();
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getInt(Lnet/minecraft/world/GameRules$RuleKey;)I"), method = "tickChunks")
public int adjustRandomTickSpeed(GameRules gameRules, GameRules.RuleKey<GameRules.IntRule> rule) {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getInt(Lnet/minecraft/world/GameRules$Key;)I"), method = "tickChunks")
public int adjustRandomTickSpeed(GameRules gameRules, GameRules.Key<GameRules.IntRule> rule) {
if (rule.equals(GameRules.RANDOM_TICK_SPEED)) {
return (int) (gameRules.getInt(rule) * TimeDilaterItem.getTimeDilationFactor(((TimeDilaterItem.DilatedWorld) getWorld()).getTimeSpeed()));
} else {

View File

@ -1,10 +1,17 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.item.TimeDilaterItem;
import com.thebrokenrail.reliccraft.packet.UpdateTimeDilationS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.function.BooleanSupplier;
@ -12,8 +19,31 @@ import java.util.function.BooleanSupplier;
@SuppressWarnings("unused")
@Mixin(ServerWorld.class)
public abstract class MixinServerWorld extends MixinWorld {
@Unique
private TimeDilaterItem.TimeSpeedState timeSpeedState;
@Inject(at = @At("RETURN"), method = "tick")
public void tick(BooleanSupplier shouldKeepTicking, CallbackInfo info) {
UpdateTimeDilationS2CPacket.send((ServerWorld) (Object) this, getTimeSpeed());
}
@ModifyConstant(constant = @Constant(longValue = 1L), method = "tickTime")
public long tickTime(long value) {
return value * TimeDilaterItem.getTimeDilationFactor(getTimeSpeed());
}
@Shadow
public abstract MinecraftServer getServer();
@Override
public void setTimeSpeed(TimeDilaterItem.TimeSpeed timeSpeed) {
TimeDilaterItem.TimeSpeedState state = getServer().getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TimeDilaterItem.TimeSpeedState::new, TimeDilaterItem.TIME_SPEED_KEY);
state.setTimeSpeed(timeSpeed);
getServer().getWorld(World.OVERWORLD).getPersistentStateManager().set(state);
}
@Override
public TimeDilaterItem.TimeSpeed getTimeSpeed() {
return getServer().getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TimeDilaterItem.TimeSpeedState::new, TimeDilaterItem.TIME_SPEED_KEY).getTimeSpeed();
}
}

View File

@ -1,7 +1,7 @@
package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
import net.minecraft.entity.thrown.ThrownEnderpearlEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.util.hit.HitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -9,12 +9,12 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused")
@Mixin(ThrownEnderpearlEntity.class)
@Mixin(EnderPearlEntity.class)
public class MixinThrownEnderpearlEntity {
@Inject(at = @At("HEAD"), method = "onCollision", cancellable = true)
public void onCollision(HitResult hitResult, CallbackInfo info) {
if (((TeleportationRestrictorBlock.TeleportingEntity) this).cannotTeleport()) {
((ThrownEnderpearlEntity) (Object) this).remove();
((EnderPearlEntity) (Object) this).remove();
info.cancel();
}
}

View File

@ -2,12 +2,9 @@ package com.thebrokenrail.reliccraft.mixin;
import com.thebrokenrail.reliccraft.item.TimeDilaterItem;
import net.minecraft.world.World;
import net.minecraft.world.level.LevelProperties;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.Unique;
@SuppressWarnings("unused")
@Mixin(World.class)
@ -15,25 +12,19 @@ public abstract class MixinWorld implements TimeDilaterItem.DilatedWorld {
@Shadow
public abstract boolean isClient();
@Shadow
@Final
protected LevelProperties properties;
@Unique
private TimeDilaterItem.TimeSpeed timeSpeed = TimeDilaterItem.TimeSpeed.NORMAL;
@Shadow
public abstract long getTime();
@ModifyConstant(constant = @Constant(longValue = 1L), method = "tickTime")
public long tickTime(long value) {
return value * TimeDilaterItem.getTimeDilationFactor(getTimeSpeed());
}
@Override
public void setTimeSpeed(TimeDilaterItem.TimeSpeed timeSpeed) {
((TimeDilaterItem.DilatedWorld) properties).setTimeSpeed(timeSpeed);
this.timeSpeed = timeSpeed;
}
@Override
public TimeDilaterItem.TimeSpeed getTimeSpeed() {
return ((TimeDilaterItem.DilatedWorld) properties).getTimeSpeed();
return timeSpeed;
}
}

View File

@ -0,0 +1,16 @@
package com.thebrokenrail.reliccraft.mixin;
import net.minecraft.client.item.ModelPredicateProvider;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(ModelPredicateProviderRegistry.class)
public interface ModelPredicateProviderRegistryHook {
@Invoker
static void callRegister(Item item, Identifier id, ModelPredicateProvider provider) {
throw new UnsupportedOperationException();
}
}

View File

@ -10,9 +10,9 @@ import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.Packet;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.world.World;
@SuppressWarnings("unused")

View File

@ -11,8 +11,8 @@ import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World;
import java.util.Random;
@ -27,8 +27,8 @@ public class RevealRelicRecipe extends SpecialCraftingRecipe {
ItemStack itemStack = ItemStack.EMPTY;
int netherStar = 0;
for (int i = 0; i < craftingInventory.getInvSize(); ++i) {
ItemStack itemStack2 = craftingInventory.getInvStack(i);
for (int i = 0; i < craftingInventory.size(); ++i) {
ItemStack itemStack2 = craftingInventory.getStack(i);
if (!itemStack2.isEmpty()) {
if (itemStack2.getItem() instanceof RelicItem) {
if (!itemStack.isEmpty()) {
@ -51,8 +51,8 @@ public class RevealRelicRecipe extends SpecialCraftingRecipe {
public ItemStack craft(CraftingInventory craftingInventory) {
ItemStack itemStack = ItemStack.EMPTY;
for (int i = 0; i < craftingInventory.getInvSize(); i++) {
ItemStack itemStack2 = craftingInventory.getInvStack(i);
for (int i = 0; i < craftingInventory.size(); i++) {
ItemStack itemStack2 = craftingInventory.getStack(i);
if (!itemStack2.isEmpty()) {
Item item = itemStack2.getItem();
if (item instanceof RelicItem) {
@ -92,9 +92,9 @@ public class RevealRelicRecipe extends SpecialCraftingRecipe {
@Override
public DefaultedList<ItemStack> getRemainingStacks(CraftingInventory inventory) {
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inventory.getInvSize(), ItemStack.EMPTY);
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY);
for (int i = 0; i < defaultedList.size(); i++) {
ItemStack stack = inventory.getInvStack(i);
ItemStack stack = inventory.getStack(i);
if (stack.getItem().hasRecipeRemainder()) {
defaultedList.set(i, new ItemStack(stack.getItem().getRecipeRemainder()));
} else if (stack.getItem() == Items.NETHER_STAR && !stack.damage(1, new Random(), null)) {

View File

@ -8,9 +8,8 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.ShapelessRecipe;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import java.util.Random;
public class TimeDilaterRecipe extends ShapelessRecipe {
@ -39,9 +38,9 @@ public class TimeDilaterRecipe extends ShapelessRecipe {
@Override
public DefaultedList<ItemStack> getRemainingStacks(CraftingInventory inventory) {
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inventory.getInvSize(), ItemStack.EMPTY);
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inventory.size(), ItemStack.EMPTY);
for (int i = 0; i < defaultedList.size(); i++) {
ItemStack stack = inventory.getInvStack(i);
ItemStack stack = inventory.getStack(i);
if (stack.getItem() == Items.NETHER_STAR && !stack.damage(1, new Random(), null) || stack.getItem() == RelicCraft.TIME_DILATER_ITEM) {
defaultedList.set(i, stack.copy());
}

View File

@ -1,34 +1,52 @@
package com.thebrokenrail.reliccraft.structure;
import com.mojang.datafixers.Dynamic;
import com.thebrokenrail.reliccraft.RelicCraft;
import net.minecraft.world.gen.feature.AbstractTempleFeature;
import com.mojang.serialization.Codec;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
import java.util.function.Function;
import java.util.Random;
public class TimeTempleFeature extends AbstractTempleFeature<DefaultFeatureConfig> {
public TimeTempleFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> configFactory) {
super(configFactory);
public class TimeTempleFeature extends StructureFeature<DefaultFeatureConfig> {
public TimeTempleFeature(Codec<DefaultFeatureConfig> codec) {
super(codec);
}
@Override
protected int getSeedModifier() {
return 0;
public StructureStartFactory<DefaultFeatureConfig> getStructureStartFactory() {
return Start::new;
}
@Override
public StructureStartFactory getStructureStartFactory() {
return TimeTempleStructureStart::new;
protected boolean shouldStartAt(ChunkGenerator chunkGenerator, BiomeSource biomeSource, long l, ChunkRandom chunkRandom, int i, int j, Biome biome, ChunkPos chunkPos, DefaultFeatureConfig defaultFeatureConfig) {
int k = i >> 4;
int m = j >> 4;
chunkRandom.setSeed((long) (k ^ m << 4) ^ l);
chunkRandom.nextInt();
return chunkRandom.nextInt(5) == 0;
}
@Override
public String getName() {
return RelicCraft.TIME_TEMPLE_ID;
}
public static class Start extends StructureStart<DefaultFeatureConfig> {
public Start(StructureFeature<DefaultFeatureConfig> feature, int chunkX, int chunkZ, BlockBox box, int references, long seed) {
super(feature, chunkX, chunkZ, box, references, seed);
}
@Override
public int getRadius() {
return 8;
@Override
public void init(ChunkGenerator chunkGenerator, StructureManager structureManager, int x, int z, Biome biome, DefaultFeatureConfig featureConfig) {
int i = x * 16;
int j = z * 16;
BlockPos blockPos = new BlockPos(i, 90, j);
BlockRotation blockRotation = BlockRotation.values()[random.nextInt(BlockRotation.values().length)];
TimeTempleGenerator.addPieces(structureManager, blockPos, blockRotation, children);
setBoundingBoxFromChildren();
}
}
}

View File

@ -6,11 +6,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.state.property.Property;
import net.minecraft.structure.SimpleStructurePiece;
import net.minecraft.structure.Structure;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructurePiece;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.*;
import net.minecraft.structure.processor.BlockIgnoreStructureProcessor;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
@ -19,7 +15,9 @@ import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import java.util.Collection;
@ -52,7 +50,7 @@ public class TimeTempleGenerator {
private void initializeStructureData(StructureManager manager) {
Structure structure = manager.getStructureOrBlank(template);
StructurePlacementData structurePlacementData = new StructurePlacementData().setRotation(rotation).setMirrored(BlockMirror.NONE).setIgnoreEntities(true).addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS);
StructurePlacementData structurePlacementData = new StructurePlacementData().setRotation(rotation).setMirror(BlockMirror.NONE).setIgnoreEntities(true).addProcessor(BlockIgnoreStructureProcessor.IGNORE_STRUCTURE_BLOCKS);
setStructureData(structure, pos, structurePlacementData);
}
@ -64,39 +62,31 @@ public class TimeTempleGenerator {
}
@Override
public boolean generate(IWorld world, ChunkGenerator<?> generator, Random random, BlockBox box, ChunkPos chunkPos) {
int yHeight = 0;
int area = 0;
for (int x = getBoundingBox().minX; x <= getBoundingBox().maxX; x++) {
for (int z = getBoundingBox().minZ; z <= getBoundingBox().maxZ; z++) {
yHeight = yHeight + world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, x, z);
area++;
}
}
yHeight = yHeight / area;
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, Random random, BlockBox boundingBox, ChunkPos chunkPos, BlockPos blockPos) {
int yHeight = world.getTopY(Heightmap.Type.WORLD_SURFACE_WG, this.pos.getX() + 5, this.pos.getZ() + 5);
BlockPos originalPos = pos;
pos = pos.add(0, yHeight - 90, 0);
boolean result = super.generate(world, generator, random, box, chunkPos);
boolean result = super.generate(world, structureAccessor, chunkGenerator, random, boundingBox, chunkPos, blockPos);
if (result) {
for (int x = getBoundingBox().minX; x <= getBoundingBox().maxX; x++) {
for (int y = getBoundingBox().minY; y <= getBoundingBox().maxY; y++) {
for (int z = getBoundingBox().minZ; z <= getBoundingBox().maxZ; z++) {
BlockPos blockPos = new BlockPos(x, y, z);
if (box.contains(blockPos)) {
BlockState state = world.getBlockState(blockPos);
BlockPos newPos = new BlockPos(x, y, z);
if (boundingBox.contains(newPos)) {
BlockState state = world.getBlockState(newPos);
boolean damaged = random.nextFloat() < 0.6f;
if (damaged) {
if (state.getBlock() == Blocks.STONE_BRICKS) {
boolean mossy = random.nextFloat() < 0.5f;
world.setBlockState(blockPos, convertState(state, mossy ? Blocks.MOSSY_STONE_BRICKS : Blocks.CRACKED_STONE_BRICKS), 3);
} else if (world.getBlockState(blockPos).getBlock() == Blocks.STONE_BRICK_STAIRS) {
world.setBlockState(blockPos, convertState(state, Blocks.MOSSY_STONE_BRICK_STAIRS), 3);
} else if (world.getBlockState(blockPos).getBlock() == Blocks.STONE_BRICK_SLAB) {
world.setBlockState(blockPos, convertState(state, Blocks.MOSSY_STONE_BRICK_SLAB), 3);
world.setBlockState(newPos, convertState(state, mossy ? Blocks.MOSSY_STONE_BRICKS : Blocks.CRACKED_STONE_BRICKS), 3);
} else if (world.getBlockState(newPos).getBlock() == Blocks.STONE_BRICK_STAIRS) {
world.setBlockState(newPos, convertState(state, Blocks.MOSSY_STONE_BRICK_STAIRS), 3);
} else if (world.getBlockState(newPos).getBlock() == Blocks.STONE_BRICK_SLAB) {
world.setBlockState(newPos, convertState(state, Blocks.MOSSY_STONE_BRICK_SLAB), 3);
}
}
}
@ -121,7 +111,7 @@ public class TimeTempleGenerator {
}
@Override
protected void handleMetadata(String metadata, BlockPos pos, IWorld world, Random random, BlockBox boundingBox) {
protected void handleMetadata(String metadata, BlockPos pos, WorldAccess world, Random random, BlockBox boundingBox) {
}
}
}

View File

@ -1,26 +0,0 @@
package com.thebrokenrail.reliccraft.structure;
import net.minecraft.structure.StructureManager;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.StructureFeature;
public class TimeTempleStructureStart extends StructureStart {
public TimeTempleStructureStart(StructureFeature<?> feature, int chunkX, int chunkZ, BlockBox box, int references, long l) {
super(feature, chunkX, chunkZ, box, references, l);
}
@Override
public void initialize(ChunkGenerator<?> chunkGenerator, StructureManager structureManager, int x, int z, Biome biome) {
int i = x * 16;
int j = z * 16;
BlockPos blockPos = new BlockPos(i, 90, j);
BlockRotation blockRotation = BlockRotation.values()[random.nextInt(BlockRotation.values().length)];
TimeTempleGenerator.addPieces(structureManager, blockPos, blockRotation, children);
setBoundingBoxFromChildren();
}
}

View File

@ -29,6 +29,6 @@
"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.15.x"
"minecraft": "1.16.x"
}
}

View File

@ -8,20 +8,19 @@
"mixins": [
"CriteriaRegistryHook",
"MixinBlockItem",
"MixinDefaultBiomeFeatures",
"MixinClientWorld",
"MixinEnderDragonFight",
"MixinEnderPearlItem",
"MixinEntity",
"MixinItemStack",
"MixinLakeFeature",
"MixinLevelProperties",
"MixinLivingEntity",
"MixinLocateCommand",
"MixinNetherStarItem",
"MixinServerChunkManager",
"MixinServerWorld",
"MixinThrownEnderpearlEntity",
"MixinWorld"
"MixinWorld",
"ModelPredicateProviderRegistryHook"
],
"injectors": {
"defaultRequire": 1