Skip to content

Commit

Permalink
almost everything?
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Oct 11, 2024
1 parent b42e289 commit 29b51b1
Show file tree
Hide file tree
Showing 646 changed files with 69 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.CampfireBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.CampfireBlockEntity;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ContainerComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
Expand All @@ -18,6 +21,7 @@
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.input.SingleStackRecipeInput;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.Clearable;
import net.minecraft.util.ItemScatterer;
Expand All @@ -36,7 +40,7 @@ public class CherineCampfireBlockEntity extends BlockEntity implements Clearable
private final DefaultedList<ItemStack> itemsBeingCooked;
private final int[] cookingTimes;
private final int[] cookingTotalTimes;
private final RecipeManager.MatchGetter<Inventory, CampfireCookingRecipe> matchGetter;
private final RecipeManager.MatchGetter<SingleStackRecipeInput, CampfireCookingRecipe> matchGetter;

public CherineCampfireBlockEntity(BlockPos pos, BlockState state) {
super(ParadiseLostBlockEntityTypes.CHERINE_CAMPFIRE, pos, state);
Expand All @@ -53,11 +57,10 @@ public static void litServerTick(World world, BlockPos pos, BlockState state, Ch
ItemStack itemStack = campfire.itemsBeingCooked.get(i);
if (!itemStack.isEmpty()) {
bl = true;
int var10002 = campfire.cookingTimes[i]++;
if (campfire.cookingTimes[i] >= campfire.cookingTotalTimes[i]) {
Inventory inventory = new SimpleInventory(itemStack);
ItemStack itemStack2 = campfire.matchGetter.getFirstMatch(inventory, world).map((recipe) -> {
return recipe.value().craft(inventory, world.getRegistryManager());
SingleStackRecipeInput singleStackRecipeInput = new SingleStackRecipeInput(itemStack);
ItemStack itemStack2 = campfire.matchGetter.getFirstMatch(singleStackRecipeInput, world).map((recipe) -> {
return (recipe.value()).craft(singleStackRecipeInput, world.getRegistryManager());
}).orElse(itemStack);
if (itemStack2.isItemEnabled(world.getEnabledFeatures())) {
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), itemStack2);
Expand Down Expand Up @@ -109,7 +112,7 @@ public static void clientTick(World world, BlockPos pos, BlockState state, Cheri
double e = (double) pos.getY() + 0.5;
double g = (double) pos.getZ() + 0.5 - (double) ((float) direction.getOffsetZ() * 0.3125F) + (double) ((float) direction.rotateYClockwise().getOffsetZ() * 0.3125F);

for (int k = 0; k < 4; ++k) {
for(int k = 0; k < 4; ++k) {
world.addParticle(ParticleTypes.SMOKE, d, e, g, 0.0, 5.0E-4, 0.0);
}
}
Expand Down Expand Up @@ -156,16 +159,16 @@ public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryL
}

public Optional<RecipeEntry<CampfireCookingRecipe>> getRecipeFor(ItemStack stack) {
return this.itemsBeingCooked.stream().noneMatch(ItemStack::isEmpty) ? Optional.empty() : this.matchGetter.getFirstMatch(new SimpleInventory(new ItemStack[]{stack}), this.world);
return this.itemsBeingCooked.stream().noneMatch(ItemStack::isEmpty) ? Optional.empty() : this.matchGetter.getFirstMatch(new SingleStackRecipeInput(stack), this.world);
}

public boolean addItem(@Nullable Entity user, ItemStack stack, int cookTime) {
for (int i = 0; i < this.itemsBeingCooked.size(); ++i) {
ItemStack itemStack = this.itemsBeingCooked.get(i);
public boolean addItem(@Nullable LivingEntity user, ItemStack stack, int cookTime) {
for(int i = 0; i < this.itemsBeingCooked.size(); ++i) {
ItemStack itemStack = (ItemStack)this.itemsBeingCooked.get(i);
if (itemStack.isEmpty()) {
this.cookingTotalTimes[i] = cookTime;
this.cookingTimes[i] = 0;
this.itemsBeingCooked.set(i, stack.split(1));
this.itemsBeingCooked.set(i, stack.splitUnlessCreative(1, user));
this.world.emitGameEvent(GameEvent.BLOCK_CHANGE, this.getPos(), GameEvent.Emitter.of(user, this.getCachedState()));
this.updateListeners();
return true;
Expand All @@ -184,14 +187,15 @@ public void clear() {
this.itemsBeingCooked.clear();
}


protected void readComponents(BlockEntity.ComponentsAccess components) {
super.readComponents(components);
(components.getOrDefault(ComponentTypes.CONTAINER, ContainerComponent.DEFAULT)).copyTo(this.getItemsBeingCooked());
(components.getOrDefault(DataComponentTypes.CONTAINER, ContainerComponent.DEFAULT)).copyTo(this.getItemsBeingCooked());
}

protected void addComponents(ComponentMap.Builder componentMapBuilder) {
super.addComponents(componentMapBuilder);
componentMapBuilder.add(ComponentTypes.CONTAINER, ContainerComponent.fromStacks(this.getItemsBeingCooked()));
componentMapBuilder.add(DataComponentTypes.CONTAINER, ContainerComponent.fromStacks(this.getItemsBeingCooked()));
}

public void removeFromCopiedStackNbt(NbtCompound nbt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.recipe.CampfireCookingRecipe;
import net.minecraft.recipe.RecipeEntry;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.input.RecipeInput;
import net.minecraft.recipe.input.SingleStackRecipeInput;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -36,13 +41,15 @@

import java.util.Optional;

public class TreeTapBlockEntity extends LootableContainerBlockEntity implements SidedInventory {
public class TreeTapBlockEntity extends LootableContainerBlockEntity implements SidedInventory, RecipeInput {

private final DefaultedList<ItemStack> inventory;
private final RecipeManager.MatchGetter<TreeTapBlockEntity, TreeTapRecipe> matchGetter;

public TreeTapBlockEntity(BlockPos pos, BlockState state) {
super(ParadiseLostBlockEntityTypes.TREE_TAP, pos, state);
inventory = DefaultedList.ofSize(1, ItemStack.EMPTY);
this.inventory = DefaultedList.ofSize(1, ItemStack.EMPTY);
this.matchGetter = RecipeManager.createCachedMatchGetter(ParadiseLostRecipeTypes.TREE_TAP_RECIPE_TYPE);
}

public void handleUse(PlayerEntity player, Hand hand, ItemStack handStack) {
Expand Down Expand Up @@ -136,7 +143,7 @@ public void tryCraft() {
return;
}

Optional<RecipeEntry<TreeTapRecipe>> recipe = this.world.getRecipeManager().getFirstMatch(ParadiseLostRecipeTypes.TREE_TAP_RECIPE_TYPE, this, this.getWorld());
Optional<RecipeEntry<TreeTapRecipe>> recipe = this.matchGetter.getFirstMatch(this, this.getWorld());
if (recipe.isPresent() && world.random.nextInt(recipe.get().value().getChance()) == 0) {
ItemStack output = recipe.get().value().craft(this, world.getRegistryManager());
Block convertBlock = recipe.get().value().getOutputBlock();
Expand Down Expand Up @@ -198,4 +205,13 @@ public void updateInClientWorld() {
((ServerWorld) world).getChunkManager().markForUpdate(pos);
}

@Override
public ItemStack getStackInSlot(int slot) {
return inventory.get(slot);
}

@Override
public int getSize() {
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
spawnPetalBurst(world, random, pos);
}
} else {
int fortune = EnchantmentHelper.getEquipmentLevel(Enchantments.FORTUNE, player);
ItemStack drops = new ItemStack(fruit.get(), random.nextInt(fortune + 1 + random.nextInt(1)) + 1);
ItemStack drops = new ItemStack(fruit.get(), random.nextInt(1 + random.nextInt(1)) + 1);
if (!player.giveItemStack(drops)) {
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), drops);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ public void setAngles(MoaEntity entity, float limbSwing, float limbSwingAmount,
}

@Override
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
torso.render(matrixStack, buffer, packedLight, packedOverlay);
}

public void setRotationAngle(ModelPart bone, float x, float y, float z) {
bone.pitch = x;
bone.yaw = y;
bone.roll = z;
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
torso.render(matrices, vertices, light, overlay);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private static Settings food(FoodComponent foodComponent) {
public static final AliasedBlockItem AMADRYS_BUSHEL = add("amadrys_bushel", new AliasedBlockItem(ParadiseLostBlocks.AMADRYS, food(ParadiseLostFoodComponent.GENERIC_WORSE)), compostable30);
public static final AliasedBlockItem NITRA_SEED = add("nitra", new AliasedBlockItem(ParadiseLostBlocks.NITRA, food()), compostable15);
public static final Item NITRA_BULB = add("nitra_bulb", new NitraItem(food()), compostable50);
public static final Item AMADRYS_NOODLES = add("amadrys_noodles", new StewItem(food(ParadiseLostFoodComponent.AMADRYS_NOODLES)));
public static final Item AMADRYS_NOODLES = add("amadrys_noodles", new Item(food(ParadiseLostFoodComponent.AMADRYS_NOODLES)));
public static final Item AMADRYS_BREAD = add("amadrys_bread", new Item(food(ParadiseLostFoodComponent.AMADRYS_BREAD)), compostable50);
public static final Item AMADRYS_BREAD_GLAZED = add("amadrys_bread_glazed", new Item(food(ParadiseLostFoodComponent.AMADRYS_BREAD_GLAZED)), compostable50);
public static final AliasedBlockItem SWEDROOT = add("swedroot", new AliasedBlockItem(ParadiseLostBlocks.SWEDROOT, food(ParadiseLostFoodComponent.SWEDROOT)), compostable30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ParadiseLostArmorMaterials {
}

private static RegistryEntry<ArmorMaterial> register(String id, EnumMap<ArmorItem.Type, Integer> defense, int enchantability, RegistryEntry<SoundEvent> equipSound, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
List<ArmorMaterial.Layer> list = List.of(new ArmorMaterial.Layer(new Identifier(id)));
List<ArmorMaterial.Layer> list = List.of(new ArmorMaterial.Layer(Identifier.of(id)));
return register(id, defense, enchantability, equipSound, toughness, knockbackResistance, repairIngredient, list);
}

Expand All @@ -59,7 +59,7 @@ private static RegistryEntry<ArmorMaterial> register(String id, EnumMap<ArmorIte
enumMap.put(type, defense.get(type));
}

return Registry.registerReference(Registries.ARMOR_MATERIAL, new Identifier(id), new ArmorMaterial(enumMap, enchantability, equipSound, repairIngredient, layers, toughness, knockbackResistance));
return Registry.registerReference(Registries.ARMOR_MATERIAL, Identifier.of(id), new ArmorMaterial(enumMap, enchantability, equipSound, repairIngredient, layers, toughness, knockbackResistance));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.component.type.FoodComponent;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.Items;

@SuppressWarnings("unused")
public class ParadiseLostFoodComponent {
Expand All @@ -13,7 +14,7 @@ public class ParadiseLostFoodComponent {
public static final FoodComponent SWEDROOT = new FoodComponent.Builder().nutrition(2).saturationModifier(1.5F).build();
public static final FoodComponent GENERIC_WORSE = new FoodComponent.Builder().nutrition(1).saturationModifier(0.25F)
.statusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 0), 0.075F).build();
public static final FoodComponent AMADRYS_NOODLES = new FoodComponent.Builder().nutrition(7).saturationModifier(0.5F).build();
public static final FoodComponent AMADRYS_NOODLES = new FoodComponent.Builder().nutrition(7).saturationModifier(0.5F).usingConvertsTo(Items.BOWL).build();
public static final FoodComponent AMADRYS_BREAD = new FoodComponent.Builder().nutrition(5).saturationModifier(1.2F).build();
public static final FoodComponent AMADRYS_BREAD_GLAZED = new FoodComponent.Builder().nutrition(8).saturationModifier(1.4F).build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public ItemStack onBucketContentsConsumed(ItemStack stack, World world, PlayerEn
return stack.isEmpty() ? new ItemStack(ParadiseLostItems.AUREL_BUCKET) : stack;
}

@Override
public int getMaxUseTime(ItemStack stack) {
return 32;
}

@Override
public UseAction getUseAction(ItemStack stack) {
if (stack.getItem() != ParadiseLostItems.AUREL_WATER_BUCKET && stack.getItem() != ParadiseLostItems.AUREL_BUCKET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@

@SuppressWarnings("unused")
public class ParadiseLostToolMaterials {
public static final ToolMaterial OLVITE = create(BlockTags.INCORRECT_FOR_IRON_TOOL, MiningLevels.IRON, 250, 4.5f, 2f, 14, () -> Ingredient.ofItems(ParadiseLostItems.OLVITE));
public static final ToolMaterial SURTRUM = create(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, MiningLevels.DIAMOND, 827, 7.0f, 3f, 16, () -> Ingredient.ofItems(ParadiseLostItems.REFINED_SURTRUM));
public static final ToolMaterial GLAZED_GOLD = create(BlockTags.INCORRECT_FOR_IRON_TOOL, MiningLevels.IRON, 131, 12f, 2f, 22, () -> Ingredient.ofItems(ParadiseLostItems.GOLDEN_AMBER));
public static final ToolMaterial OLVITE = create(BlockTags.INCORRECT_FOR_IRON_TOOL, 250, 4.5f, 2f, 14, () -> Ingredient.ofItems(ParadiseLostItems.OLVITE));
public static final ToolMaterial SURTRUM = create(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 827, 7.0f, 3f, 16, () -> Ingredient.ofItems(ParadiseLostItems.REFINED_SURTRUM));
public static final ToolMaterial GLAZED_GOLD = create(BlockTags.INCORRECT_FOR_IRON_TOOL, 131, 12f, 2f, 22, () -> Ingredient.ofItems(ParadiseLostItems.GOLDEN_AMBER));


public static ToolMaterial create(final TagKey incorrect, int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {
return new ParadiseToolMaterial(incorrect, miningLevel, itemDurability, miningSpeed, attackDamage, enchantability, repairIngredient);
public static ToolMaterial create(final TagKey<Block> incorrect, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {
return new ParadiseToolMaterial(incorrect, itemDurability, miningSpeed, attackDamage, enchantability, repairIngredient);
}

static class ParadiseToolMaterial implements ToolMaterial {

private final TagKey<Block> incorrectTag;
private final int miningLevel;
private final int itemDurability;
private final float miningSpeed;
private final float attackDamage;
private final int enchantability;
private final Supplier<Ingredient> repairIngredient;

ParadiseToolMaterial(final TagKey incorrect, int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, final Supplier<Ingredient> repairIngredient) {
ParadiseToolMaterial(final TagKey<Block> incorrect, int itemDurability, float miningSpeed, float attackDamage, int enchantability, final Supplier<Ingredient> repairIngredient) {
this.incorrectTag = incorrect;
this.miningLevel = miningLevel;
this.itemDurability = itemDurability;
this.miningSpeed = miningSpeed;
this.attackDamage = attackDamage;
Expand All @@ -58,10 +56,6 @@ public TagKey<Block> getInverseTag() {
return this.incorrectTag;
}

public int getMiningLevel() {
return this.miningLevel;
}

public int getEnchantability() {
return this.enchantability;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.FluidModificationItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand Down Expand Up @@ -63,29 +66,14 @@ public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {

@Override
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
WorldAccess worldAccess = pointer.world();
FluidModificationItem fluidModificationItem = (FluidModificationItem)stack.getItem();
BlockPos blockPos = pointer.pos().offset(pointer.state().get(DispenserBlock.FACING));
BlockState blockState = worldAccess.getBlockState(blockPos);
Block block = blockState.getBlock();
if (block instanceof FluidDrainable fluidDrainable && blockState.getFluidState().isOf(Fluids.WATER)) {
ItemStack itemStack = fluidDrainable.tryDrainFluid(null, worldAccess, blockPos, blockState);
if (itemStack.isEmpty()) {
return super.dispenseSilently(pointer, stack);
} else {
worldAccess.emitGameEvent(null, GameEvent.FLUID_PICKUP, blockPos);
Item item = ParadiseLostItems.AUREL_WATER_BUCKET;
stack.decrement(1);
if (stack.isEmpty()) {
return new ItemStack(item);
} else {
if (pointer.blockEntity().addToFirstFreeSlot(new ItemStack(item)) < 0) {
this.fallbackBehavior.dispense(pointer, new ItemStack(item));
}
return stack;
}
}
World world = pointer.world();
if (fluidModificationItem.placeFluid(null, world, blockPos, null)) {
fluidModificationItem.onEmptied(null, world, stack, blockPos);
return this.decrementStackWithRemainder(pointer, stack, new ItemStack(ParadiseLostItems.AUREL_WATER_BUCKET));
} else {
return super.dispenseSilently(pointer, stack);
return this.fallbackBehavior.dispense(pointer, stack);
}
}
};
Expand Down
Loading

0 comments on commit 29b51b1

Please sign in to comment.