Skip to content

Commit

Permalink
Add display entities to entity_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Oct 17, 2023
1 parent 44acbf2 commit 0ea9aea
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlockData;
import com.laytonsmith.abstraction.entities.MCBlockDisplay;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Entity;

public class BukkitMCBlockDisplay extends BukkitMCDisplay implements MCBlockDisplay {

BlockDisplay bd;

public BukkitMCBlockDisplay(Entity e) {
super(e);
this.bd = (BlockDisplay) e;
}

@Override
public MCBlockData getBlockData() {
return new BukkitMCBlockData(this.bd.getBlock());
}

@Override
public void setBlockData(MCBlockData data) {
this.bd.setBlock((BlockData) data.getHandle());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.MCColor;
import com.laytonsmith.abstraction.bukkit.BukkitMCColor;
import com.laytonsmith.abstraction.entities.MCDisplay;
import org.bukkit.Color;
import org.bukkit.entity.Display;
import org.bukkit.entity.Entity;

public class BukkitMCDisplay extends BukkitMCEntity implements MCDisplay {

Display d;

public BukkitMCDisplay(Entity e) {
super(e);
this.d = (Display) e;
}

@Override
public MCDisplay.Billboard getBillboard() {
return MCDisplay.Billboard.valueOf(this.d.getBillboard().name());
}

@Override
public void setBillboard(MCDisplay.Billboard billboard) {
this.d.setBillboard(Display.Billboard.valueOf(billboard.name()));
}

@Override
public MCDisplay.Brightness getBrightness() {
Display.Brightness brightness = this.d.getBrightness();
if(brightness == null) {
return null;
}
return new MCDisplay.Brightness(brightness.getBlockLight(), brightness.getSkyLight());
}

@Override
public void setBrightness(MCDisplay.Brightness brightness) {
if(brightness == null) {
this.d.setBrightness(null);
} else {
this.d.setBrightness(new Display.Brightness(brightness.block(), brightness.sky()));
}
}

@Override
public MCColor getGlowColorOverride() {
Color color = this.d.getGlowColorOverride();
if(color == null) {
return null;
}
return BukkitMCColor.GetMCColor(color);
}

@Override
public void setGlowColorOverride(MCColor color) {
if(color == null) {
this.d.setGlowColorOverride(null);
} else {
this.d.setGlowColorOverride(BukkitMCColor.GetColor(color));
}
}

@Override
public float getDisplayHeight() {
return this.d.getDisplayHeight();
}

@Override
public void setDisplayHeight(float height) {
this.d.setDisplayHeight(height);
}

@Override
public float getDisplayWidth() {
return this.d.getDisplayWidth();
}

@Override
public void setDisplayWidth(float width) {
this.d.setDisplayWidth(width);
}

@Override
public int getInterpolationDurationTicks() {
return this.d.getInterpolationDuration();
}

@Override
public void setInterpolationDurationTicks(int ticks) {
this.d.setInterpolationDuration(ticks);
}

@Override
public int getInterpolationDelayTicks() {
return this.d.getInterpolationDelay();
}

@Override
public void setInterpolationDelayTicks(int ticks) {
this.d.setInterpolationDuration(ticks);
}

@Override
public float getShadowRadius() {
return this.d.getShadowRadius();
}

@Override
public void setShadowRadius(float radius) {
this.d.setShadowRadius(radius);
}

@Override
public float getShadowStrength() {
return this.d.getShadowStrength();
}

@Override
public void setShadowStrength(float strength) {
this.d.setShadowStrength(strength);
}

@Override
public float getViewRange() {
return this.d.getViewRange();
}

@Override
public void setViewRange(float range) {
this.d.setViewRange(range);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack;
import com.laytonsmith.abstraction.entities.MCItemDisplay;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.ItemDisplay.ItemDisplayTransform;
import org.bukkit.inventory.ItemStack;

public class BukkitMCItemDisplay extends BukkitMCDisplay implements MCItemDisplay {

ItemDisplay id;

public BukkitMCItemDisplay(Entity e) {
super(e);
this.id = (ItemDisplay) e;
}

@Override
public MCItemStack getItem() {
ItemStack item = this.id.getItemStack();
if(item == null) {
return null;
}
return new BukkitMCItemStack(item);
}

@Override
public void setItem(MCItemStack item) {
if(item == null) {
this.id.setItemStack(null);
} else {
this.id.setItemStack((ItemStack) item.getHandle());
}
}

@Override
public ModelTransform getItemModelTransform() {
return ModelTransform.valueOf(this.id.getItemDisplayTransform().name());
}

@Override
public void setItemModelTransform(ModelTransform transform) {
this.id.setItemDisplayTransform(ItemDisplayTransform.valueOf(transform.name()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.entities.MCTextDisplay;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TextDisplay;
import org.bukkit.entity.TextDisplay.TextAlignment;

public class BukkitMCTextDisplay extends BukkitMCDisplay implements MCTextDisplay {

TextDisplay td;

public BukkitMCTextDisplay(Entity e) {
super(e);
this.td = (TextDisplay) e;
}

@Override
public MCTextDisplay.Alignment getAlignment() {
return MCTextDisplay.Alignment.valueOf(td.getAlignment().name());
}

@Override
public void setAlignment(MCTextDisplay.Alignment alignment) {
td.setAlignment(TextAlignment.valueOf(alignment.name()));
}

@Override
public boolean usesDefaultBackground() {
return td.isDefaultBackground();
}

@Override
public void setUsesDefaultBackground(boolean defaultBackground) {
td.setDefaultBackground(defaultBackground);
}

@Override
public int getLineWidth() {
return td.getLineWidth();
}

@Override
public void setLineWidth(int width) {
td.setLineWidth(width);
}

@Override
public boolean isVisibleThroughBlocks() {
return td.isSeeThrough();
}

@Override
public void setVisibleThroughBlocks(boolean visible) {
td.setSeeThrough(visible);
}

@Override
public boolean hasShadow() {
return td.isShadowed();
}

@Override
public void setHasShadow(boolean hasShadow) {
td.setShadowed(hasShadow);
}

@Override
public String getText() {
return td.getText();
}

@Override
public void setText(String text) {
td.setText(text);
}

@Override
public byte getOpacity() {
return td.getTextOpacity();
}

@Override
public void setOpacity(byte opacity) {
td.setTextOpacity(opacity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.abstraction.blocks.MCBlockData;

public interface MCBlockDisplay extends MCDisplay {

MCBlockData getBlockData();

void setBlockData(MCBlockData data);

}
73 changes: 73 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/entities/MCDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.abstraction.MCColor;
import com.laytonsmith.abstraction.MCEntity;

public interface MCDisplay extends MCEntity {

Billboard getBillboard();

void setBillboard(Billboard billboard);

Brightness getBrightness();

void setBrightness(Brightness brightness);

MCColor getGlowColorOverride();

void setGlowColorOverride(MCColor color);

float getDisplayHeight();

void setDisplayHeight(float height);

float getDisplayWidth();

void setDisplayWidth(float width);

int getInterpolationDurationTicks();

void setInterpolationDurationTicks(int ticks);

int getInterpolationDelayTicks();

void setInterpolationDelayTicks(int ticks);

float getShadowRadius();

void setShadowRadius(float radius);

float getShadowStrength();

void setShadowStrength(float strength);

float getViewRange();

void setViewRange(float range);

enum Billboard {
CENTER,
FIXED,
HORIZONTAL,
VERTICAL
}

class Brightness {

final int block;
final int sky;

public Brightness(int block, int sky) {
this.block = block;
this.sky = sky;
}

public int block() {
return this.block;
}

public int sky() {
return this.sky;
}
}
}
Loading

0 comments on commit 0ea9aea

Please sign in to comment.