Skip to content

Commit

Permalink
Reduce import reorder noise in the diff and remove use of var
Browse files Browse the repository at this point in the history
  • Loading branch information
altrisi committed Jun 24, 2024
1 parent d913084 commit e18c99d
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 152 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package carpetextra.dispenser.behaviors;

import net.minecraft.block.*;
import net.minecraft.block.dispenser.*;
import net.minecraft.item.*;
import net.minecraft.server.world.*;
import net.minecraft.util.math.*;
import net.minecraft.world.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.NetherWartBlock;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldEvents;

public class BlazePowderDispenserBehavior extends FallibleItemDispenserBehavior {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package carpetextra.dispenser.behaviors;

import net.minecraft.block.*;
import net.minecraft.block.dispenser.*;
import net.minecraft.item.*;
import net.minecraft.server.world.*;
import net.minecraft.sound.*;
import net.minecraft.util.math.*;
import net.minecraft.world.event.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CarvedPumpkinBlock;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.event.GameEvent;

public class CarvePumpkinDispenserBehavior extends FallibleItemDispenserBehavior {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package carpetextra.dispenser.behaviors;

import carpetextra.dispenser.*;
import net.minecraft.block.*;
import net.minecraft.component.*;
import net.minecraft.component.type.*;
import net.minecraft.item.*;
import net.minecraft.potion.*;
import net.minecraft.registry.entry.*;
import net.minecraft.registry.tag.*;
import net.minecraft.server.world.*;
import net.minecraft.sound.*;
import net.minecraft.util.math.*;
import net.minecraft.world.event.*;
import carpetextra.dispenser.DispenserBehaviorHelper;
import net.minecraft.block.AbstractCauldronBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.LeveledCauldronBlock;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.BannerPatternsComponent;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.item.BannerItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.Potions;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.event.GameEvent;

public class CauldronWaterDispenserBehavior extends DispenserBehaviorHelper {
@Override
Expand All @@ -23,13 +36,13 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
BlockState frontBlockState = world.getBlockState(frontBlockPos);
Block frontBlock = frontBlockState.getBlock();

if(frontBlock == Blocks.WATER_CAULDRON) {
if(item == Items.POTION) {
if (frontBlock == Blocks.WATER_CAULDRON) {
if (item == Items.POTION) {
// check if it's a water bottle (https://minecraft.wiki/w/Potion#Base_potions)
var potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
PotionContentsComponent potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
if (potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER)) {
// check if cauldron is not full
if(!((AbstractCauldronBlock) frontBlock).isFull(frontBlockState)) {
if (!((AbstractCauldronBlock) frontBlock).isFull(frontBlockState)) {
// increase cauldron level
int level = frontBlockState.get(LeveledCauldronBlock.LEVEL);
BlockState cauldronState = frontBlockState.with(LeveledCauldronBlock.LEVEL, level + 1);
Expand All @@ -40,15 +53,15 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
}
}
}
else if(item == Items.GLASS_BOTTLE) {
else if (item == Items.GLASS_BOTTLE) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// return water bottle
return this.addOrDispense(pointer, stack, PotionContentsComponent.createStack(Items.POTION, Potions.WATER));
}
else if(Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
else if (Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
// make sure item isn't plain shulker box
if(item != Items.SHULKER_BOX) {
if (item != Items.SHULKER_BOX) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// turn dyed shulker box into undyed shulker box
Expand All @@ -58,9 +71,9 @@ else if(Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
return this.addOrDispense(pointer, stack, undyedShulkerBox);
}
}
if(stack.isIn(ItemTags.DYEABLE)) {
if (stack.isIn(ItemTags.DYEABLE)) {
// check if dyeable item has color
if(stack.contains(DataComponentTypes.DYED_COLOR)) {
if (stack.contains(DataComponentTypes.DYED_COLOR)) {
// decrease cauldron level
LeveledCauldronBlock.decrementFluidLevel(frontBlockState, world, frontBlockPos);
// remove color
Expand All @@ -69,7 +82,7 @@ else if(Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
return stack;
}
}
else if(item instanceof BannerItem) {
else if (item instanceof BannerItem) {
// check if banner has layers (https://minecraft.wiki/w/Banner#Patterns)
BannerPatternsComponent bannerPatternsComponent = stack.getOrDefault(DataComponentTypes.BANNER_PATTERNS, BannerPatternsComponent.DEFAULT);
if (!bannerPatternsComponent.layers().isEmpty()) {
Expand All @@ -87,7 +100,7 @@ else if(item instanceof BannerItem) {
}
else if(frontBlock == Blocks.CAULDRON && item == Items.POTION) {
// check if it's a water bottle (https://minecraft.wiki/w/Potion#Base_potions)
var potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
PotionContentsComponent potionContentsComponent = stack.get(DataComponentTypes.POTION_CONTENTS);
if (potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER)) {
// increase cauldron level
BlockState cauldronState = Blocks.WATER_CAULDRON.getDefaultState();
Expand Down Expand Up @@ -116,7 +129,7 @@ public static boolean isWaterCauldronItem(ItemStack stack) {
if (item == Items.GLASS_BOTTLE || item instanceof BannerItem)
return true;
if (item == Items.POTION) {
var potionContentsComponent = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
PotionContentsComponent potionContentsComponent = stack.getComponents().get(DataComponentTypes.POTION_CONTENTS);
return potionContentsComponent != null && potionContentsComponent.matches(Potions.WATER);
}
if (Block.getBlockFromItem(item) instanceof ShulkerBoxBlock) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package carpetextra.dispenser.behaviors;

import java.util.List;
import java.util.Optional;

import net.minecraft.registry.tag.ItemTags;

import carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.component.type.SuspiciousStewEffectsComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.MooshroomEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;

import java.util.List;

public class FeedMooshroomDispenserBehavior extends FallibleItemDispenserBehavior {
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
Expand All @@ -40,7 +43,7 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
// check if mooshroom has no stew effect
if (mooshroomAccessor.getStewEffects() == null) {
// get stew effect and length for flower
var effect = mooshroomAccessor.invokeGetStewEffectFrom(stack);
Optional<SuspiciousStewEffectsComponent> effect = mooshroomAccessor.invokeGetStewEffectFrom(stack);

// check if effect is present
if (effect.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package carpetextra.dispenser.behaviors;

import java.util.List;

import carpetextra.dispenser.DispenserBehaviorHelper;
import carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin;
import net.minecraft.block.DispenserBlock;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.SuspiciousStewEffectsComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.MooshroomEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -17,8 +20,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;

import java.util.List;

public class MilkMooshroomDispenserBehavior extends DispenserBehaviorHelper {
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
Expand Down Expand Up @@ -56,7 +57,7 @@ private static ItemStack getStewType(List<MooshroomEntity> mooshrooms) {
for (MooshroomEntity mooshroom : mooshrooms) {
// from MooshroomEntity#interact
MooshroomEntity_StatusEffectAccessorMixin mooshroomAccessor = (MooshroomEntity_StatusEffectAccessorMixin) mooshroom;
var stewEffects = mooshroomAccessor.getStewEffects();
SuspiciousStewEffectsComponent stewEffects = mooshroomAccessor.getStewEffects();
if (stewEffects != null) {
// create suspicious stew and add mooshroom's stew effect to it
ItemStack stewStack = new ItemStack(Items.SUSPICIOUS_STEW);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package carpetextra.dispenser.behaviors;

import java.util.List;

import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.entity.EntityType;
Expand All @@ -13,8 +15,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;

import java.util.List;

public class ShearChickenDispenserBehavior extends FallibleItemDispenserBehavior {
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package carpetextra.dispenser.behaviors;

import java.util.Collection;
import java.util.Set;

import carpetextra.dispenser.DispenserItemUsageContext;
import carpetextra.mixins.AxeItem_StrippedBlocksAccessorMixin;
import net.minecraft.block.Block;
Expand All @@ -17,9 +20,6 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

import java.util.Collection;
import java.util.Set;

public class StripBlocksDispenserBehavior extends FallibleItemDispenserBehavior {
// stripable blocks
public static final Set<Block> STRIPPED_BLOCKS = AxeItem_StrippedBlocksAccessorMixin.getStrippedBlocks().keySet();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package carpetextra.dispenser.behaviors;

import java.util.Set;

import carpetextra.dispenser.DispenserItemUsageContext;
import carpetextra.mixins.HoeItem_TilledBlocksAccessorMixin;
import net.minecraft.block.Block;
Expand All @@ -15,8 +17,6 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;

import java.util.Set;

public class TillSoilDispenserBehavior extends FallibleItemDispenserBehavior {
public static final Set<Block> TILLED_BLOCKS = HoeItem_TilledBlocksAccessorMixin.getTilledBlocks().keySet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
BlockState frontBlockState = world.getBlockState(frontBlockPos);

// check if block can be toggled
if(TOGGLEABLE_BLOCKS.contains(frontBlockState.getBlock())) {
if (TOGGLEABLE_BLOCKS.contains(frontBlockState.getBlock())) {
BlockHitResult hitResult = new BlockHitResult(Vec3d.of(frontBlockPos), dispenserFacing.getOpposite(), frontBlockPos, false);

// use on block, test if successful
if(frontBlockState.onUse(world, null, hitResult).isAccepted()) {
if (frontBlockState.onUse(world, null, hitResult).isAccepted()) {
return stack;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package carpetextra.mixins;

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.CallbackInfoReturnable;

import carpetextra.utils.PlaceBlockDispenserBehavior;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPointer;
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.CallbackInfoReturnable;

@Mixin(targets = "net/minecraft/block/dispenser/DispenserBehavior$5")
public abstract class DispenserBehaviorCarvedPumpkinMixin extends FallibleItemDispenserBehavior {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package carpetextra.mixins;

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.CallbackInfoReturnable;

import carpetextra.utils.PlaceBlockDispenserBehavior;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPointer;
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.CallbackInfoReturnable;

@Mixin(targets = {
/* mob & player heads */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package carpetextra.mixins;

import java.util.Map;

import org.spongepowered.asm.mixin.Final;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import carpet.script.value.Value;
import carpet.script.value.ValueConversions;
import carpetextra.dispenser.CarpetExtraDispenserBehaviors;
Expand All @@ -13,15 +23,6 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Final;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Map;

@Mixin(DispenserBlock.class)
public abstract class DispenserBlock_GetCustomBehaviorMixin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package carpetextra.mixins;

import java.util.Random;

import carpetextra.CarpetExtraSettings;
import carpetextra.fakes.DispenserBlockEntityInterface;
import carpetextra.utils.VoidContainer;
Expand All @@ -26,8 +28,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Random;

@Mixin(DropperBlock.class)
public class DropperBlock_craftingMixin extends DispenserBlock
{
Expand Down
Loading

0 comments on commit e18c99d

Please sign in to comment.