1.0.3
SlightlyVanilla/pipeline/head This commit looks good Details

Update Dispenser Behavior
This commit is contained in:
TheBrokenRail 2020-03-19 21:26:13 -04:00
parent 36f1f31bad
commit bc7c87aeab
10 changed files with 57 additions and 9 deletions

View File

@ -1,5 +1,8 @@
# Changelog
**1.0.3**
* Update Dispenser Behavior
**1.0.2**
* Allow Shooting Slimeballs from Dispensers
* Update Lang

View File

@ -6,7 +6,7 @@ Suggest more tweaks in the issue tracker!
## Tweaks
* Use Respawn Anchor in Any Dimension
* Instantly Kill In Creative Mode
* Instant Kill In Creative Mode
* Throwable Slimeballs
* Throwable Spawn Eggs

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
fabric_loader_version = 0.7.8+build.189
# Mod Properties
mod_version = 1.0.2
mod_version = 1.0.3
maven_group = com.thebrokenrail
archives_base_name = slightlyvanilla

View File

@ -2,11 +2,24 @@ package com.thebrokenrail.slightlyvanilla;
import me.sargunvohra.mcmods.autoconfig1u.ConfigData;
import me.sargunvohra.mcmods.autoconfig1u.annotation.Config;
import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry;
@Config(name = SlightlyVanilla.NAMESPACE)
public class ModConfig implements ConfigData {
public boolean useRespawnAnchorInAnyDimension = true;
public boolean instantKillInCreative = true;
public boolean throwableSlimeballs = true;
public boolean throwableSpawnEggs = true;
@ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
public ThrowableOption throwableSlimeballs = new ThrowableOption(true, true);
@ConfigEntry.Gui.CollapsibleObject(startExpanded = true)
public ThrowableOption throwableSpawnEggs = new ThrowableOption(true, false);
public static class ThrowableOption {
public boolean player;
public boolean dispenser;
private ThrowableOption(boolean player, boolean dispenser) {
this.player = player;
this.dispenser = dispenser;
}
}
}

View File

@ -7,17 +7,19 @@ import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
@ -43,7 +45,7 @@ public class SlightlyVanilla implements ModInitializer {
Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "spawn_egg"), SPAWN_EGG_ENTITY);
DispenserBlock.registerBehavior(Items.SLIME_BALL, (pointer, stack) -> {
if (getConfig().throwableSlimeballs) {
if (getConfig().throwableSlimeballs.dispenser) {
return new ProjectileDispenserBehavior() {
@Override
protected ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) {
@ -56,5 +58,31 @@ public class SlightlyVanilla implements ModInitializer {
return new ItemDispenserBehavior().dispense(pointer, stack);
}
});
for (SpawnEggItem spawnEgg : SpawnEggItem.getAll()) {
DispenserBlock.registerBehavior(spawnEgg, (pointer, stack) -> {
if (getConfig().throwableSpawnEggs.dispenser) {
return new ProjectileDispenserBehavior() {
@Override
protected ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) {
SpawnEggEntity entity = new SpawnEggEntity(position, stack.getX(), stack.getY(), stack.getZ());
entity.setItem(itemStack);
return entity;
}
}.dispense(pointer, stack);
} else {
return new ItemDispenserBehavior() {
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
Direction direction = pointer.getBlockState().get(DispenserBlock.FACING);
EntityType<?> entityType = ((SpawnEggItem)stack.getItem()).getEntityType(stack.getTag());
entityType.spawnFromItemStack(pointer.getWorld(), stack, null, pointer.getBlockPos().offset(direction), SpawnType.DISPENSER, direction != Direction.UP, false);
stack.decrement(1);
return stack;
}
}.dispense(pointer, stack);
}
});
}
}
}

View File

@ -1,5 +1,6 @@
package com.thebrokenrail.slightlyvanilla.client;
import com.google.common.collect.Lists;
import com.thebrokenrail.slightlyvanilla.SlightlyVanilla;
import com.thebrokenrail.slightlyvanilla.ModConfig;
import com.thebrokenrail.slightlyvanilla.entity.SlimeballEntity;

View File

@ -8,7 +8,6 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.network.Packet;

View File

@ -21,7 +21,7 @@ public class MixinItem {
@Inject(at = @At("HEAD"), method = "use", cancellable = true)
public void use(World world, PlayerEntity playerEntity, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> info) {
ItemStack stack = playerEntity.getStackInHand(hand);
if (stack.getItem() == Items.SLIME_BALL && SlightlyVanilla.getConfig().throwableSlimeballs) {
if (stack.getItem() == Items.SLIME_BALL && SlightlyVanilla.getConfig().throwableSlimeballs.player) {
if (!world.isClient()) {
SlimeballEntity entity = new SlimeballEntity(world, playerEntity);
entity.setItem(stack);

View File

@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
public class MixinSpawnEggItem {
@Inject(at = @At("RETURN"), method = "use", cancellable = true)
public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> info) {
if (SlightlyVanilla.getConfig().throwableSpawnEggs && info.getReturnValue().getResult() == ActionResult.PASS) {
if (SlightlyVanilla.getConfig().throwableSpawnEggs.player && info.getReturnValue().getResult() == ActionResult.PASS) {
ItemStack stack = user.getStackInHand(hand);
if (!world.isClient()) {
SpawnEggEntity entity = new SpawnEggEntity(world, user);

View File

@ -3,7 +3,11 @@
"text.autoconfig.slightlyvanilla.option.useRespawnAnchorInAnyDimension": "Use Respawn Anchor In Any Dimension",
"text.autoconfig.slightlyvanilla.option.instantKillInCreative": "Instant Kill In Creative Mode",
"text.autoconfig.slightlyvanilla.option.throwableSlimeballs": "Throwable Slimeballs",
"text.autoconfig.slightlyvanilla.option.throwableSlimeballs.player": "Player",
"text.autoconfig.slightlyvanilla.option.throwableSlimeballs.dispenser": "Dispenser",
"text.autoconfig.slightlyvanilla.option.throwableSpawnEggs": "Throwable Spawn Eggs",
"text.autoconfig.slightlyvanilla.option.throwableSpawnEggs.player": "Player",
"text.autoconfig.slightlyvanilla.option.throwableSpawnEggs.dispenser": "Dispenser",
"entity.slightlyvanilla.slimeball": "Slimeball",
"entity.slightlyvanilla.spawn_egg": "Spawn Egg"
}